@aiquants/period-slider 0.9.0 → 0.10.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.
@@ -12,7 +12,28 @@
12
12
  */
13
13
  import { addDays, addMonths, addYears } from "date-fns"
14
14
  import type React from "react"
15
- import { type CSSProperties, memo, useCallback, useEffect, useId, useMemo, useRef, useState } from "react"
15
+ import { type CSSProperties, memo, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react"
16
+ import {
17
+ buildVernierProjectionPath,
18
+ clearDragPresentation,
19
+ DRAG_LABEL_VARIABLE_PREFIXES,
20
+ DRAG_PRESENTATION_VARIABLES,
21
+ DRAG_SNAP_ATTRIBUTE,
22
+ DRAG_SNAP_BACK_MS,
23
+ DRAG_SNAP_DURATION_VARIABLE,
24
+ type DragLabelPlacement,
25
+ type DragLabelPlacementPair,
26
+ type DragPresentationRail,
27
+ dragLabelPlacementValue,
28
+ dragPresentationValue,
29
+ resolveBandDragRatios,
30
+ resolveDraggedEdge,
31
+ resolveEdgeDragRatios,
32
+ writeDragLabelPlacement,
33
+ writeDragPresentation,
34
+ } from "./dragPresentation"
35
+ import { containsEventTarget, ownsPaintedPoint, registerRangeAreaWheelParticipant } from "./rangeAreaWheel"
36
+ import { STEPPER_OUTWARD_RESERVE_CLASSES, STEPPER_ROW_GAP_CLASS, type StepArrowDirection, StepperButton } from "./StepperButton"
16
37
 
17
38
  // ======================================================================
18
39
  // 1. Core Domain Types & Public Interfaces
@@ -212,7 +233,7 @@ export interface BasePeriodSliderProps extends AccessibleSliderLabels {
212
233
  showStepper?: boolean
213
234
  /** Tooltip display strategy (default: "always") / ツールチップ表示方式 (既定: "always") */
214
235
  tooltipStyle?: "always" | "hover" | "balloon"
215
- /** Label position: "top" (default) or "bottom" / ラベル表示位置("top": 上側 [既定], "bottom": 下側) */
236
+ /** Label position: "top" (default) or "bottom" / ラベル表示位置 ("top": 上側 [既定], "bottom": 下側) */
216
237
  labelPosition?: PeriodSliderLabelPosition
217
238
  /** Whether to automatically slant labels when a pair comes close, in range mode and on both vernier rails (default: true) / Range モードとノギスの両レールで、対が接近した時に自動斜め表示するか (既定: true) */
218
239
  autoSlantLabels?: boolean
@@ -593,7 +614,7 @@ const clampDateInto = (date: Date, min: Date, max: Date): Date => (date < min ?
593
614
  * @param macroRange - Current macro window tuple / 現在のマクロ窓タプル
594
615
  * @param minDate - Domain lower boundary / 定義域の下限
595
616
  * @param maxDate - Domain upper boundary / 定義域の上限
596
- * @returns Window tuple in micro unit resolution, guaranteed to lie inside [minDate, maxDate] / [minDate, maxDate] の内側であることが保証されたミクロ解像度の窓タプル
617
+ * @returns Window tuple in micro unit resolution, guaranteed to lie inside [minDate, maxDate] at that resolution / そのミクロ解像度で [minDate, maxDate] の内側であることが保証されたミクロ解像度の窓タプル
597
618
  * @throws RangeError naming this function when macroRange is not a usable tuple, when a boundary is absent or an Invalid Date, or when either pair is inverted / macroRange が利用可能なタプルでない場合、境界が未指定または Invalid Date の場合、いずれかの対が逆転している場合 (メッセージは本関数を名指しする)
598
619
  */
599
620
  export const resolveMacroWindow = (macroUnit: PeriodSliderUnit, microUnit: PeriodSliderUnit, macroRange: [Date, Date], minDate: Date, maxDate: Date): [Date, Date] => {
@@ -603,7 +624,9 @@ export const resolveMacroWindow = (macroUnit: PeriodSliderUnit, microUnit: Perio
603
624
  if (!isValidDate(maxDate)) throw new RangeError(`resolveMacroWindow: maxDate must be a valid Date (received: ${describeDateValue(maxDate)})`)
604
625
  if (maxDate.getTime() < minDate.getTime()) throw new RangeError(`resolveMacroWindow: maxDate must not precede minDate (minDate: ${describeDateValue(minDate)}, maxDate: ${describeDateValue(maxDate)})`)
605
626
  // クランプの結果は生の minDate / maxDate になり得るため、ミクロ単位へ畳み直す。
606
- // 畳まないと返り値は「ミクロ解像度」を名乗れず、日付で比較する呼び出し側が符号化で比較する側と食い違う
627
+ // 畳まないと返り値は「ミクロ解像度」を名乗れず、日付で比較する呼び出し側が符号化で比較する側と食い違う。
628
+ // 境界が期間の途中を指すと畳んだ開始は生の minDate より前の時刻を持つが、それはレールが実際に描く先頭の
629
+ // ミクロ期間そのものであり、定義域の内包もそのミクロ解像度で判定される (assertSelectionWithinDomain)
607
630
  return [normalizeDateByUnit(microUnit, clampDateInto(getMacroWindowStartDate(macroUnit, microUnit, macroRange[0]), minDate, maxDate)), normalizeDateByUnit(microUnit, clampDateInto(getMacroWindowEndDate(macroUnit, microUnit, macroRange[1]), minDate, maxDate))]
608
631
  }
609
632
 
@@ -854,25 +877,6 @@ export const calculateHandleDragValues = (handle: "low" | "high", clampedVal: nu
854
877
  return [Math.max(rangeMin, Math.min(rangeMax, nextLow)), Math.max(rangeMin, Math.min(rangeMax, nextHigh))]
855
878
  }
856
879
 
857
- /**
858
- * Determines which handle ('low' or 'high') is actively under the pointer when dragging.
859
- * ドラッグ操作中にポインターが現在操作しているハンドル ('low' または 'high') の判定。
860
- *
861
- * @param originalHandle - Originally grabbed handle on pointerdown ('low' or 'high')
862
- * @param pointerVal - Current value calculated from pointer position
863
- * @param startLowVal - Initial low value when drag began
864
- * @param startHighVal - Initial high value when drag began
865
- * @param isPointMode - Whether slider is in single-point mode
866
- * @returns Handle name corresponding to the active pointer position
867
- */
868
- export const getActiveDragHandle = (originalHandle: "low" | "high", pointerVal: number, startLowVal: number, startHighVal: number, isPointMode: boolean): "low" | "high" => {
869
- if (isPointMode) return "low"
870
- if (originalHandle === "low") {
871
- return pointerVal > startHighVal ? "high" : "low"
872
- }
873
- return pointerVal < startLowVal ? "low" : "high"
874
- }
875
-
876
880
  /**
877
881
  * Input bundle for translating a connect-bar drag into a new [lower, upper] value pair.
878
882
  * 接続バードラッグを新しい上下限値の組へ変換するための入力一式。
@@ -1048,6 +1052,22 @@ const DEFAULT_LABEL_PADDING_PX = 12
1048
1052
  /** Angle the labels reach when the two handles coincide, in degrees / 2 つのつまみが完全一致した時に到達する角度 (度) */
1049
1053
  const DEFAULT_MAX_SLANT_ANGLE_DEG = 90
1050
1054
 
1055
+ /**
1056
+ * Half extents of the bounding box of a rectangle rotated by an angle, along its unrotated width and across it.
1057
+ * 角度だけ回転した矩形の外接矩形の半寸法 (回転前の幅方向と、その直交方向)。
1058
+ *
1059
+ * @param widthPx - Unrotated width in pixels / 回転前の幅 (ピクセル)
1060
+ * @param heightPx - Unrotated height in pixels / 回転前の高さ (ピクセル)
1061
+ * @param angleDeg - Rotation in degrees / 回転角 (度)
1062
+ * @returns Half extents along and across the unrotated width / 回転前の幅方向と直交方向の半寸法
1063
+ */
1064
+ export const resolveRotatedHalfExtents = (widthPx: number, heightPx: number, angleDeg: number): { alongPx: number; acrossPx: number } => {
1065
+ const rad = (angleDeg * Math.PI) / 180
1066
+ const sin = Math.abs(Math.sin(rad))
1067
+ const cos = Math.abs(Math.cos(rad))
1068
+ return { alongPx: (widthPx * cos + heightPx * sin) / 2, acrossPx: (widthPx * sin + heightPx * cos) / 2 }
1069
+ }
1070
+
1051
1071
  /**
1052
1072
  * Builds the upright placement both labels take whenever no rotation applies.
1053
1073
  * 回転を行わない場合に両ラベルが取る直立配置を構築する関数。
@@ -1084,6 +1104,11 @@ const buildHorizontalSlantResult = (labelPosition: PeriodSliderLabelPosition, co
1084
1104
  * label yields the upright baseline instead of an invented number.
1085
1105
  * 幾何計算が使う 2 つの寸法はいずれも描画結果であるため、トラックまたはラベルが未実測なら数値を捏造せず直立基準値を返す。
1086
1106
  *
1107
+ * The rotated half extents come from `resolveRotatedHalfExtents`, the same helper the range area reads to know how far
1108
+ * a drawn label reaches from the rail, so the placement and the area can never disagree about a rotated label's size.
1109
+ * 回転後の半寸法は `resolveRotatedHalfExtents` から得る。範囲領域が描かれたラベルのレールからの到達距離を求める際も同じ関数を読むため、
1110
+ * 回転したラベルの寸法について配置と範囲領域が食い違わない。
1111
+ *
1087
1112
  * @param lowPct - Percent position of lower handle (0-100) / 下限つまみの位置 (0-100%)
1088
1113
  * @param highPct - Percent position of upper handle (0-100) / 上限つまみの位置 (0-100%)
1089
1114
  * @param trackWidthPx - Measured pixel width of the track; a non-positive value means "not measured yet" and yields the horizontal baseline / 実測トラック幅 (0 以下は未実測とみなし水平基準値を返す)
@@ -1126,14 +1151,13 @@ export const calculateLabelSlant = (lowPct: number, highPct: number, trackWidthP
1126
1151
 
1127
1152
  // 回転後の外接矩形の半高は (W/2)|sin θ| + (H/2)|cos θ|。
1128
1153
  // 中心をこの分だけ離隔に足して押し出さないと、傾けた瞬間にラベル下端がつまみへ食い込む
1129
- const rad = (angle * Math.PI) / 180
1130
- const halfHeightRotated = (labelWidth / 2) * Math.abs(Math.sin(rad)) + (labelHeight / 2) * Math.abs(Math.cos(rad))
1131
- const calculatedCenterDist = clearance + halfHeightRotated
1154
+ const rotated = resolveRotatedHalfExtents(labelWidth, labelHeight, angle)
1155
+ const calculatedCenterDist = clearance + rotated.acrossPx
1132
1156
  const calculatedOffsetY = labelPosition === "top" ? -calculatedCenterDist : +calculatedCenterDist
1133
1157
 
1134
1158
  // 同角度で回転した合同な 2 矩形は、中心間距離が回転後の水平占有幅 W*|cos θ| + H*|sin θ| 以上になった時点で
1135
1159
  // 分離軸定理より必ず分離する。角度ランプだけでは中間距離帯で重なるため、不足分を左右へ等分して押し広げる
1136
- const rotatedFootprint = labelWidth * Math.abs(Math.cos(rad)) + labelHeight * Math.abs(Math.sin(rad))
1160
+ const rotatedFootprint = 2 * rotated.alongPx
1137
1161
  const shiftX = Math.max(0, (rotatedFootprint + padding - pixelDistance) / 2)
1138
1162
 
1139
1163
  return {
@@ -1185,6 +1209,13 @@ export type VernierMicroShape = "range" | "point"
1185
1209
  * トラックは中心線で分かれた 2 本のレールを載せるため、オフセットの符号とマクロレールの側だけが判定規則の全て。
1186
1210
  * スケールを選ぶ必要のある操作 (押下・ホイール) は、規則を再掲せず本関数を読む。
1187
1211
  *
1212
+ * The rule is half-open: a negative offset is the first rail (top or left) and offset 0 is the second, because
1213
+ * pixels are addressed by their top-left corner, so the pixel that starts at the centre line is drawn and
1214
+ * hit-tested as part of the second band. An offset far outside the 8px band (over a label, in the lane) reads the
1215
+ * same sign.
1216
+ * 判定は半開区間で、負のオフセットが第一レール (上または左)、0 は第二レール。画素は左上角で番地付けされるため、
1217
+ * 中心線から始まる画素は第二レールの帯として描かれ、ヒットテストされる。8px の帯から離れた位置 (ラベルの上、レーン) も同じ符号で読む。
1218
+ *
1188
1219
  * @param pointerCrossAxisOffset - Signed pointer offset from the track center line in pixels / トラック中心線からのポインター直交軸オフセット (ピクセル、符号付き)
1189
1220
  * @param orientation - Which rail the macro scale is drawn on / マクロスケールを描くレール
1190
1221
  * @returns Rail the offset belongs to / オフセットが属するレール
@@ -1192,7 +1223,8 @@ export type VernierMicroShape = "range" | "point"
1192
1223
  export const resolveVernierRailZone = (pointerCrossAxisOffset: number, orientation: "macro-top" | "macro-bottom" | "macro-left" | "macro-right"): "macro" | "micro" => {
1193
1224
  // orientation に応じて第一レール (上段または左段) がマクロかミクロかを決定
1194
1225
  const isFirstRailMacro = orientation === "macro-top" || orientation === "macro-left"
1195
- const isTargetingFirstRail = pointerCrossAxisOffset <= 0
1226
+ // 画素は左上角で番地付けされるため、中心線から始まる画素は第二レールの帯に属する (ヒットテストと一致)
1227
+ const isTargetingFirstRail = pointerCrossAxisOffset < 0
1196
1228
  return (isFirstRailMacro && isTargetingFirstRail) || !(isFirstRailMacro || isTargetingFirstRail) ? "macro" : "micro"
1197
1229
  }
1198
1230
 
@@ -1223,7 +1255,7 @@ export const resolveWheelStep = (deltaX: number, deltaY: number, isVertical: boo
1223
1255
 
1224
1256
  /**
1225
1257
  * Resolves the target Vernier handle based on pointer primary-axis ratio and cross-axis offset relative to track center.
1226
- * トラック中心線に対するポインターの直交軸オフセットと主軸比率から、操作対象となるノギスハンドル(マクロまたはミクロ)を判定します。
1258
+ * トラック中心線に対するポインターの直交軸オフセットと主軸比率から、操作対象となるノギスハンドル (マクロまたはミクロ) を判定します。
1227
1259
  *
1228
1260
  * @param pointerPrimaryRatio - Pointer position along the track as a 0-1 ratio / トラック主軸上のポインター位置比率 (0-1)
1229
1261
  * @param pointerCrossAxisOffset - Signed pointer offset from the track center line in pixels / トラック中心線からのポインター直交軸オフセット (ピクセル、符号付き)
@@ -1249,7 +1281,7 @@ export function resolveVernierTargetHandle(
1249
1281
  allowConnectHandles: boolean = true,
1250
1282
  microShape: VernierMicroShape = "range",
1251
1283
  ): VernierHandle {
1252
- // orientation に応じて第一レール(上段または左段)がマクロかミクロかを決定
1284
+ // orientation に応じて第一レール (上段または左段) がマクロかミクロかを決定
1253
1285
  if (resolveVernierRailZone(pointerCrossAxisOffset, orientation) === "macro") {
1254
1286
  // マクロ操作ゾーン
1255
1287
  const distLow = Math.abs(pointerPrimaryRatio - macroLowRatio)
@@ -1301,24 +1333,13 @@ export function resolveVernierTargetHandle(
1301
1333
  */
1302
1334
  export function calculateVernierMacroDrag(handle: "macro-low" | "macro-high" | "macro-connect", pointerRatio: number, startPointerRatio: number, startMacroLowRatio: number, startMacroHighRatio: number): [number, number, "macro-low" | "macro-high" | "macro-connect"] {
1303
1335
  if (handle === "macro-connect") {
1304
- const delta = pointerRatio - startPointerRatio
1305
- const width = startMacroHighRatio - startMacroLowRatio
1306
- const nextLow = Math.max(0, Math.min(1 - width, startMacroLowRatio + delta))
1307
- const nextHigh = nextLow + width
1308
- return [nextLow, nextHigh, "macro-connect"]
1309
- }
1310
- if (handle === "macro-low") {
1311
- const clamped = Math.max(0, Math.min(1, pointerRatio))
1312
- if (clamped > startMacroHighRatio) {
1313
- return [startMacroHighRatio, clamped, "macro-high"]
1314
- }
1315
- return [clamped, startMacroHighRatio, "macro-low"]
1336
+ const [bandLowRatio, bandHighRatio] = resolveBandDragRatios(pointerRatio - startPointerRatio, startMacroLowRatio, startMacroHighRatio)
1337
+ return [bandLowRatio, bandHighRatio, "macro-connect"]
1316
1338
  }
1317
- const clamped = Math.max(0, Math.min(1, pointerRatio))
1318
- if (clamped < startMacroLowRatio) {
1319
- return [clamped, startMacroLowRatio, "macro-low"]
1320
- }
1321
- return [startMacroLowRatio, clamped, "macro-high"]
1339
+ const kind = handle === "macro-low" ? "low" : "high"
1340
+ const [nextLowRatio, nextHighRatio] = resolveEdgeDragRatios(kind, pointerRatio, startMacroLowRatio, startMacroHighRatio)
1341
+ const edge = resolveDraggedEdge(kind, pointerRatio, startMacroLowRatio, startMacroHighRatio)
1342
+ return [nextLowRatio, nextHighRatio, edge === "low" ? "macro-low" : "macro-high"]
1322
1343
  }
1323
1344
 
1324
1345
  /**
@@ -1344,28 +1365,17 @@ export function calculateVernierMicroDrag(
1344
1365
  startMicroHighRatio: number,
1345
1366
  ): [number, number, "micro-low" | "micro-high" | "micro-connect" | "micro-point"] {
1346
1367
  if (handle === "micro-point") {
1347
- const clamped = Math.max(0, Math.min(1, pointerRatio))
1348
- return [clamped, clamped, "micro-point"]
1368
+ const [pointRatio] = resolveEdgeDragRatios("point", pointerRatio, startMicroLowRatio, startMicroHighRatio)
1369
+ return [pointRatio, pointRatio, "micro-point"]
1349
1370
  }
1350
1371
  if (handle === "micro-connect") {
1351
- const delta = pointerRatio - startPointerRatio
1352
- const width = startMicroHighRatio - startMicroLowRatio
1353
- const nextLow = Math.max(0, Math.min(1 - width, startMicroLowRatio + delta))
1354
- const nextHigh = nextLow + width
1355
- return [nextLow, nextHigh, "micro-connect"]
1356
- }
1357
- if (handle === "micro-low") {
1358
- const clamped = Math.max(0, Math.min(1, pointerRatio))
1359
- if (clamped > startMicroHighRatio) {
1360
- return [startMicroHighRatio, clamped, "micro-high"]
1361
- }
1362
- return [clamped, startMicroHighRatio, "micro-low"]
1372
+ const [bandLowRatio, bandHighRatio] = resolveBandDragRatios(pointerRatio - startPointerRatio, startMicroLowRatio, startMicroHighRatio)
1373
+ return [bandLowRatio, bandHighRatio, "micro-connect"]
1363
1374
  }
1364
- const clamped = Math.max(0, Math.min(1, pointerRatio))
1365
- if (clamped < startMicroLowRatio) {
1366
- return [clamped, startMicroLowRatio, "micro-low"]
1367
- }
1368
- return [startMicroLowRatio, clamped, "micro-high"]
1375
+ const kind = handle === "micro-low" ? "low" : "high"
1376
+ const [nextLowRatio, nextHighRatio] = resolveEdgeDragRatios(kind, pointerRatio, startMicroLowRatio, startMicroHighRatio)
1377
+ const edge = resolveDraggedEdge(kind, pointerRatio, startMicroLowRatio, startMicroHighRatio)
1378
+ return [nextLowRatio, nextHighRatio, edge === "low" ? "micro-low" : "micro-high"]
1369
1379
  }
1370
1380
 
1371
1381
  /**
@@ -1461,8 +1471,8 @@ const assertSelectionDate = (propName: string, value: unknown): void => {
1461
1471
  }
1462
1472
 
1463
1473
  /**
1464
- * Validates that a selection date lies inside the declared slider domain.
1465
- * 選択日付が宣言済みのスライダー定義域の内側にあることを検証する関数。
1474
+ * Validates that a selection date lies inside the declared slider domain, at the resolution of the scale it is on.
1475
+ * 選択日付が、その選択が載るスケールの解像度で、宣言済みのスライダー定義域の内側にあることを検証する関数。
1466
1476
  *
1467
1477
  * An out-of-domain selection makes the slider report aria-valuenow outside aria-valuemin / aria-valuemax
1468
1478
  * and pin the knob to the rail end while its label shows a date the rail does not contain, so it is
@@ -1470,15 +1480,25 @@ const assertSelectionDate = (propName: string, value: unknown): void => {
1470
1480
  * 定義域外の選択は aria-valuenow が aria-valuemin / aria-valuemax の外側を指し、レール端に貼り付いたつまみが
1471
1481
  * レール上に存在しない日付を表示するため、黙ってクランプせず拒否。
1472
1482
  *
1483
+ * Containment is decided on the encoded key, because the rail is: its ends are `encode(unit, minDate)` and
1484
+ * `encode(unit, maxDate)`, so a domain boundary falling mid period puts the whole of that period on the rail. A raw
1485
+ * timestamp comparison would reject the very value the rail's own end draws - which is what every commit path, the
1486
+ * `Home` / `End` keys and the state hooks hand straight back as a controlled prop.
1487
+ * 内包の判定は符号化キーで行う (レールがそう出来ているため)。レール両端は `encode(unit, minDate)` と
1488
+ * `encode(unit, maxDate)` であり、境界が期間の途中を指せばその期間まるごとがレールに載る。生の時刻で比較すると、
1489
+ * レール自身の端が描いている値を拒むことになる (確定経路・`Home` / `End`・ステートフックがそのまま制御 Props として戻す値)。
1490
+ *
1473
1491
  * @param propName - Prop name quoted in the error message / エラーメッセージへ埋め込む Props 名
1474
1492
  * @param value - Selection date supplied by the consumer / 利用側が指定した選択日付
1493
+ * @param unit - Time resolution unit of the scale the selection sits on / その選択が載るスケールの時間解像度単位
1475
1494
  * @param minDate - Lower domain boundary / 定義域下限
1476
1495
  * @param maxDate - Upper domain boundary / 定義域上限
1477
1496
  * @returns Nothing; the function only throws or returns normally / 戻り値なし (正常時は無返却)
1478
- * @throws RangeError when the value lies outside [minDate, maxDate] / 値が [minDate, maxDate] の外にある場合
1497
+ * @throws RangeError when the value lies outside [minDate, maxDate] at unit resolution / 値が単位解像度で [minDate, maxDate] の外にある場合
1479
1498
  */
1480
- const assertSelectionWithinDomain = (propName: string, value: Date, minDate: Date, maxDate: Date): void => {
1481
- if (value.getTime() < minDate.getTime() || value.getTime() > maxDate.getTime()) {
1499
+ const assertSelectionWithinDomain = (propName: string, value: Date, unit: PeriodSliderUnit, minDate: Date, maxDate: Date): void => {
1500
+ const encoded = encode(unit, value)
1501
+ if (encoded < encode(unit, minDate) || encoded > encode(unit, maxDate)) {
1482
1502
  throw new RangeError(`PeriodSlider: ${propName} must lie within [minDate, maxDate] (received: ${describeDateValue(value)}, minDate: ${describeDateValue(minDate)}, maxDate: ${describeDateValue(maxDate)})`)
1483
1503
  }
1484
1504
  }
@@ -1503,8 +1523,8 @@ const assertSelectionProps = (props: PeriodSliderProps, minDate: Date, maxDate:
1503
1523
  const value = props[propName]
1504
1524
  if (value === undefined) continue
1505
1525
  assertDateRangeTuple(propName, value)
1506
- assertSelectionWithinDomain(`${propName}[0]`, value[0], minDate, maxDate)
1507
- assertSelectionWithinDomain(`${propName}[1]`, value[1], minDate, maxDate)
1526
+ assertSelectionWithinDomain(`${propName}[0]`, value[0], props.unit, minDate, maxDate)
1527
+ assertSelectionWithinDomain(`${propName}[1]`, value[1], props.unit, minDate, maxDate)
1508
1528
  }
1509
1529
  return
1510
1530
  }
@@ -1513,7 +1533,7 @@ const assertSelectionProps = (props: PeriodSliderProps, minDate: Date, maxDate:
1513
1533
  const value = props[propName]
1514
1534
  if (value === undefined) continue
1515
1535
  assertSelectionDate(propName, value)
1516
- assertSelectionWithinDomain(propName, value, minDate, maxDate)
1536
+ assertSelectionWithinDomain(propName, value, props.unit, minDate, maxDate)
1517
1537
  }
1518
1538
  }
1519
1539
 
@@ -1541,19 +1561,24 @@ interface VernierMicroSelection {
1541
1561
  * ミクロ 2 系統は相互排他。両方指定するとつまみ数が決まらず、黙って片方を優先すれば他方のコールバックは永久に鳴らない。
1542
1562
  *
1543
1563
  * The micro selection is a value the user must be able to reach, so it is required to lie inside the
1544
- * declared domain - unlike macroRange, which is deliberately allowed to overhang it (the rails intersect
1545
- * the window with the domain, and the macro callback clamps what it emits).
1546
- * ミクロ選択は利用者が到達できる値であるため宣言済み定義域の内側を要求する。定義域からはみ出すことを
1547
- * 意図的に許している macroRange とは扱いが異なる (レールは窓と定義域の積を取り、マクロ通知はクランプ済みの値を配る)。
1564
+ * declared domain at micro-unit resolution - the resolution the micro rail is drawn at, so "reachable" and
1565
+ * "inside the domain" name the same set. macroRange is deliberately allowed to overhang the domain instead
1566
+ * (the rails intersect the window with the domain, and the macro callback clamps what it emits).
1567
+ * ミクロ選択は利用者が到達できる値であるため、ミクロ単位の解像度で宣言済み定義域の内側を要求する
1568
+ * (ミクロレールが描かれる解像度そのものであり、「到達できる」と「定義域の内側」が同じ集合を指す)。
1569
+ * 定義域からはみ出すことを意図的に許している macroRange とは扱いが異なる
1570
+ * (レールは窓と定義域の積を取り、マクロ通知はクランプ済みの値を配る)。
1548
1571
  *
1549
1572
  * @param props - Raw vernier props the component was rendered with / コンポーネントへ渡された生のノギス Props
1550
1573
  * @param minDate - Lower domain boundary / 定義域下限
1551
1574
  * @param maxDate - Upper domain boundary / 定義域上限
1552
1575
  * @returns Resolved micro shape and the selection tuple seeding the uncontrolled state / 解決済みのミクロ形態と、非制御ステートの初期値となる選択タプル
1553
- * @throws RangeError when macroRange is unusable, when both micro families are supplied, when neither is, or when a supplied micro selection lies outside the domain / macroRange が利用不能な場合、ミクロ 2 系統を同時指定した場合、いずれも未指定の場合、指定されたミクロ選択が定義域外の場合
1576
+ * @throws RangeError when macroRange is unusable, when both micro families are supplied, when neither is, or when a supplied micro selection lies outside the domain at micro-unit resolution / macroRange が利用不能な場合、ミクロ 2 系統を同時指定した場合、いずれも未指定の場合、指定されたミクロ選択がミクロ単位の解像度で定義域外の場合
1554
1577
  */
1555
1578
  const resolveVernierMicroSelection = (props: PeriodSliderVernierProps, minDate: Date, maxDate: Date): VernierMicroSelection => {
1556
1579
  assertDateRangeTuple("macroRange", props.macroRange)
1580
+ // ミクロ選択が載るのはミクロレールであり、定義域の内包もそのレールの解像度で判定する
1581
+ const microUnit = props.microUnit ?? props.unit
1557
1582
 
1558
1583
  const hasRangeProps = props.microRange !== undefined || props.defaultMicroRange !== undefined || props.onChangeMicroRange !== undefined
1559
1584
  const hasPointProps = props.microValue !== undefined || props.defaultMicroValue !== undefined || props.onChangeMicroPoint !== undefined
@@ -1565,12 +1590,12 @@ const resolveVernierMicroSelection = (props: PeriodSliderVernierProps, minDate:
1565
1590
  if (hasPointProps) {
1566
1591
  if (props.microValue !== undefined) {
1567
1592
  assertSelectionDate("microValue", props.microValue)
1568
- assertSelectionWithinDomain("microValue", props.microValue, minDate, maxDate)
1593
+ assertSelectionWithinDomain("microValue", props.microValue, microUnit, minDate, maxDate)
1569
1594
  return { shape: "point", selection: [props.microValue, props.microValue] }
1570
1595
  }
1571
1596
  if (props.defaultMicroValue !== undefined) {
1572
1597
  assertSelectionDate("defaultMicroValue", props.defaultMicroValue)
1573
- assertSelectionWithinDomain("defaultMicroValue", props.defaultMicroValue, minDate, maxDate)
1598
+ assertSelectionWithinDomain("defaultMicroValue", props.defaultMicroValue, microUnit, minDate, maxDate)
1574
1599
  return { shape: "point", selection: [props.defaultMicroValue, props.defaultMicroValue] }
1575
1600
  }
1576
1601
  throw new RangeError("PeriodSlider: vernier point mode requires a micro selection; supply microValue (controlled) or defaultMicroValue (uncontrolled)")
@@ -1578,14 +1603,14 @@ const resolveVernierMicroSelection = (props: PeriodSliderVernierProps, minDate:
1578
1603
 
1579
1604
  if (props.microRange !== undefined) {
1580
1605
  assertDateRangeTuple("microRange", props.microRange)
1581
- assertSelectionWithinDomain("microRange[0]", props.microRange[0], minDate, maxDate)
1582
- assertSelectionWithinDomain("microRange[1]", props.microRange[1], minDate, maxDate)
1606
+ assertSelectionWithinDomain("microRange[0]", props.microRange[0], microUnit, minDate, maxDate)
1607
+ assertSelectionWithinDomain("microRange[1]", props.microRange[1], microUnit, minDate, maxDate)
1583
1608
  return { shape: "range", selection: props.microRange }
1584
1609
  }
1585
1610
  if (props.defaultMicroRange !== undefined) {
1586
1611
  assertDateRangeTuple("defaultMicroRange", props.defaultMicroRange)
1587
- assertSelectionWithinDomain("defaultMicroRange[0]", props.defaultMicroRange[0], minDate, maxDate)
1588
- assertSelectionWithinDomain("defaultMicroRange[1]", props.defaultMicroRange[1], minDate, maxDate)
1612
+ assertSelectionWithinDomain("defaultMicroRange[0]", props.defaultMicroRange[0], microUnit, minDate, maxDate)
1613
+ assertSelectionWithinDomain("defaultMicroRange[1]", props.defaultMicroRange[1], microUnit, minDate, maxDate)
1589
1614
  return { shape: "range", selection: props.defaultMicroRange }
1590
1615
  }
1591
1616
  // 形態を宣言済みの呼び出し側へ他方の形態の救済を示すと、それは型エラーであり、
@@ -1634,6 +1659,25 @@ interface PendingEmitSlot {
1634
1659
  emit: (() => void) | null
1635
1660
  }
1636
1661
 
1662
+ /**
1663
+ * Committed vernier selection as encoded scale positions, the basis every emission is compared against.
1664
+ * 確定しているノギスの選択を符号化した位置 (全ての発火がこれと比較される判定基準)。
1665
+ */
1666
+ interface CommittedVernierScales {
1667
+ /** Unit the macro window is encoded in / マクロ窓を符号化した単位 */
1668
+ macroUnit: PeriodSliderUnit
1669
+ /** Encoded start of the committed macro window / 確定しているマクロ窓開始位置の符号値 */
1670
+ macroLowEnc: number
1671
+ /** Encoded end of the committed macro window / 確定しているマクロ窓終了位置の符号値 */
1672
+ macroHighEnc: number
1673
+ /** Unit the micro selection is encoded in / ミクロ選択を符号化した単位 */
1674
+ microUnit: PeriodSliderUnit
1675
+ /** Encoded start of the committed micro selection / 確定しているミクロ選択開始位置の符号値 */
1676
+ microLowEnc: number
1677
+ /** Encoded end of the committed micro selection / 確定しているミクロ選択終了位置の符号値 */
1678
+ microHighEnc: number
1679
+ }
1680
+
1637
1681
  /**
1638
1682
  * Disarms the pending emission of a slot without running it.
1639
1683
  * 枠に保留中の発火を、実行せずに取り消す関数。
@@ -1734,13 +1778,131 @@ const useMeasuredBorderBox = (): [(element: HTMLElement | null) => void, Measure
1734
1778
  * 衝突回避は 2 枚の実寸で決まる。片方だけでは広い方が分からず押し出し量を誤ってトラックへ食い込ませる
1735
1779
  * ため、片方でも未実測なら既定値を捏造せず「寸法なし」として扱う。
1736
1780
  *
1781
+ * The pair box is `resolvePairBox`, which the range area's label reach reads too.
1782
+ * 対の箱は `resolvePairBox` が決め、範囲領域のラベル到達距離も同じ関数を読む。
1783
+ *
1737
1784
  * @param lowBox - Measured box of the low label, or null while unmeasured / 下限ラベルの実測ボックス (未実測時は null)
1738
1785
  * @param highBox - Measured box of the high label, or null while unmeasured / 上限ラベルの実測ボックス (未実測時は null)
1739
1786
  * @returns Config built from the larger of the pair, or undefined while either box is missing / 対の大きい方から構築した設定 (片方でも欠ければ undefined)
1740
1787
  */
1741
1788
  const buildPairSlantConfig = (lowBox: MeasuredBoxPx | null, highBox: MeasuredBoxPx | null): LabelSlantConfig | undefined => {
1742
- if (lowBox === null || highBox === null) return undefined
1743
- return { estimatedWidthPx: Math.max(lowBox.widthPx, highBox.widthPx), estimatedHeightPx: Math.max(lowBox.heightPx, highBox.heightPx) }
1789
+ const pairBox = resolvePairBox(lowBox, highBox)
1790
+ return pairBox === null ? undefined : { estimatedWidthPx: pairBox.widthPx, estimatedHeightPx: pairBox.heightPx }
1791
+ }
1792
+
1793
+ /**
1794
+ * Resolves the box a label pair is laid out with: the larger extent of both labels, or nothing while either is unmeasured.
1795
+ * ラベル対の配置に使う箱 (両ラベルの大きい方の寸法。片方でも未実測なら無し) を解決する関数。
1796
+ *
1797
+ * @param lowBox - Measured box of the low label, or null while unmeasured / 下限ラベルの実測ボックス (未実測時は null)
1798
+ * @param highBox - Measured box of the high label, or null while unmeasured / 上限ラベルの実測ボックス (未実測時は null)
1799
+ * @returns Larger extent of the pair, or null while either box is missing / 対の大きい方の寸法 (片方でも欠ければ null)
1800
+ */
1801
+ const resolvePairBox = (lowBox: MeasuredBoxPx | null, highBox: MeasuredBoxPx | null): MeasuredBoxPx | null => {
1802
+ if (lowBox === null || highBox === null) return null
1803
+ return { widthPx: Math.max(lowBox.widthPx, highBox.widthPx), heightPx: Math.max(lowBox.heightPx, highBox.heightPx) }
1804
+ }
1805
+
1806
+ /**
1807
+ * Side of the rail centre line, named in reading order: before is top (horizontal) or left (vertical).
1808
+ * レール中心線の側 (読み順で命名。before は横向きで上、縦向きで左)。
1809
+ */
1810
+ export type RailSide = "before" | "after"
1811
+
1812
+ /**
1813
+ * One layer of labels standing on one side of the rail, in the terms the range area needs.
1814
+ * Each layer names the rule its reach follows, so a layer never carries a quantity its rule does not read: a label the
1815
+ * stylesheet stands beside the rail reaches by its own inline size, a label the placement solver rotated reaches by its
1816
+ * rotated half-extent (from the anchor line, or from the rail centre line when the component places its centre there).
1817
+ * レールの片側に立つラベル層を、範囲領域が必要とする量で表したもの。層は到達距離の規則を自ら名乗るため、規則が読まない量を持つことはない
1818
+ * (スタイルシートがレールの横へ置くラベルは自身のインライン方向の寸法、配置解決が回したラベルは回転後の半寸法で届く)。
1819
+ */
1820
+ export type RailSideLabelLayer = {
1821
+ /** Side of the rail the layer stands on / 層が立つレールの側 */
1822
+ side: RailSide
1823
+ /** Box the layer is laid out with, or null while unmeasured / 層の配置に使う箱 (未実測時は null) */
1824
+ box: MeasuredBoxPx | null
1825
+ } & (
1826
+ | {
1827
+ /** The stylesheet anchors the label's inner edge beside the rail; the reach is the label's own inline size / スタイルシートがラベルの内縁をレールの横の基準線へ置く形。到達距離はラベル自身のインライン方向の寸法 */
1828
+ reach: "inline-size"
1829
+ }
1830
+ | {
1831
+ /** The placement solver rotated the label; the reach comes from the rotated half-extent / 配置解決がラベルを回した形。到達距離は回転後の半寸法から求める */
1832
+ reach: "rotated"
1833
+ /** Rotation the placement solver applied, in degrees / 配置解決が与えた回転角 (度) */
1834
+ angleDeg: number
1835
+ /** Label centre from the rail centre line when the component places it there, or null when the stylesheet anchors the inner edge / コンポーネントが中心線基準で置くときの中心線からのラベル中心距離 (スタイルシートが内縁を基準線へ置くときは null) */
1836
+ centreOffsetPx: number | null
1837
+ /** Push the solver applied along the rail, in pixels / 配置解決がレール方向へ与えた押し出し量 (ピクセル) */
1838
+ alongPushPx: number
1839
+ }
1840
+ )
1841
+
1842
+ /**
1843
+ * How far the drawn labels reach, in the two forms the component needs.
1844
+ * 描かれたラベルの到達距離を、コンポーネントが必要とする 2 つの形で表したもの。
1845
+ */
1846
+ export interface LabelReach {
1847
+ /** Inline custom properties the root carries for the stylesheet / スタイルシートのためにルートが持つインラインのカスタムプロパティ */
1848
+ style: CSSProperties
1849
+ /** Along-rail reach in integer pixels / レール方向の到達距離 (整数ピクセル) */
1850
+ mainPx: number
1851
+ }
1852
+
1853
+ /**
1854
+ * Resolves how far the drawn labels reach past the lines the stylesheet anchors them to, as inline custom properties.
1855
+ * 描かれたラベルがスタイルシートの基準線からどこまで届くかを、インラインのカスタムプロパティとして解決する関数。
1856
+ *
1857
+ * A label reaches in two directions and the range area needs both: across the rail it reaches from the anchor line of
1858
+ * its own side, and along the rail it reaches from the knob it is centred on - which stands at the very end of the
1859
+ * rail whenever the value is at a domain bound, so the outer half of that label hangs past the rail. The along-rail
1860
+ * reach is one quantity for the whole area, because both ends of the rail carry the same label geometry.
1861
+ * ラベルは 2 方向へ届き、範囲領域はその双方を必要とする (交差軸では自分の側の基準線から、レール方向では中心に置かれた
1862
+ * つまみから)。つまみは値が定義域の端にあるときレールの端そのものに立つため、そのラベルの外側半分はレールの外へ出る。
1863
+ * レール方向の到達距離は領域全体で 1 つの量 (レールの両端とも同じラベル幾何を載せるため)。
1864
+ *
1865
+ * Only the measured reach crosses from TypeScript to CSS: the anchor line and the lane width depend on lengths the
1866
+ * stylesheet owns, so CSS composes the area from this reach.
1867
+ * TypeScript から CSS へ渡すのは実測した到達距離だけ。基準線とレーンの幅はスタイルシートが持つ長さに依存するため、
1868
+ * 範囲領域の組み立ては CSS が行う。
1869
+ *
1870
+ * The along-rail reach is returned as a number as well as a custom property, because the two tiers that need it
1871
+ * read it in different units: the stylesheet composes the drawn lane from the property, and the wheel ownership rule
1872
+ * inflates the measured rectangle by the same pixels rather than growing the element (an element grown past the root
1873
+ * adds that much scrollable overflow to a tight host, for a region that draws nothing).
1874
+ * レール方向の到達距離はカスタムプロパティと数値の双方で返す。必要とする 2 つの層が別の単位で読むため
1875
+ * (スタイルシートは描かれるレーンをプロパティから組み立て、ホイールの持ち主判定は要素を大きくせず実測した矩形を同じ
1876
+ * ピクセルだけ膨らませる。ルートの外へ大きくした要素は、何も描かない領域のために余裕のないホストへ同じ量の
1877
+ * スクロールのはみ出しを足すため)。
1878
+ *
1879
+ * @param layers - Label layers drawn on the rail / レールに描かれたラベル層
1880
+ * @returns Reach per measured side, the along-rail reach and its pixel value, or undefined when no side has a measured layer / 実測済みの側ごとの到達距離・レール方向の到達距離とそのピクセル値 (実測済みの層が無ければ undefined)
1881
+ */
1882
+ export const resolveLabelReach = (layers: readonly RailSideLabelLayer[]): LabelReach | undefined => {
1883
+ const style: Record<string, string> = {}
1884
+ let mainReachPx = 0
1885
+ for (const layer of layers) {
1886
+ const { side, box } = layer
1887
+ if (box === null) continue
1888
+ let reachPx: number
1889
+ if (layer.reach === "inline-size") {
1890
+ reachPx = box.widthPx
1891
+ // 縦向きのラベルはつまみの高さ中央に置かれるため、レール方向 (縦) へは自身の半分だけ届く
1892
+ mainReachPx = Math.max(mainReachPx, box.heightPx / 2)
1893
+ } else {
1894
+ const rotated = resolveRotatedHalfExtents(box.widthPx, box.heightPx, layer.angleDeg)
1895
+ reachPx = layer.centreOffsetPx === null ? 2 * rotated.acrossPx : Math.abs(layer.centreOffsetPx) + rotated.acrossPx
1896
+ // 押し広げた対はつまみより外へ中心が動く。その分を足さないと、端に着いた対のラベルが領域の外に残る
1897
+ mainReachPx = Math.max(mainReachPx, rotated.alongPx + Math.abs(layer.alongPushPx))
1898
+ }
1899
+ // 整数へ切り上げるのは、傾斜の連続変化で継承カスタムプロパティがフレーム毎に変わり子孫のスタイル再計算を招くため
1900
+ style[`--ps-label-reach-${side}`] = `${Math.ceil(reachPx)}px`
1901
+ }
1902
+ if (Object.keys(style).length === 0) return undefined
1903
+ const mainPx = Math.ceil(mainReachPx)
1904
+ style["--ps-label-reach-main"] = `${mainPx}px`
1905
+ return { style: style as CSSProperties, mainPx }
1744
1906
  }
1745
1907
 
1746
1908
  /**
@@ -1754,6 +1916,8 @@ interface VernierPairPlacement {
1754
1916
  lowStyle: CSSProperties | undefined
1755
1917
  /** Inline placement of the high label, or undefined to keep the rail baseline / 上限ラベルのインライン配置 (undefined はレール基準配置のまま) */
1756
1918
  highStyle: CSSProperties | undefined
1919
+ /** Placement of both labels for the presentation tier to write, or null when the pair keeps the rail baseline / 表示層が書き込むための両枚の配置 (対がレール基準配置のままなら null) */
1920
+ placements: DragLabelPlacementPair
1757
1921
  }
1758
1922
 
1759
1923
  /**
@@ -1763,13 +1927,48 @@ interface VernierPairPlacement {
1763
1927
  * @param offsetX - Horizontal push in pixels / 水平押し出し量 (ピクセル)
1764
1928
  * @param offsetYDelta - Extra vertical push the rotation adds, in pixels / 回転により増える垂直押し出し量 (ピクセル)
1765
1929
  * @param angleDeg - Rotation in degrees / 回転角 (度)
1930
+ * @returns Placement the tooltip transform composes / ツールチップの transform が合成する配置
1931
+ */
1932
+ const buildVernierLabelPlacement = (offsetX: number, offsetYDelta: number, angleDeg: number): DragLabelPlacement => ({
1933
+ tx: `calc(-50% + ${offsetX}px)`,
1934
+ ty: `${offsetYDelta}px`,
1935
+ rot: `${angleDeg}deg`,
1936
+ })
1937
+
1938
+ /**
1939
+ * Expresses one flat-rail label placement from the knob centre the stylesheet places it on.
1940
+ * 平レール (Range / Point) のラベル 1 枚の配置を、スタイルシートが基準に置くつまみ中心から表現する関数。
1941
+ *
1942
+ * @param offsetX - Horizontal push in pixels / 水平押し出し量 (ピクセル)
1943
+ * @param offsetY - Vertical distance from the knob centre in pixels / つまみ中心からの垂直距離 (ピクセル)
1944
+ * @param angleDeg - Rotation in degrees / 回転角 (度)
1945
+ * @returns Placement the tooltip transform composes / ツールチップの transform が合成する配置
1946
+ */
1947
+ const buildFlatLabelPlacement = (offsetX: number, offsetY: number, angleDeg: number): DragLabelPlacement => ({
1948
+ tx: `calc(-50% + ${offsetX}px)`,
1949
+ ty: `calc(-50% + ${offsetY}px)`,
1950
+ rot: `${angleDeg}deg`,
1951
+ })
1952
+
1953
+ /**
1954
+ * Builds the inline style of one label: every placement quantity read as its live variable, committed value as fallback.
1955
+ * ラベル 1 枚のインラインスタイルを構築する関数 (各配置量を実時間の変数として読み、既定値を確定値とする)。
1956
+ *
1957
+ * The drawn distance between two labels is the pointer's, not the committed one, so the anti-collision geometry has to
1958
+ * be solvable while the pointer is down. Reading every quantity through the same `var(<live>, <committed>)` form the
1959
+ * positions use is what lets the presentation tier hand it over without a second write and without a render.
1960
+ * 2 枚のラベルが描かれている距離はポインターのものであり確定値のものではないため、重なり回避の幾何は押している間も解ける必要がある。
1961
+ * 位置と同じ `var(<実時間>, <確定値>)` の形で各量を読むことで、表示層が二度目の書き込みもレンダーも無しに引き渡せる。
1962
+ *
1963
+ * @param prefix - Custom property prefix of this label / このラベルのカスタムプロパティ接頭辞
1964
+ * @param placement - Committed placement of this label / このラベルの確定配置
1766
1965
  * @returns Custom properties the stylesheet substitutes into the tooltip transform / スタイルシートがツールチップの transform へ代入するカスタムプロパティ
1767
1966
  */
1768
- const buildVernierTooltipStyle = (offsetX: number, offsetYDelta: number, angleDeg: number): CSSProperties =>
1967
+ const buildLabelPlacementStyle = (prefix: string, placement: DragLabelPlacement): CSSProperties =>
1769
1968
  ({
1770
- "--ps-tooltip-tx": `calc(-50% + ${offsetX}px)`,
1771
- "--ps-tooltip-ty": `${offsetYDelta}px`,
1772
- "--ps-tooltip-rot": `${angleDeg}deg`,
1969
+ "--ps-tooltip-tx": dragLabelPlacementValue(prefix, "tx", placement.tx),
1970
+ "--ps-tooltip-ty": dragLabelPlacementValue(prefix, "ty", placement.ty),
1971
+ "--ps-tooltip-rot": dragLabelPlacementValue(prefix, "rot", placement.rot),
1773
1972
  }) as CSSProperties
1774
1973
 
1775
1974
  /**
@@ -1791,27 +1990,138 @@ const buildVernierTooltipStyle = (offsetX: number, offsetYDelta: number, angleDe
1791
1990
  * かつ縦レールの CSS 基準配置が別物 (tx: 0px / ty: -50%) のため、ここの結果を書くと対を離すのではなく
1792
1991
  * ラベルを移動させてしまう。
1793
1992
  *
1993
+ * Both tiers solve through here: the committed tier for the positions the values name, the presentation tier for the
1994
+ * positions the pointer is at.
1995
+ * 両層ともこの関数を通して解く (確定層は値が名指す位置に対して、表示層はポインターが居る位置に対して)。
1996
+ *
1997
+ * @param rail - Vernier rail this pair belongs to / この対が属するノギスのレール
1794
1998
  * @param lowRatio - Low handle position along the track as a 0-1 ratio / トラック上の下限つまみ位置比率 (0-1)
1795
1999
  * @param highRatio - High handle position along the track as a 0-1 ratio / トラック上の上限つまみ位置比率 (0-1)
1796
- * @param trackLengthPx - Measured track length in pixels / 実測トラック長 (ピクセル)
1797
- * @param labelPosition - Side of the track this rail draws its labels on / このレールがラベルを描くトラックの側
1798
- * @param config - Measured geometry of this pair, or undefined while unmeasured / この対の実測幾何 (未実測時は undefined)
1799
- * @param isMerged - Whether the pair holds one value and therefore shows one label / 対が同一値で 1 枚だけ見えている状態か
1800
- * @param isSlantable - Whether this rail may slant at all / このレールが傾斜してよいか
1801
- * @returns Geometry of the pair and the inline placement of each of its two labels / 対の幾何と 2 枚それぞれのインライン配置
2000
+ * @param input - Everything the placement depends on besides the two positions / 2 つの位置以外に配置が依存するもの一式
2001
+ * @returns Geometry of the pair, the inline placement of each of its two labels, and the placement the presentation tier writes / 対の幾何、2 枚それぞれのインライン配置、および表示層が書き込む配置
1802
2002
  */
1803
- const solveVernierPairPlacement = (lowRatio: number, highRatio: number, trackLengthPx: number, labelPosition: PeriodSliderLabelPosition, config: LabelSlantConfig | undefined, isMerged: boolean, isSlantable: boolean): VernierPairPlacement => {
1804
- const baseline = buildHorizontalSlantResult(labelPosition, config)
2003
+ const solveVernierPairPlacement = (rail: "macro" | "micro", lowRatio: number, highRatio: number, input: VernierPairPlacementInput): VernierPairPlacement => {
2004
+ const baseline = buildHorizontalSlantResult(input.labelPosition, input.config)
1805
2005
 
1806
- if (!isSlantable) return { slant: baseline, lowStyle: undefined, highStyle: undefined }
2006
+ if (!input.isSlantable) return { slant: baseline, lowStyle: undefined, highStyle: undefined, placements: null }
1807
2007
 
1808
- const solved = calculateLabelSlant(lowRatio * 100, highRatio * 100, trackLengthPx, labelPosition, config)
1809
- const slant = isMerged ? withoutHorizontalPush(solved) : solved
2008
+ const solved = calculateLabelSlant(lowRatio * 100, highRatio * 100, input.trackLengthPx, input.labelPosition, input.config)
2009
+ const slant = input.isMerged ? withoutHorizontalPush(solved) : solved
2010
+ const prefixes = DRAG_LABEL_VARIABLE_PREFIXES[rail]
2011
+ const placements = {
2012
+ low: buildVernierLabelPlacement(slant.lowOffsetX, slant.lowOffsetY - baseline.lowOffsetY, slant.lowAngleDeg),
2013
+ high: buildVernierLabelPlacement(slant.highOffsetX, slant.highOffsetY - baseline.highOffsetY, slant.highAngleDeg),
2014
+ }
1810
2015
 
1811
2016
  return {
1812
2017
  slant,
1813
- lowStyle: buildVernierTooltipStyle(slant.lowOffsetX, slant.lowOffsetY - baseline.lowOffsetY, slant.lowAngleDeg),
1814
- highStyle: buildVernierTooltipStyle(slant.highOffsetX, slant.highOffsetY - baseline.highOffsetY, slant.highAngleDeg),
2018
+ lowStyle: buildLabelPlacementStyle(prefixes.low, placements.low),
2019
+ highStyle: buildLabelPlacementStyle(prefixes.high, placements.high),
2020
+ placements,
2021
+ }
2022
+ }
2023
+
2024
+ /**
2025
+ * Everything a vernier label pair's placement depends on besides the two positions it is solved for.
2026
+ * ノギスのラベルの対の配置が、解く対象の 2 つの位置以外に依存するもの一式。
2027
+ */
2028
+ interface VernierPairPlacementInput {
2029
+ /** Measured track length in pixels / 実測トラック長 (ピクセル) */
2030
+ trackLengthPx: number
2031
+ /** Side of the track this rail draws its labels on / このレールがラベルを描くトラックの側 */
2032
+ labelPosition: PeriodSliderLabelPosition
2033
+ /** Measured geometry of this pair, or undefined while unmeasured / この対の実測幾何 (未実測時は undefined) */
2034
+ config: LabelSlantConfig | undefined
2035
+ /** Whether the pair holds one value and therefore shows one label / 対が同一値で 1 枚だけ見えている状態か */
2036
+ isMerged: boolean
2037
+ /** Whether this rail may slant at all / このレールが傾斜してよいか */
2038
+ isSlantable: boolean
2039
+ }
2040
+
2041
+ /**
2042
+ * Placement the flat rail (`range` / `point`) label pair takes, in both tiers' terms.
2043
+ * 平レール (`range` / `point`) のラベルの対が取る配置を、両層の言葉で表したもの。
2044
+ */
2045
+ interface FlatPairPlacement {
2046
+ /** Geometry solved for the pair / 対に対して解決した傾斜幾何 */
2047
+ slant: LabelSlantResult
2048
+ /** Inline placement of the low label / 下限ラベルのインライン配置 */
2049
+ lowStyle: CSSProperties
2050
+ /** Inline placement of the high label / 上限ラベルのインライン配置 */
2051
+ highStyle: CSSProperties
2052
+ /** Placement of both labels for the presentation tier to write, or null when the placement does not depend on the positions / 表示層が書き込むための両枚の配置 (配置が位置に依存しないなら null) */
2053
+ placements: DragLabelPlacementPair
2054
+ }
2055
+
2056
+ /**
2057
+ * Everything the flat rail's label placement depends on besides the two positions it is solved for.
2058
+ * 平レールのラベル配置が、解く対象の 2 つの位置以外に依存するもの一式。
2059
+ */
2060
+ interface FlatPairPlacementInput {
2061
+ /** Whether one handle selects a single point / つまみ 1 つで時点を選ぶ形態か */
2062
+ isPointMode: boolean
2063
+ /** Whether the slider is drawn vertically / 縦向き描画か */
2064
+ isVertical: boolean
2065
+ /** Whether the host allows the anti-collision rotation / ホストが重なり回避の回転を許すか */
2066
+ autoSlantLabels: boolean
2067
+ /** Whether the pair holds one value and therefore shows one label / 対が同一値で 1 枚だけ見えている状態か */
2068
+ isMerged: boolean
2069
+ /** Measured track length in pixels / 実測トラック長 (ピクセル) */
2070
+ trackLengthPx: number
2071
+ /** Side of the track the labels sit on / ラベルが載るトラックの側 */
2072
+ labelPosition: PeriodSliderLabelPosition
2073
+ /** Measured geometry of the pair, or undefined while unmeasured / 対の実測幾何 (未実測時は undefined) */
2074
+ config: LabelSlantConfig | undefined
2075
+ }
2076
+
2077
+ /** Placement of a vertical slider's labels: the stylesheet stands them beside the rail, so no geometry is solved / 縦向きスライダーのラベルの配置 (スタイルシートがレールの横へ立てるため幾何は解かない) */
2078
+ const VERTICAL_FLAT_LABEL_STYLE = {
2079
+ "--ps-tooltip-origin": "100% 50%",
2080
+ "--ps-tooltip-tx": "0px",
2081
+ "--ps-tooltip-ty": "-50%",
2082
+ "--ps-tooltip-rot": "0deg",
2083
+ } as CSSProperties
2084
+
2085
+ /**
2086
+ * Solves the anti-collision placement of the flat rail's label pair for one pair of positions.
2087
+ * 平レールのラベルの対について、指定の位置の対に対する衝突回避配置を解決する関数。
2088
+ *
2089
+ * Both tiers solve through here: the committed tier for the positions the values name, the presentation tier for the
2090
+ * positions the pointer is at. Anything else would separate the labels for a distance they are not drawn at.
2091
+ * 両層ともこの関数を通して解く (確定層は値が名指す位置に対して、表示層はポインターが居る位置に対して)。
2092
+ * 別経路で解くと、描かれていない距離に対してラベルを離すことになる。
2093
+ *
2094
+ * @param lowPct - Lower label position along the track in percent / トラック上の下限ラベル位置 (百分率)
2095
+ * @param highPct - Upper label position along the track in percent / トラック上の上限ラベル位置 (百分率)
2096
+ * @param input - Everything the placement depends on besides the two positions / 2 つの位置以外に配置が依存するもの一式
2097
+ * @returns Geometry of the pair, the inline placement of each label, and the placement the presentation tier writes / 対の幾何、各ラベルのインライン配置、および表示層が書き込む配置
2098
+ */
2099
+ const solveFlatPairPlacement = (lowPct: number, highPct: number, input: FlatPairPlacementInput): FlatPairPlacement => {
2100
+ const baseline = buildHorizontalSlantResult(input.labelPosition, input.config)
2101
+ // 縦向きは X 軸オフセットしか返さない幾何を適用できない。Point モードは避ける相手そのものが居ない
2102
+ if (input.isVertical) return { slant: baseline, lowStyle: VERTICAL_FLAT_LABEL_STYLE, highStyle: VERTICAL_FLAT_LABEL_STYLE, placements: null }
2103
+
2104
+ const isSolvable = input.autoSlantLabels && !input.isPointMode
2105
+ let slant = baseline
2106
+ if (isSolvable) {
2107
+ const solved = calculateLabelSlant(lowPct, highPct, input.trackLengthPx, input.labelPosition, input.config)
2108
+ // 併合時に残る 1 枚は前面側であり、front は焦点・押下・交差のたび入れ替わる。押し退けを残すと
2109
+ // 唯一のラベルが ±shiftX の間を飛び、離す相手も居ない。角度と垂直オフセットは 90deg のラベルを
2110
+ // つまみから逃がすために必要なので保持し、接近から一致まで角度も位置も連続させる
2111
+ slant = input.isMerged ? withoutHorizontalPush(solved) : solved
2112
+ }
2113
+
2114
+ const prefixes = DRAG_LABEL_VARIABLE_PREFIXES.flat
2115
+ const placements = {
2116
+ low: buildFlatLabelPlacement(slant.lowOffsetX, slant.lowOffsetY, slant.lowAngleDeg),
2117
+ high: buildFlatLabelPlacement(slant.highOffsetX, slant.highOffsetY, slant.highAngleDeg),
2118
+ }
2119
+
2120
+ return {
2121
+ slant,
2122
+ lowStyle: { "--ps-tooltip-origin": "50% 50%", ...buildLabelPlacementStyle(prefixes.low, placements.low) } as CSSProperties,
2123
+ highStyle: { "--ps-tooltip-origin": "50% 50%", ...buildLabelPlacementStyle(prefixes.high, placements.high) } as CSSProperties,
2124
+ placements: isSolvable ? placements : null,
1815
2125
  }
1816
2126
  }
1817
2127
 
@@ -1821,10 +2131,10 @@ const solveVernierPairPlacement = (lowRatio: number, highRatio: number, trackLen
1821
2131
  */
1822
2132
  type StepDirection = "decrease" | "increase"
1823
2133
 
1824
- /** Arrow each stepper direction is drawn with per axis / 軸ごとの各ステッパー方向の矢印 */
1825
- const STEPPER_GLYPHS: Record<"horizontal" | "vertical", Record<StepDirection, string>> = {
1826
- horizontal: { decrease: "◀", increase: "▶" },
1827
- vertical: { decrease: "▼", increase: "▲" },
2134
+ /** Direction each stepper's arrow points per axis / 軸ごとの各ステッパーの矢印の向き */
2135
+ const STEPPER_ARROWS: Record<"horizontal" | "vertical", Record<StepDirection, StepArrowDirection>> = {
2136
+ horizontal: { decrease: "left", increase: "right" },
2137
+ vertical: { decrease: "down", increase: "up" },
1828
2138
  }
1829
2139
 
1830
2140
  /** Position class each stepper direction carries per axis / 軸ごとの各ステッパー方向が持つ配置クラス */
@@ -1833,6 +2143,58 @@ const STEPPER_POSITION_CLASSES: Record<"horizontal" | "vertical", Record<StepDir
1833
2143
  vertical: { decrease: "period-slider-stepper-prev period-slider-stepper-down", increase: "period-slider-stepper-next period-slider-stepper-up" },
1834
2144
  }
1835
2145
 
2146
+ /**
2147
+ * Reserve, inside the slider root, of the distance the round knob's target reaches past the end of the rail: half of
2148
+ * `--ps-target-size`, because the target is centred on a knob that stands on the rail's very end whenever the value is
2149
+ * at a domain bound. Only the rail-only root needs it - with steppers the rail sits a stepper box and a row gap further
2150
+ * in than the knob can reach, and `STEPPER_OUTWARD_RESERVE_CLASSES` already holds the steppers' own reach. Without it
2151
+ * the knob's target hit-tests outside the component, where it takes the presses of a host control, of an adjacent
2152
+ * selector's arrow and of a neighbouring slider, and adds the same amount of scrollable overflow to a tight host.
2153
+ * レール端の外へ丸つまみの当たり判定が伸びる量 (`--ps-target-size` の半分) をスライダーのルートの中へ確保するクラス。
2154
+ * 当たり判定は箱の中心に置かれ、値が定義域の端にあるときつまみはレールの端そのものに立つ。必要なのはレールのみのルートだけ
2155
+ * (ステッパー表示時はボタンの箱と行の間隔の分だけレールが内側へ入り、つまみの到達距離を超えるうえ、
2156
+ * ステッパー自身の到達距離は `STEPPER_OUTWARD_RESERVE_CLASSES` が既に確保している)。確保しないと当たり判定が
2157
+ * コンポーネントの外でヒットテストに答え、ホストの部品・隣のセレクタの矢印・隣のスライダーの押下を奪い、
2158
+ * 余裕のないホストへ同じ量のスクロールのはみ出しを足す。
2159
+ */
2160
+ export const KNOB_OUTWARD_RESERVE_CLASSES: Record<"horizontal" | "vertical", string> = { horizontal: "px-[calc(var(--ps-target-size)/2)]", vertical: "py-[calc(var(--ps-target-size)/2)]" }
2161
+
2162
+ /** Root grid per axis: stepper, rail, stepper when steppers are shown, the rail alone otherwise; either way the outward target reach of the outermost part is reserved inside the root / 軸ごとのルートのグリッド (ステッパー表示時はステッパー・レール・ステッパー、非表示時はレールのみ。いずれも最も外側の部品の当たり判定が外へ伸びる分をルートの中へ確保する) */
2163
+ const ROOT_GRID_CLASSES: Record<"horizontal" | "vertical", Record<"withSteppers" | "railOnly", string>> = {
2164
+ horizontal: { withSteppers: `grid-cols-[auto_minmax(0,1fr)_auto] ${STEPPER_ROW_GAP_CLASS} ${STEPPER_OUTWARD_RESERVE_CLASSES.horizontal}`, railOnly: `grid-cols-[minmax(0,1fr)] ${KNOB_OUTWARD_RESERVE_CLASSES.horizontal}` },
2165
+ vertical: { withSteppers: `grid-rows-[auto_minmax(0,1fr)_auto] ${STEPPER_ROW_GAP_CLASS} ${STEPPER_OUTWARD_RESERVE_CLASSES.vertical}`, railOnly: `grid-rows-[minmax(0,1fr)] ${KNOB_OUTWARD_RESERVE_CLASSES.vertical}` },
2166
+ }
2167
+
2168
+ /** Explicit cell of each root child per axis; the range area spans every cell, so auto-placement would push the rest into a new row / 軸ごとのルートの子の明示セル (範囲領域が全セルを占めるため、自動配置だと残りが次の行へ押し出される) */
2169
+ const ROOT_GRID_CELL_CLASSES: Record<"horizontal" | "vertical", Record<"leading" | "rail" | "railOnly" | "trailing", string>> = {
2170
+ horizontal: { leading: "col-start-1 row-start-1", rail: "col-start-2 row-start-1", railOnly: "col-start-1 row-start-1", trailing: "col-start-3 row-start-1" },
2171
+ vertical: { leading: "col-start-1 row-start-1", rail: "col-start-1 row-start-2", railOnly: "col-start-1 row-start-1", trailing: "col-start-1 row-start-3" },
2172
+ }
2173
+
2174
+ /**
2175
+ * Binds the rest of a pointer gesture to the element it began on.
2176
+ * ポインター操作の残りすべてを、操作が始まった要素へ結び付ける関数。
2177
+ *
2178
+ * Without capture the browser keeps delivering the gesture to whatever lies under the pointer, so a release that
2179
+ * happens over another document (any same-page `<iframe>`) is delivered there and this document's window listeners
2180
+ * never see the end of the gesture: the drag stays live for ever, keeps following a cursor with no button pressed,
2181
+ * keeps publishing values, and keeps out the wheel, the arrow keys and the steppers, which all stand down while a
2182
+ * gesture owns the value. With capture every move and the release are retargeted to the grabbed element, so they
2183
+ * reach this document's window listeners wherever the pointer travels.
2184
+ * 捕捉しなければ、ブラウザは操作をポインターの下にあるものへ配送し続ける。別文書 (同一ページの `<iframe>`) の上で
2185
+ * 離された解放はそちらへ配送され、この文書の window リスナーは操作の終わりを 1 度も見ない。掴みは永久に生き続け、
2186
+ * ボタンを押していないカーソルを追い続け、値を発火し続け、操作が値を持つ間は退く規則のホイール・矢印キー・ステッパーを
2187
+ * 締め出したままになる。捕捉すれば移動も解放も掴んだ要素へ宛て直されるため、ポインターがどこへ行っても
2188
+ * この文書の window リスナーへ届く。
2189
+ *
2190
+ * @param grabbed - Element the press landed on / 押下が当たった要素
2191
+ * @param pointerId - Pointer the gesture owns / 操作が持つポインターの識別子
2192
+ * @returns Nothing / 戻り値なし
2193
+ */
2194
+ const captureGesturePointer = (grabbed: Element, pointerId: number): void => {
2195
+ grabbed.setPointerCapture(pointerId)
2196
+ }
2197
+
1836
2198
  // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Vernier integrated multi-mode scale requires comprehensive coordinate handling
1837
2199
  const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1838
2200
  const {
@@ -1875,7 +2237,6 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1875
2237
  const vernierGradId = useId()
1876
2238
 
1877
2239
  const propsRef = useRef(props)
1878
- propsRef.current = props
1879
2240
 
1880
2241
  const minTime = minDate.getTime()
1881
2242
  const maxTime = maxDate.getTime()
@@ -1983,7 +2344,6 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1983
2344
  const [draggingValues, setDraggingValues] = useState<[number, number] | null>(null)
1984
2345
  const [activeHandle, setActiveHandle] = useState<"low" | "high" | "connect" | null>(null)
1985
2346
  const activeHandleRef = useRef<"low" | "high" | "connect" | null>(null)
1986
- activeHandleRef.current = activeHandle
1987
2347
  const [frontHandle, setFrontHandle] = useState<"low" | "high">("high")
1988
2348
 
1989
2349
  const [hoverValue, setHoverValue] = useState<number | null>(null)
@@ -1995,7 +2355,6 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1995
2355
  // 重複発火の判定基準。「最後に発火した値」を覚えると、利用側が別経路で選択を戻した瞬間に基準が実態から外れ、
1996
2356
  // その値へ二度と戻れなくなる。いま確定している選択そのものを基準にすればずれようがない
1997
2357
  const committedValuesRef = useRef<[number, number]>([currentLowVal, currentHighVal])
1998
- committedValuesRef.current = [currentLowVal, currentHighVal]
1999
2358
 
2000
2359
  // ------------------------------------------------------------------
2001
2360
  // C-2. ノギススケールの境界とドラッグ状態
@@ -2026,7 +2385,6 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2026
2385
 
2027
2386
  const [activeVernierHandle, setActiveVernierHandle] = useState<VernierHandle | null>(null)
2028
2387
  const activeVernierHandleRef = useRef<VernierHandle | null>(null)
2029
- activeVernierHandleRef.current = activeVernierHandle
2030
2388
  // 初期前面は実在するつまみでなければならない。時点形態に micro-high は無く、
2031
2389
  // 描かれないハンドルを初期値にすると最初の 1 回だけ前面が誰も指さない状態になる
2032
2390
  const [frontVernierHandleState, setFrontVernierHandle] = useState<VernierHandle>(() => (isMicroPointShape ? "micro-point" : "micro-high"))
@@ -2164,6 +2522,12 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2164
2522
  const vernierMicroLowDate = useMemo(() => decode(microUnit, vernierMicroLowEnc), [microUnit, vernierMicroLowEnc])
2165
2523
  const vernierMicroHighDate = useMemo(() => decode(microUnit, vernierMicroHighEnc), [microUnit, vernierMicroHighEnc])
2166
2524
 
2525
+ // 重複発火の判定基準。ミクロ側は利用側が保持している選択そのものを符号化する (レールへ載せた表示値を基準にすると、
2526
+ // 窓の外へ出た選択を窓の中へ収め直す訂正が、比較の両辺が同値になって発火しなくなる)
2527
+ const committedVernierScales: CommittedVernierScales | null =
2528
+ !isVernierMode || vernierMicroSelection === null ? null : { macroUnit, macroLowEnc: vernierMacroLowEnc, macroHighEnc: vernierMacroHighEnc, microUnit, microLowEnc: encode(microUnit, vernierMicroSelection[0]), microHighEnc: encode(microUnit, vernierMicroSelection[1]) }
2529
+ const committedVernierRef = useRef(committedVernierScales)
2530
+
2167
2531
  // 比率 (0.0 〜 1.0)。離散レールは当たり判定と同じ候補空間で描かないと、つまみがポインターから離れて飛ぶ
2168
2532
  const macroSpan = Math.max(1, vernierMacroMaxEnc - vernierMacroMinEnc)
2169
2533
  const macroLowRatio = macroIsDiscreteScale ? discreteDateToRailRatio(sortedMacroAllowedDates, macroUnit, snapMode, vernierMacroLowDate) : Math.max(0, Math.min(1, (vernierMacroLowEnc - vernierMacroMinEnc) / macroSpan))
@@ -2279,10 +2643,15 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2279
2643
  */
2280
2644
  const notifyMacroRange = useCallback(
2281
2645
  (lower: Date, upper: Date, immediate = false) => {
2282
- if (propsRef.current.mode !== "vernier") return
2646
+ const committed = committedVernierRef.current
2647
+ // 判定基準を持たないのはノギス以外のモードのときだけ
2648
+ if (propsRef.current.mode !== "vernier" || committed === null) return
2283
2649
  // 境界は macroUnit の先頭へ丸められるため、そのままでは minDate より前の日付を利用側へ渡してしまう
2284
2650
  const clampedLower = clampToDomain(lower)
2285
2651
  const clampedUpper = clampToDomain(upper)
2652
+ // 選択が動いていない確定値でコールバックを撃つと、変更駆動の消費側が無意味な再取得を行う。
2653
+ // デバウンス保留中だけは例外で、予約済みの古い値を確定値で上書きしないと最後の位置が消える (notifyChange と同じ規則)
2654
+ if (encode(committed.macroUnit, clampedLower) === committed.macroLowEnc && encode(committed.macroUnit, clampedUpper) === committed.macroHighEnc && macroEmitRef.current.timerId === null) return
2286
2655
  scheduleEmit(
2287
2656
  macroEmitRef.current,
2288
2657
  () => {
@@ -2312,9 +2681,13 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2312
2681
  const notifyMicroSelection = useCallback(
2313
2682
  (lower: Date, upper: Date, immediate = false) => {
2314
2683
  const p = propsRef.current
2315
- if (p.mode !== "vernier") return
2684
+ const committed = committedVernierRef.current
2685
+ // 判定基準を持たないのはノギス以外のモードのときだけ
2686
+ if (p.mode !== "vernier" || committed === null) return
2316
2687
  const clampedLower = clampToDomain(lower)
2317
2688
  const clampedUpper = clampToDomain(upper)
2689
+ // マクロ側と同じ規則 (動いていない選択では鳴らさない。デバウンス保留中だけは例外)
2690
+ if (encode(committed.microUnit, clampedLower) === committed.microLowEnc && encode(committed.microUnit, clampedUpper) === committed.microHighEnc && microEmitRef.current.timerId === null) return
2318
2691
  // 非制御時はここが唯一の自律更新点。書かなければコールバックだけが鳴り、つまみは初期位置で固まる。
2319
2692
  // デバウンス対象は利用側への通知のみで、つまみ追従までは遅らせない
2320
2693
  if (isMicroPointShape ? p.microValue === undefined : p.microRange === undefined) {
@@ -2407,7 +2780,13 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2407
2780
  // ------------------------------------------------------------------
2408
2781
  // F. ポインター座標追跡とトラック実測
2409
2782
  // ------------------------------------------------------------------
2783
+ const rootRef = useRef<HTMLDivElement | null>(null)
2784
+ const rangeAreaRef = useRef<HTMLDivElement | null>(null)
2785
+ const labelReachMainRef = useRef(0)
2410
2786
  const trackRef = useRef<HTMLDivElement | null>(null)
2787
+ const projectionRef = useRef<SVGPathElement | null>(null)
2788
+ const decreaseStepperRef = useRef<HTMLButtonElement | null>(null)
2789
+ const increaseStepperRef = useRef<HTMLButtonElement | null>(null)
2411
2790
  const [trackLength, setTrackLength] = useState<number>(0)
2412
2791
 
2413
2792
  const [lowLabelRef, lowLabelBox] = useMeasuredBorderBox()
@@ -2420,6 +2799,40 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2420
2799
  const [microLowLabelRef, microLowLabelBox] = useMeasuredBorderBox()
2421
2800
  const [microHighLabelRef, microHighLabelBox] = useMeasuredBorderBox()
2422
2801
 
2802
+ // Point モードはラベルが 1 枚で、その 1 枚の実寸がそのまま直立基準の高さになる。
2803
+ // 対になる 2 枚の規則 (片方でも未実測なら寸法なし) は buildPairSlantConfig が一手に持つ
2804
+ const labelSlantConfig: LabelSlantConfig | undefined = isPointMode ? (lowLabelBox === null ? undefined : { estimatedWidthPx: lowLabelBox.widthPx, estimatedHeightPx: lowLabelBox.heightPx }) : buildPairSlantConfig(lowLabelBox, highLabelBox)
2805
+
2806
+ // 値が一致するとき 2 枚のラベルは文字列まで同一になる (valueToDate が純粋なので構造的に保証される)。
2807
+ // ピクセル距離では別日と区別できないため判定は必ず値で行う。
2808
+ // point モードは上限値を下限値へ寄せるため素の一致判定が恒真になり、!isPointMode で外さないと成立しない
2809
+ const isLabelMerged = !isPointMode && currentLowVal === currentHighVal
2810
+
2811
+ // ノギスの 2 対も Range と同じ根拠で畳む。マクロ・ミクロとも符号化値から復元した日付を整形するため、
2812
+ // 符号化値が一致すればラベルは文字列まで一致する。しかもノギスには押し退けが無く 2 枚が同一矩形へ
2813
+ // 完全に重なるため、畳まないと同じ値が二重に読み上げられるだけで視覚的な情報も増えない
2814
+ const isVernierMacroLabelMerged = vernierMacroLowEnc === vernierMacroHighEnc
2815
+ // 時点形態のミクロラベルは 1 枚しか無い。畳み込み判定は恒真になるため、Point モードの !isPointMode と
2816
+ // 同じ理由で形態ごと外す (外さないと唯一のラベルが重複として隠れる)
2817
+ const isVernierMicroLabelMerged = !isMicroPointShape && vernierMicroLowEnc === vernierMicroHighEnc
2818
+
2819
+ // ラベルが載る面はつまみと同じ側であり、JSX の data-vernier-pos が示す面と必ず一致する
2820
+ const macroRailLabelPosition: PeriodSliderLabelPosition = isMacroFirstRail ? "top" : "bottom"
2821
+ const microRailLabelPosition: PeriodSliderLabelPosition = isMacroFirstRail ? "bottom" : "top"
2822
+
2823
+ // 傾斜可否はレール単位で決まる。縦向きノギスは縦向き Range と同じ理由で外す (solveVernierPairPlacement 参照)
2824
+ const isVernierSlantable = autoSlantLabels && !isVertical
2825
+ // 傾斜は接近した対を離すための機構であり、時点形態には離す相手が居ない。Point モードが
2826
+ // buildHorizontalSlantResult へ落ちるのと同じく、直立のまま置く
2827
+ const isMicroPairSlantable = isVernierSlantable && !isMicroPointShape
2828
+
2829
+ // 位置以外の入力は 3 レールとも 1 度だけ組む。確定層 (レンダー) と表示層 (ポインター移動) が同じものを読むため、
2830
+ // ラベルを離す距離が「描かれている距離」から外れることが構造的に起こらない。
2831
+ // マクロとミクロは同じトラックの上で比率も単位空間もラベル幅も異なるため、対ごとに独立して解く
2832
+ const flatPlacementInput: FlatPairPlacementInput = { isPointMode, isVertical, autoSlantLabels, isMerged: isLabelMerged, trackLengthPx: trackLength, labelPosition, config: labelSlantConfig }
2833
+ const macroPairInput: VernierPairPlacementInput = { trackLengthPx: trackLength, labelPosition: macroRailLabelPosition, config: buildPairSlantConfig(macroLowLabelBox, macroHighLabelBox), isMerged: isVernierMacroLabelMerged, isSlantable: isVernierSlantable }
2834
+ const microPairInput: VernierPairPlacementInput = { trackLengthPx: trackLength, labelPosition: microRailLabelPosition, config: buildPairSlantConfig(microLowLabelBox, microHighLabelBox), isMerged: isVernierMicroLabelMerged, isSlantable: isMicroPairSlantable }
2835
+
2423
2836
  useEffect(() => {
2424
2837
  const el = trackRef.current
2425
2838
  if (!el) return
@@ -2445,8 +2858,11 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2445
2858
  return () => ro.disconnect()
2446
2859
  }
2447
2860
 
2448
- window.addEventListener("resize", updateDimensions)
2449
- return () => window.removeEventListener("resize", updateDimensions)
2861
+ // ResizeObserver を持たない環境の代替。ここも事象を配送するのはトラックが描かれている文書の window
2862
+ const view = el.ownerDocument.defaultView
2863
+ if (!view) return
2864
+ view.addEventListener("resize", updateDimensions)
2865
+ return () => view.removeEventListener("resize", updateDimensions)
2450
2866
  }, [isVertical])
2451
2867
 
2452
2868
  const calcRatioFromPos = useCallback(
@@ -2472,6 +2888,152 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2472
2888
  [calcRatioFromPos],
2473
2889
  )
2474
2890
 
2891
+ // ------------------------------------------------------------------
2892
+ // F-2. ドラッグ表示層 (値層とは別に、いま指が居る位置を描く)
2893
+ // ------------------------------------------------------------------
2894
+ const dragPresentationRef = useRef<{ rail: DragPresentationRail; lowRatio: number; highRatio: number } | null>(null)
2895
+ const snapBackTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
2896
+
2897
+ // 表示層の書き込みはポインターのイベントから呼ばれ、その時点の向き・確定値・実測寸法を読まなければならない。
2898
+ // useCallback の依存に並べる形では、依存に載せ忘れた 1 つが「離した瞬間だけ古い形へ戻る」形で表に出る (ポインター移動と同じ手)。
2899
+ // 持ち替えはレンダー中ではなくコミット後に行う。破棄されたレンダーでも本体は走るため、レンダー中に書くと
2900
+ // 画面に出ていない値が残り得る (ホストが startTransition の下でこのコンポーネントを駆動する場合に起こる)
2901
+ const projectionGeometryRef = useRef({ macroLowRatio, macroHighRatio, isVertical, isMacroFirstRail })
2902
+ const labelPlacementInputsRef = useRef({ flat: flatPlacementInput, macro: macroPairInput, micro: microPairInput })
2903
+
2904
+ useLayoutEffect(() => {
2905
+ projectionGeometryRef.current = { macroLowRatio, macroHighRatio, isVertical, isMacroFirstRail }
2906
+ labelPlacementInputsRef.current = { flat: flatPlacementInput, macro: macroPairInput, micro: microPairInput }
2907
+ // 事象の時点でレンダーの値を読む口はどれも同じ規則に従う (持ち替えはレンダー中ではなくコミット後)。
2908
+ // Props・確定値・掴んでいるつまみは、破棄されたレンダーの値を残すと、画面に出ていない値で
2909
+ // コールバックの抑止判定と前面の判定が行われる
2910
+ propsRef.current = props
2911
+ committedValuesRef.current = [currentLowVal, currentHighVal]
2912
+ committedVernierRef.current = committedVernierScales
2913
+ activeHandleRef.current = activeHandle
2914
+ activeVernierHandleRef.current = activeVernierHandle
2915
+ })
2916
+
2917
+ /**
2918
+ * Draws the projection cone for a given macro window pair.
2919
+ * 指定のマクロ窓の対に対して、台形プロジェクションを描く関数。
2920
+ *
2921
+ * @param lowRatio - Macro window start as a 0-1 ratio / マクロ窓開始位置の比率 (0-1)
2922
+ * @param highRatio - Macro window end as a 0-1 ratio / マクロ窓終了位置の比率 (0-1)
2923
+ * @returns Nothing / 戻り値なし
2924
+ */
2925
+ const writeProjectionPath = (lowRatio: number, highRatio: number): void => {
2926
+ const geometry = projectionGeometryRef.current
2927
+ projectionRef.current?.setAttribute("d", buildVernierProjectionPath(lowRatio, highRatio, geometry.isVertical, geometry.isMacroFirstRail))
2928
+ }
2929
+
2930
+ /**
2931
+ * Solves the anti-collision placement of the label pair drawn at a given position pair.
2932
+ * 指定の位置の対へ描かれるラベルの対について、衝突回避配置を解決する関数。
2933
+ *
2934
+ * @param rail - Rail the drag moves / ドラッグが動かすレール
2935
+ * @param lowRatio - Lower label position as a 0-1 ratio / 下限側のラベル位置 (0-1 比率)
2936
+ * @param highRatio - Upper label position as a 0-1 ratio / 上限側のラベル位置 (0-1 比率)
2937
+ * @returns Placement of both labels, or null when the pair's placement does not depend on the positions / 両枚の配置 (対の配置が位置に依存しないなら null)
2938
+ */
2939
+ const solveLiveLabelPlacement = (rail: DragPresentationRail, lowRatio: number, highRatio: number): DragLabelPlacementPair => {
2940
+ const inputs = labelPlacementInputsRef.current
2941
+ if (rail === "flat") return solveFlatPairPlacement(lowRatio * 100, highRatio * 100, inputs.flat).placements
2942
+ return solveVernierPairPlacement(rail, lowRatio, highRatio, rail === "macro" ? inputs.macro : inputs.micro).placements
2943
+ }
2944
+
2945
+ /**
2946
+ * Draws one rail's parts at the position the pointer is actually at.
2947
+ * 1 つのレールの部品を、ポインターが実際に居る位置へ描く関数。
2948
+ *
2949
+ * @param rail - Rail the drag moves / ドラッグが動かすレール
2950
+ * @param lowRatio - Lower part position as a 0-1 ratio / 下限側の位置 (0-1 比率)
2951
+ * @param highRatio - Upper part position as a 0-1 ratio / 上限側の位置 (0-1 比率)
2952
+ * @returns Nothing / 戻り値なし
2953
+ */
2954
+ const applyDragPresentation = (rail: DragPresentationRail, lowRatio: number, highRatio: number): void => {
2955
+ const track = trackRef.current
2956
+ if (!track) return
2957
+ dragPresentationRef.current = { rail, lowRatio, highRatio }
2958
+ writeDragPresentation(track, rail, lowRatio, highRatio)
2959
+ const placements = solveLiveLabelPlacement(rail, lowRatio, highRatio)
2960
+ if (placements !== null) writeDragLabelPlacement(track, rail, placements)
2961
+ // コーンの根元はマクロ帯そのもの。マクロを動かしている間だけ、帯と同じ対から描き直す
2962
+ if (rail === "macro") writeProjectionPath(lowRatio, highRatio)
2963
+ }
2964
+
2965
+ /**
2966
+ * Closes the settling window, so the parts it was interpolating stand still again.
2967
+ * 収め戻しの窓を閉じ、補間中だった部品を再び静止させる関数。
2968
+ *
2969
+ * Two callers need it, for one reason each. A fresh grab has to start from a part that is standing still,
2970
+ * otherwise the first `DRAG_SNAP_BACK_MS` of the new drag run through the settling transition and the knob lags
2971
+ * the finger. And a change that did not come from a drag - a key, a wheel, a stepper - must never be interpolated
2972
+ * at all; landing inside the window of a just-released drag is the only way it could be.
2973
+ * 呼び出し元は 2 つあり、理由はそれぞれ別。掴み直しは静止した部品から始めなければならない
2974
+ * (でなければ新しいドラッグの最初の `DRAG_SNAP_BACK_MS` が収め戻しの遷移を通り、つまみが指から遅れる)。
2975
+ * そしてドラッグ以外の変化 (キー・ホイール・ステッパー) は決して補間されてはならず、
2976
+ * 直前に離したドラッグの窓の中で起こることがその唯一の抜け道。
2977
+ *
2978
+ * @returns Nothing / 戻り値なし
2979
+ */
2980
+ const cancelSnapBack = useCallback((): void => {
2981
+ if (snapBackTimerRef.current !== null) {
2982
+ clearTimeout(snapBackTimerRef.current)
2983
+ snapBackTimerRef.current = null
2984
+ }
2985
+ const track = trackRef.current
2986
+ if (!track) return
2987
+ track.removeAttribute(DRAG_SNAP_ATTRIBUTE)
2988
+ track.style.removeProperty(DRAG_SNAP_DURATION_VARIABLE)
2989
+ }, [])
2990
+
2991
+ /**
2992
+ * Hands every part back to its committed position and opens the window during which it settles there.
2993
+ * 全部品を確定位置へ返し、そこへ収まるまでの窓を開く関数。
2994
+ *
2995
+ * A press that never moved wrote no position, so it opens no window: only a drag that actually left the
2996
+ * committed position has anything to settle back onto.
2997
+ * 一度も動かなかった押下は位置を書いていないため窓を開かない (収め戻す先を持つのは、確定位置から実際に離れたドラッグだけ)。
2998
+ *
2999
+ * @returns Nothing / 戻り値なし
3000
+ */
3001
+ const endDragPresentation = (): void => {
3002
+ const track = trackRef.current
3003
+ if (dragPresentationRef.current === null || !track) {
3004
+ dragPresentationRef.current = null
3005
+ return
3006
+ }
3007
+ dragPresentationRef.current = null
3008
+ if (snapBackTimerRef.current !== null) clearTimeout(snapBackTimerRef.current)
3009
+ track.style.setProperty(DRAG_SNAP_DURATION_VARIABLE, `${DRAG_SNAP_BACK_MS}ms`)
3010
+ track.setAttribute(DRAG_SNAP_ATTRIBUTE, "true")
3011
+ clearDragPresentation(track)
3012
+ // `d` は CSS 変数を読めないため、確定形状も表示層が書き戻す。React の持つ値と同一なので描画はこの 1 回で終わる
3013
+ writeProjectionPath(projectionGeometryRef.current.macroLowRatio, projectionGeometryRef.current.macroHighRatio)
3014
+ snapBackTimerRef.current = setTimeout(() => {
3015
+ snapBackTimerRef.current = null
3016
+ track.removeAttribute(DRAG_SNAP_ATTRIBUTE)
3017
+ // 窓を閉じたら継続時間も持ち帰る。残すと静止中のトラックが、次の掴みまで意味を持たない宣言を抱えたままになる
3018
+ track.style.removeProperty(DRAG_SNAP_DURATION_VARIABLE)
3019
+ }, DRAG_SNAP_BACK_MS)
3020
+ }
3021
+
3022
+ // 変数はトラックの style 属性にあり React は触れないが、コーンの `d` だけは React が Props として持つ。
3023
+ // ドラッグ中に確定値が 1 段進むと React がそれを書き戻してしまうため、描画のたびに表示層が取り返す
3024
+ useLayoutEffect(() => {
3025
+ const live = dragPresentationRef.current
3026
+ if (live === null) return
3027
+ applyDragPresentation(live.rail, live.lowRatio, live.highRatio)
3028
+ })
3029
+
3030
+ useEffect(
3031
+ () => () => {
3032
+ if (snapBackTimerRef.current !== null) clearTimeout(snapBackTimerRef.current)
3033
+ },
3034
+ [],
3035
+ )
3036
+
2475
3037
  // ------------------------------------------------------------------
2476
3038
  // G. ドラッグ操作とイベント購読
2477
3039
  // ------------------------------------------------------------------
@@ -2481,6 +3043,8 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2481
3043
  startPointerPos: number
2482
3044
  startLowVal: number
2483
3045
  startHighVal: number
3046
+ startLowRatio: number
3047
+ startHighRatio: number
2484
3048
  } | null>(null)
2485
3049
 
2486
3050
  const vernierDragContextRef = useRef<{
@@ -2500,303 +3064,347 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2500
3064
  const lastEmittedMacroRangeRef = useRef<string | null>(null)
2501
3065
  const lastEmittedMicroRangeRef = useRef<string | null>(null)
2502
3066
 
2503
- const handleGlobalPointerMove = useCallback(
2504
- (e: PointerEvent) => {
2505
- if (disabled) return
2506
-
2507
- if (isVernierMode) {
2508
- const vCtx = vernierDragContextRef.current
2509
- if (!vCtx || (e.pointerId !== 0 && e.pointerId !== vCtx.pointerId)) return
2510
- if (!trackRef.current) return
2511
- const pointerRatio = calcRatioFromPos(e.clientX, e.clientY, trackRef.current.getBoundingClientRect())
2512
- if (pointerRatio === null) return
2513
-
2514
- if (vCtx.handle === "macro-low" || vCtx.handle === "macro-high" || vCtx.handle === "macro-connect") {
2515
- const [nextMacroLowRatio, nextMacroHighRatio, activeMacroHandle] = calculateVernierMacroDrag(vCtx.handle, pointerRatio, vCtx.startPointerRatio, vCtx.startMacroLowRatio, vCtx.startMacroHighRatio)
2516
- if (activeMacroHandle !== activeVernierHandleRef.current) {
2517
- activeVernierHandleRef.current = activeMacroHandle
2518
- setActiveVernierHandle(activeMacroHandle)
2519
- setFrontVernierHandle(activeMacroHandle)
2520
- }
3067
+ /**
3068
+ * Tells whether a pointer gesture currently owns the value.
3069
+ * いまポインター操作が値の持ち主かどうかを返す関数。
3070
+ *
3071
+ * One gesture owns the value from its press to its release, and every other path that could change the value -
3072
+ * a second pointer, a wheel notch, an arrow key, a stepper - returns while it is live. Without that rule the
3073
+ * drag recomputes the pair from the snapshot it took at the press and silently takes the other path's change
3074
+ * back, after the host has already been handed it as final.
3075
+ * 1 つの操作が押下から解放まで値の持ち主であり、値を変え得る他の経路 (2 本目のポインター・ホイールの 1 段・矢印キー・
3076
+ * ステッパー) はその間ずっと戻る。この規則が無いと、ドラッグは押下時に取った控えから対を計算し直し、確定として
3077
+ * 利用側へ渡した後の他経路の変更を黙って取り消す。
3078
+ *
3079
+ * @returns Whether a flat or vernier drag context is live / 平レール・ノギスのいずれかのドラッグ文脈が生きているか
3080
+ */
3081
+ const isGestureLive = useCallback((): boolean => dragContextRef.current !== null || vernierDragContextRef.current !== null, [])
2521
3082
 
2522
- let nextMacroLowDate: Date
2523
- let nextMacroHighDate: Date
2524
- if (macroIsDiscreteScale) {
2525
- const lowIdx = railRatioToDiscreteIndex(sortedMacroAllowedDates, macroUnit, snapMode, nextMacroLowRatio)
2526
- const highIdx = Math.max(lowIdx, railRatioToDiscreteIndex(sortedMacroAllowedDates, macroUnit, snapMode, nextMacroHighRatio))
2527
- nextMacroLowDate = sortedMacroAllowedDates[lowIdx]
2528
- nextMacroHighDate = sortedMacroAllowedDates[highIdx]
2529
- } else {
2530
- const nextLowEnc = Math.round(vernierMacroMinEnc + nextMacroLowRatio * macroSpan)
2531
- const nextHighEnc = Math.round(vernierMacroMinEnc + nextMacroHighRatio * macroSpan)
2532
- nextMacroLowDate = decode(macroUnit, nextLowEnc)
2533
- nextMacroHighDate = decode(macroUnit, nextHighEnc)
2534
- }
3083
+ /**
3084
+ * Draws and publishes the value under the pointer for the gesture that owns the drag.
3085
+ * ドラッグの持ち主である操作について、ポインターの下の値を描き、発火するハンドラ。
3086
+ *
3087
+ * The listener dispatches through a ref assigned after every commit, so the handler needs no memoised
3088
+ * identity: it is read fresh at event time and closes over the values of the render that is on screen.
3089
+ * リスナーは毎コミット後に持ち替える ref 経由で呼ぶため、この関数はメモ化した同一性を必要としない
3090
+ * (事象の時点で読み直され、画面に出ているレンダーの値を閉じ込める)。
3091
+ *
3092
+ * @param e - Pointer move delivered to the window while a drag is live / ドラッグ中に window へ配送されたポインター移動
3093
+ * @returns Nothing / 戻り値なし
3094
+ */
3095
+ const handleGlobalPointerMove = (e: PointerEvent): void => {
3096
+ if (disabled) return
2535
3097
 
2536
- const macroKey = `${nextMacroLowDate.getTime()}_${nextMacroHighDate.getTime()}`
2537
- if (macroKey !== lastEmittedMacroRangeRef.current) {
2538
- lastEmittedMacroRangeRef.current = macroKey
2539
- notifyMacroRange(nextMacroLowDate, nextMacroHighDate)
2540
- }
3098
+ if (isVernierMode) {
3099
+ const vCtx = vernierDragContextRef.current
3100
+ if (!vCtx || e.pointerId !== vCtx.pointerId) return
3101
+ if (!trackRef.current) return
3102
+ const pointerRatio = calcRatioFromPos(e.clientX, e.clientY, trackRef.current.getBoundingClientRect())
3103
+ if (pointerRatio === null) return
3104
+
3105
+ if (vCtx.handle === "macro-low" || vCtx.handle === "macro-high" || vCtx.handle === "macro-connect") {
3106
+ const [nextMacroLowRatio, nextMacroHighRatio, activeMacroHandle] = calculateVernierMacroDrag(vCtx.handle, pointerRatio, vCtx.startPointerRatio, vCtx.startMacroLowRatio, vCtx.startMacroHighRatio)
3107
+ applyDragPresentation("macro", nextMacroLowRatio, nextMacroHighRatio)
3108
+ if (activeMacroHandle !== activeVernierHandleRef.current) {
3109
+ activeVernierHandleRef.current = activeMacroHandle
3110
+ setActiveVernierHandle(activeMacroHandle)
3111
+ setFrontVernierHandle(activeMacroHandle)
3112
+ }
3113
+
3114
+ let nextMacroLowDate: Date
3115
+ let nextMacroHighDate: Date
3116
+ if (macroIsDiscreteScale) {
3117
+ const lowIdx = railRatioToDiscreteIndex(sortedMacroAllowedDates, macroUnit, snapMode, nextMacroLowRatio)
3118
+ const highIdx = Math.max(lowIdx, railRatioToDiscreteIndex(sortedMacroAllowedDates, macroUnit, snapMode, nextMacroHighRatio))
3119
+ nextMacroLowDate = sortedMacroAllowedDates[lowIdx]
3120
+ nextMacroHighDate = sortedMacroAllowedDates[highIdx]
3121
+ } else {
3122
+ const nextLowEnc = Math.round(vernierMacroMinEnc + nextMacroLowRatio * macroSpan)
3123
+ const nextHighEnc = Math.round(vernierMacroMinEnc + nextMacroHighRatio * macroSpan)
3124
+ nextMacroLowDate = decode(macroUnit, nextLowEnc)
3125
+ nextMacroHighDate = decode(macroUnit, nextHighEnc)
3126
+ }
3127
+
3128
+ const macroKey = `${nextMacroLowDate.getTime()}_${nextMacroHighDate.getTime()}`
3129
+ if (macroKey !== lastEmittedMacroRangeRef.current) {
3130
+ lastEmittedMacroRangeRef.current = macroKey
3131
+ notifyMacroRange(nextMacroLowDate, nextMacroHighDate)
3132
+ }
2541
3133
 
2542
- // 両分岐とも同じ窓を見るため、解決は 1 度だけ
2543
- const [nextWindowStart, nextWindowEnd] = resolveMacroWindow(macroUnit, microUnit, [nextMacroLowDate, nextMacroHighDate], minDate, maxDate)
2544
- const nextMicroMinEnc = encode(microUnit, nextWindowStart)
2545
- const nextMicroMaxEnc = encode(microUnit, nextWindowEnd)
2546
- const nextMicroCandidates = microIsDiscrete ? narrowMicroCandidatesToWindow(nextMicroMinEnc, nextMicroMaxEnc) : []
2547
-
2548
- // 異単位スケール間(例: 月×日)でのパン操作時の日数ズレを防ぐため、マクロ単位の暦月・暦年差分に基づいて平行移動
2549
- let nextMicroLowDate: Date
2550
- let nextMicroHighDate: Date
2551
-
2552
- if (vCtx.handle === "macro-connect") {
2553
- const curMacroLowDate = nextWindowStart
2554
- const curMacroHighDate = nextWindowEnd
2555
-
2556
- let shiftedLowDate: Date
2557
- let shiftedHighDate: Date
2558
- if (macroUnit === "year") {
2559
- const yearDelta = nextMacroLowDate.getFullYear() - vCtx.startMacroLowDate.getFullYear()
2560
- shiftedLowDate = addUnit("year", vCtx.initialMicroLowDate, yearDelta)
2561
- shiftedHighDate = addUnit("year", vCtx.initialMicroHighDate, yearDelta)
2562
- } else if (macroUnit === "month") {
2563
- const monthDelta = (nextMacroLowDate.getFullYear() - vCtx.startMacroLowDate.getFullYear()) * 12 + (nextMacroLowDate.getMonth() - vCtx.startMacroLowDate.getMonth())
2564
- shiftedLowDate = addUnit("month", vCtx.initialMicroLowDate, monthDelta)
2565
- shiftedHighDate = addUnit("month", vCtx.initialMicroHighDate, monthDelta)
2566
- } else {
2567
- const dayDelta = Math.round((nextMacroLowDate.getTime() - vCtx.startMacroLowDate.getTime()) / (24 * 60 * 60 * 1000))
2568
- shiftedLowDate = addUnit("day", vCtx.initialMicroLowDate, dayDelta)
2569
- shiftedHighDate = addUnit("day", vCtx.initialMicroHighDate, dayDelta)
2570
- }
2571
-
2572
- const minMs = curMacroLowDate.getTime()
2573
- const maxMs = curMacroHighDate.getTime()
2574
- const durationMs = vCtx.initialMicroHighDate.getTime() - vCtx.initialMicroLowDate.getTime()
2575
- let targetLowMs = shiftedLowDate.getTime()
2576
- let targetHighMs = shiftedHighDate.getTime()
2577
-
2578
- if (targetLowMs < minMs) {
2579
- targetLowMs = minMs
2580
- targetHighMs = Math.min(maxMs, targetLowMs + durationMs)
2581
- }
2582
- if (targetHighMs > maxMs) {
2583
- targetHighMs = maxMs
2584
- targetLowMs = Math.max(minMs, targetHighMs - durationMs)
2585
- }
2586
-
2587
- nextMicroLowDate = normalizeDateByUnit(microUnit, new Date(targetLowMs))
2588
- nextMicroHighDate = normalizeDateByUnit(microUnit, new Date(targetHighMs))
3134
+ // 両分岐とも同じ窓を見るため、解決は 1 度だけ
3135
+ const [nextWindowStart, nextWindowEnd] = resolveMacroWindow(macroUnit, microUnit, [nextMacroLowDate, nextMacroHighDate], minDate, maxDate)
3136
+ const nextMicroMinEnc = encode(microUnit, nextWindowStart)
3137
+ const nextMicroMaxEnc = encode(microUnit, nextWindowEnd)
3138
+ const nextMicroCandidates = microIsDiscrete ? narrowMicroCandidatesToWindow(nextMicroMinEnc, nextMicroMaxEnc) : []
3139
+
3140
+ // 異単位スケール間 (例: 月×日) でのパン操作時の日数ズレを防ぐため、マクロ単位の暦月・暦年差分に基づいて平行移動
3141
+ let nextMicroLowDate: Date
3142
+ let nextMicroHighDate: Date
3143
+
3144
+ if (vCtx.handle === "macro-connect") {
3145
+ const curMacroLowDate = nextWindowStart
3146
+ const curMacroHighDate = nextWindowEnd
3147
+
3148
+ let shiftedLowDate: Date
3149
+ let shiftedHighDate: Date
3150
+ if (macroUnit === "year") {
3151
+ const yearDelta = nextMacroLowDate.getFullYear() - vCtx.startMacroLowDate.getFullYear()
3152
+ shiftedLowDate = addUnit("year", vCtx.initialMicroLowDate, yearDelta)
3153
+ shiftedHighDate = addUnit("year", vCtx.initialMicroHighDate, yearDelta)
3154
+ } else if (macroUnit === "month") {
3155
+ const monthDelta = (nextMacroLowDate.getFullYear() - vCtx.startMacroLowDate.getFullYear()) * 12 + (nextMacroLowDate.getMonth() - vCtx.startMacroLowDate.getMonth())
3156
+ shiftedLowDate = addUnit("month", vCtx.initialMicroLowDate, monthDelta)
3157
+ shiftedHighDate = addUnit("month", vCtx.initialMicroHighDate, monthDelta)
2589
3158
  } else {
2590
- // マクロ窓境界変更時の弾性復元 (Elastic Range Restoration & Push Clamp)
2591
- // 記憶した初期境界を毎 move 生きた窓へ当て直すことで、窓を再拡張した際に選択が元位置へ戻る (クランプ後の値を確定させると戻らない)
2592
- const minMs = nextWindowStart.getTime()
2593
- const maxMs = nextWindowEnd.getTime()
2594
- const targetLowMs = vCtx.initialMicroLowDate.getTime()
2595
- const targetHighMs = vCtx.initialMicroHighDate.getTime()
2596
-
2597
- const clampedLowMs = Math.max(minMs, Math.min(maxMs, targetLowMs))
2598
- const clampedHighMs = Math.max(clampedLowMs, Math.min(maxMs, targetHighMs))
2599
-
2600
- nextMicroLowDate = normalizeDateByUnit(microUnit, new Date(clampedLowMs))
2601
- nextMicroHighDate = normalizeDateByUnit(microUnit, new Date(clampedHighMs))
3159
+ const dayDelta = Math.round((nextMacroLowDate.getTime() - vCtx.startMacroLowDate.getTime()) / (24 * 60 * 60 * 1000))
3160
+ shiftedLowDate = addUnit("day", vCtx.initialMicroLowDate, dayDelta)
3161
+ shiftedHighDate = addUnit("day", vCtx.initialMicroHighDate, dayDelta)
2602
3162
  }
2603
3163
 
2604
- // 離散レールはつまみを最近傍候補の位置に描くため、確定値も同じ規則で解決しないと
2605
- // 描かれている位置と利用側のステートが食い違う (ミクロつまみのドラッグは既にこの規則で動く)
2606
- const emitLowEnc = resolveMicroRailEnc(nextMicroLowDate, nextMicroCandidates, nextMicroMinEnc, nextMicroMaxEnc)
2607
- const emitHighEnc = Math.max(emitLowEnc, resolveMicroRailEnc(nextMicroHighDate, nextMicroCandidates, nextMicroMinEnc, nextMicroMaxEnc))
2608
- nextMicroLowDate = decode(microUnit, emitLowEnc)
2609
- nextMicroHighDate = decode(microUnit, emitHighEnc)
2610
-
2611
- const microKey = `${nextMicroLowDate.getTime()}_${nextMicroHighDate.getTime()}`
2612
- if (microKey !== lastEmittedMicroRangeRef.current) {
2613
- lastEmittedMicroRangeRef.current = microKey
2614
- notifyMicroSelection(nextMicroLowDate, nextMicroHighDate)
3164
+ const minMs = curMacroLowDate.getTime()
3165
+ const maxMs = curMacroHighDate.getTime()
3166
+ const durationMs = vCtx.initialMicroHighDate.getTime() - vCtx.initialMicroLowDate.getTime()
3167
+ let targetLowMs = shiftedLowDate.getTime()
3168
+ let targetHighMs = shiftedHighDate.getTime()
3169
+
3170
+ if (targetLowMs < minMs) {
3171
+ targetLowMs = minMs
3172
+ targetHighMs = Math.min(maxMs, targetLowMs + durationMs)
2615
3173
  }
2616
- } else if (vCtx.handle === "micro-low" || vCtx.handle === "micro-high" || vCtx.handle === "micro-connect" || vCtx.handle === "micro-point") {
2617
- const [nextMicroLowRatio, nextMicroHighRatio, activeMicroHandle] = calculateVernierMicroDrag(vCtx.handle, pointerRatio, vCtx.startPointerRatio, vCtx.startMicroLowRatio, vCtx.startMicroHighRatio)
2618
- if (activeMicroHandle !== activeVernierHandleRef.current) {
2619
- activeVernierHandleRef.current = activeMicroHandle
2620
- setActiveVernierHandle(activeMicroHandle)
2621
- setFrontVernierHandle(activeMicroHandle)
3174
+ if (targetHighMs > maxMs) {
3175
+ targetHighMs = maxMs
3176
+ targetLowMs = Math.max(minMs, targetHighMs - durationMs)
2622
3177
  }
2623
3178
 
2624
- let nextMicroLowDate: Date
2625
- let nextMicroHighDate: Date
2626
- if (microIsDiscreteScale) {
2627
- const lowIdx = railRatioToDiscreteIndex(sortedMicroAllowedDates, microUnit, snapMode, nextMicroLowRatio)
2628
- const highIdx = Math.max(lowIdx, railRatioToDiscreteIndex(sortedMicroAllowedDates, microUnit, snapMode, nextMicroHighRatio))
2629
- nextMicroLowDate = sortedMicroAllowedDates[lowIdx]
2630
- nextMicroHighDate = sortedMicroAllowedDates[highIdx]
2631
- } else {
2632
- // microSpan は比率計算の 0 除算を避けるため 1 で床止めされている。乗数として使うと
2633
- // 幅 1 単位の窓で窓端の 1 つ先を指すため、他の発火経路と同じレール規則へ通す
2634
- const lowEnc = resolveMicroRailEnc(decode(microUnit, Math.round(vernierMicroMinEnc + nextMicroLowRatio * microSpan)), railMicroCandidates, vernierMicroMinEnc, vernierMicroMaxEnc)
2635
- const highEnc = Math.max(lowEnc, resolveMicroRailEnc(decode(microUnit, Math.round(vernierMicroMinEnc + nextMicroHighRatio * microSpan)), railMicroCandidates, vernierMicroMinEnc, vernierMicroMaxEnc))
2636
- nextMicroLowDate = decode(microUnit, lowEnc)
2637
- nextMicroHighDate = decode(microUnit, highEnc)
2638
- }
3179
+ nextMicroLowDate = normalizeDateByUnit(microUnit, new Date(targetLowMs))
3180
+ nextMicroHighDate = normalizeDateByUnit(microUnit, new Date(targetHighMs))
3181
+ } else {
3182
+ // マクロ窓境界変更時の弾性復元 (Elastic Range Restoration & Push Clamp)
3183
+ // 記憶した初期境界を毎 move 生きた窓へ当て直すことで、窓を再拡張した際に選択が元位置へ戻る (クランプ後の値を確定させると戻らない)
3184
+ const minMs = nextWindowStart.getTime()
3185
+ const maxMs = nextWindowEnd.getTime()
3186
+ const targetLowMs = vCtx.initialMicroLowDate.getTime()
3187
+ const targetHighMs = vCtx.initialMicroHighDate.getTime()
3188
+
3189
+ const clampedLowMs = Math.max(minMs, Math.min(maxMs, targetLowMs))
3190
+ const clampedHighMs = Math.max(clampedLowMs, Math.min(maxMs, targetHighMs))
3191
+
3192
+ nextMicroLowDate = normalizeDateByUnit(microUnit, new Date(clampedLowMs))
3193
+ nextMicroHighDate = normalizeDateByUnit(microUnit, new Date(clampedHighMs))
3194
+ }
2639
3195
 
2640
- const microKey = `${nextMicroLowDate.getTime()}_${nextMicroHighDate.getTime()}`
2641
- if (microKey !== lastEmittedMicroRangeRef.current) {
2642
- lastEmittedMicroRangeRef.current = microKey
2643
- notifyMicroSelection(nextMicroLowDate, nextMicroHighDate)
2644
- }
3196
+ // 離散レールはつまみを最近傍候補の位置に描くため、確定値も同じ規則で解決しないと
3197
+ // 描かれている位置と利用側のステートが食い違う (ミクロつまみのドラッグは既にこの規則で動く)
3198
+ const emitLowEnc = resolveMicroRailEnc(nextMicroLowDate, nextMicroCandidates, nextMicroMinEnc, nextMicroMaxEnc)
3199
+ const emitHighEnc = Math.max(emitLowEnc, resolveMicroRailEnc(nextMicroHighDate, nextMicroCandidates, nextMicroMinEnc, nextMicroMaxEnc))
3200
+ nextMicroLowDate = decode(microUnit, emitLowEnc)
3201
+ nextMicroHighDate = decode(microUnit, emitHighEnc)
3202
+
3203
+ const microKey = `${nextMicroLowDate.getTime()}_${nextMicroHighDate.getTime()}`
3204
+ if (microKey !== lastEmittedMicroRangeRef.current) {
3205
+ lastEmittedMicroRangeRef.current = microKey
3206
+ notifyMicroSelection(nextMicroLowDate, nextMicroHighDate)
3207
+ }
3208
+ } else if (vCtx.handle === "micro-low" || vCtx.handle === "micro-high" || vCtx.handle === "micro-connect" || vCtx.handle === "micro-point") {
3209
+ const [nextMicroLowRatio, nextMicroHighRatio, activeMicroHandle] = calculateVernierMicroDrag(vCtx.handle, pointerRatio, vCtx.startPointerRatio, vCtx.startMicroLowRatio, vCtx.startMicroHighRatio)
3210
+ applyDragPresentation("micro", nextMicroLowRatio, nextMicroHighRatio)
3211
+ if (activeMicroHandle !== activeVernierHandleRef.current) {
3212
+ activeVernierHandleRef.current = activeMicroHandle
3213
+ setActiveVernierHandle(activeMicroHandle)
3214
+ setFrontVernierHandle(activeMicroHandle)
2645
3215
  }
2646
- return
2647
- }
2648
3216
 
2649
- const ctx = dragContextRef.current
2650
- if (!ctx || (e.pointerId !== 0 && e.pointerId !== ctx.pointerId)) return
3217
+ let nextMicroLowDate: Date
3218
+ let nextMicroHighDate: Date
3219
+ if (microIsDiscreteScale) {
3220
+ const lowIdx = railRatioToDiscreteIndex(sortedMicroAllowedDates, microUnit, snapMode, nextMicroLowRatio)
3221
+ const highIdx = Math.max(lowIdx, railRatioToDiscreteIndex(sortedMicroAllowedDates, microUnit, snapMode, nextMicroHighRatio))
3222
+ nextMicroLowDate = sortedMicroAllowedDates[lowIdx]
3223
+ nextMicroHighDate = sortedMicroAllowedDates[highIdx]
3224
+ } else {
3225
+ // microSpan は比率計算の 0 除算を避けるため 1 で床止めされている。乗数として使うと
3226
+ // 幅 1 単位の窓で窓端の 1 つ先を指すため、他の発火経路と同じレール規則へ通す
3227
+ const lowEnc = resolveMicroRailEnc(decode(microUnit, Math.round(vernierMicroMinEnc + nextMicroLowRatio * microSpan)), railMicroCandidates, vernierMicroMinEnc, vernierMicroMaxEnc)
3228
+ const highEnc = Math.max(lowEnc, resolveMicroRailEnc(decode(microUnit, Math.round(vernierMicroMinEnc + nextMicroHighRatio * microSpan)), railMicroCandidates, vernierMicroMinEnc, vernierMicroMaxEnc))
3229
+ nextMicroLowDate = decode(microUnit, lowEnc)
3230
+ nextMicroHighDate = decode(microUnit, highEnc)
3231
+ }
2651
3232
 
2652
- if (!trackRef.current) return
2653
- const rect = trackRef.current.getBoundingClientRect()
2654
- const currentPos = isVertical ? e.clientY : e.clientX
2655
- const trackLength = isVertical ? rect.height : rect.width
2656
- if (!(Number.isFinite(trackLength) && trackLength > 0)) return
2657
-
2658
- if (ctx.handle === "connect") {
2659
- const rawDiffPct = isVertical ? (ctx.startPointerPos - currentPos) / trackLength : (currentPos - ctx.startPointerPos) / trackLength
2660
-
2661
- const res = calculateConnectDragValues({
2662
- posDiffPct: rawDiffPct,
2663
- startLowVal: ctx.startLowVal,
2664
- startHighVal: ctx.startHighVal,
2665
- rangeMin,
2666
- rangeMax,
2667
- isDiscrete,
2668
- sortedAllowedDates,
2669
- snapMode,
2670
- unit,
2671
- })
2672
- if (latestDraggingValuesRef.current && latestDraggingValuesRef.current[0] === res[0] && latestDraggingValuesRef.current[1] === res[1]) {
2673
- return
3233
+ const microKey = `${nextMicroLowDate.getTime()}_${nextMicroHighDate.getTime()}`
3234
+ if (microKey !== lastEmittedMicroRangeRef.current) {
3235
+ lastEmittedMicroRangeRef.current = microKey
3236
+ notifyMicroSelection(nextMicroLowDate, nextMicroHighDate)
2674
3237
  }
2675
- latestDraggingValuesRef.current = res
2676
- setDraggingValues(res)
2677
- notifyChange(res[0], res[1], false)
3238
+ }
3239
+ return
3240
+ }
3241
+
3242
+ const ctx = dragContextRef.current
3243
+ if (!ctx || e.pointerId !== ctx.pointerId) return
3244
+
3245
+ if (!trackRef.current) return
3246
+ const rect = trackRef.current.getBoundingClientRect()
3247
+ const currentPos = isVertical ? e.clientY : e.clientX
3248
+ const trackLength = isVertical ? rect.height : rect.width
3249
+ if (!(Number.isFinite(trackLength) && trackLength > 0)) return
3250
+
3251
+ if (ctx.handle === "connect") {
3252
+ const rawDiffPct = isVertical ? (ctx.startPointerPos - currentPos) / trackLength : (currentPos - ctx.startPointerPos) / trackLength
3253
+
3254
+ // 値が 1 段も進まない移動でも指には付いて来る必要があるため、値の変化を見る早期脱出より前に置く
3255
+ const [bandLowRatio, bandHighRatio] = resolveBandDragRatios(rawDiffPct, ctx.startLowRatio, ctx.startHighRatio)
3256
+ applyDragPresentation("flat", bandLowRatio, bandHighRatio)
3257
+
3258
+ const res = calculateConnectDragValues({
3259
+ posDiffPct: rawDiffPct,
3260
+ startLowVal: ctx.startLowVal,
3261
+ startHighVal: ctx.startHighVal,
3262
+ rangeMin,
3263
+ rangeMax,
3264
+ isDiscrete,
3265
+ sortedAllowedDates,
3266
+ snapMode,
3267
+ unit,
3268
+ })
3269
+ if (latestDraggingValuesRef.current && latestDraggingValuesRef.current[0] === res[0] && latestDraggingValuesRef.current[1] === res[1]) {
2678
3270
  return
2679
3271
  }
3272
+ latestDraggingValuesRef.current = res
3273
+ setDraggingValues(res)
3274
+ notifyChange(res[0], res[1], false)
3275
+ return
3276
+ }
2680
3277
 
2681
- // 長さガードで読んだ矩形を再利用する。読み直すと 1 move につき同期レイアウトが 2 回走る
2682
- const ratio = calcRatioFromPos(e.clientX, e.clientY, rect)
2683
- if (ratio === null) return
2684
- const clickedVal = pctToValue(ratio * 100)
3278
+ // 長さガードで読んだ矩形を再利用する。読み直すと 1 move につき同期レイアウトが 2 回走る
3279
+ const ratio = calcRatioFromPos(e.clientX, e.clientY, rect)
3280
+ if (ratio === null) return
2685
3281
 
2686
- const [nextLow, nextHigh] = calculateHandleDragValues(ctx.handle, clickedVal, ctx.startLowVal, ctx.startHighVal, rangeMin, rangeMax, isPointMode)
2687
- if (!latestDraggingValuesRef.current || latestDraggingValuesRef.current[0] !== nextLow || latestDraggingValuesRef.current[1] !== nextHigh) {
2688
- latestDraggingValuesRef.current = [nextLow, nextHigh]
2689
- setDraggingValues([nextLow, nextHigh])
2690
- notifyChange(nextLow, nextHigh, false)
2691
- }
3282
+ const [edgeLowRatio, edgeHighRatio] = resolveEdgeDragRatios(isPointMode ? "point" : ctx.handle, ratio, ctx.startLowRatio, ctx.startHighRatio)
3283
+ applyDragPresentation("flat", edgeLowRatio, edgeHighRatio)
2692
3284
 
2693
- if (!isPointMode && (ctx.handle === "low" || ctx.handle === "high")) {
2694
- const currentActive = getActiveDragHandle(ctx.handle, clickedVal, ctx.startLowVal, ctx.startHighVal, isPointMode)
2695
- if (activeHandleRef.current !== currentActive) {
2696
- activeHandleRef.current = currentActive
2697
- setActiveHandle(currentActive)
2698
- setFrontHandle(currentActive)
2699
- }
2700
- }
2701
- },
2702
- [
2703
- disabled,
2704
- isVernierMode,
2705
- isVertical,
2706
- macroUnit,
2707
- microUnit,
2708
- macroIsDiscreteScale,
2709
- microIsDiscreteScale,
2710
- microIsDiscrete,
2711
- minTime,
2712
- maxTime,
2713
- sortedMacroAllowedDates,
2714
- sortedMicroAllowedDates,
2715
- sortedMicroDomainDates,
2716
- vernierMacroMinEnc,
2717
- macroSpan,
2718
- vernierMicroMinEnc,
2719
- microSpan,
2720
- rangeMin,
2721
- rangeMax,
2722
- isDiscrete,
2723
- sortedAllowedDates,
2724
- snapMode,
2725
- unit,
2726
- calcRatioFromPos,
2727
- pctToValue,
2728
- notifyChange,
2729
- notifyMacroRange,
2730
- notifyMicroSelection,
2731
- isPointMode,
2732
- ],
2733
- )
3285
+ const clickedVal = pctToValue(ratio * 100)
2734
3286
 
2735
- const handleGlobalPointerUp = useCallback(
2736
- (e: PointerEvent) => {
2737
- if (isVernierMode) {
2738
- lastEmittedMacroRangeRef.current = null
2739
- lastEmittedMicroRangeRef.current = null
2740
- vernierDragContextRef.current = null
2741
- activeVernierHandleRef.current = null
2742
- setActiveVernierHandle(null)
2743
- // 予約したままドラッグを終えると、指を離した位置の値が発火されずに消える
2744
- flushPendingEmit(macroEmitRef.current)
2745
- flushPendingEmit(microEmitRef.current)
2746
- return
3287
+ const [nextLow, nextHigh] = calculateHandleDragValues(ctx.handle, clickedVal, ctx.startLowVal, ctx.startHighVal, rangeMin, rangeMax, isPointMode)
3288
+ if (!latestDraggingValuesRef.current || latestDraggingValuesRef.current[0] !== nextLow || latestDraggingValuesRef.current[1] !== nextHigh) {
3289
+ latestDraggingValuesRef.current = [nextLow, nextHigh]
3290
+ setDraggingValues([nextLow, nextHigh])
3291
+ notifyChange(nextLow, nextHigh, false)
3292
+ }
3293
+
3294
+ if (!isPointMode && (ctx.handle === "low" || ctx.handle === "high")) {
3295
+ // 強調と最前面は、いま指の下に描かれているつまみが持たなければならない。丸めた値で判定すると
3296
+ // 支点を越えてから半目盛りの間、動いていないつまみが強調され、動いているつまみがその背面へ回る
3297
+ const currentActive = resolveDraggedEdge(ctx.handle, ratio, ctx.startLowRatio, ctx.startHighRatio)
3298
+ if (activeHandleRef.current !== currentActive) {
3299
+ activeHandleRef.current = currentActive
3300
+ setActiveHandle(currentActive)
3301
+ setFrontHandle(currentActive)
2747
3302
  }
3303
+ }
3304
+ }
2748
3305
 
2749
- const ctx = dragContextRef.current
2750
- if (!ctx || (e.pointerId !== 0 && e.pointerId !== ctx.pointerId)) return
3306
+ /**
3307
+ * Ends the gesture that owns the drag, commits its final value and opens the settling window.
3308
+ * ドラッグの持ち主である操作を終え、確定値を発火して収め戻しの窓を開くハンドラ。
3309
+ *
3310
+ * A cancelled pointer ends the gesture exactly as a released one does: the position the gesture was interrupted at
3311
+ * is the committed value, and the pre-drag value is not restored. That is what a native range input does, and the
3312
+ * values along the way have already been published, so restoring would hand the host a change it never made.
3313
+ * 取り消されたポインターは、離されたポインターと全く同じように操作を終える (中断された位置がそのまま確定値であり、
3314
+ * ドラッグ開始前の値へは戻さない)。ネイティブの range 入力と同じ挙動であり、途上の値は既に発火済みのため、
3315
+ * 戻すことは利用者が行っていない変更を利用側へ渡すことになる。
3316
+ *
3317
+ * @param e - Pointer up or pointer cancel delivered to the window / window へ配送された pointerup または pointercancel
3318
+ * @returns Nothing / 戻り値なし
3319
+ */
3320
+ const handleGlobalPointerUp = (e: PointerEvent): void => {
3321
+ if (isVernierMode) {
3322
+ const vCtx = vernierDragContextRef.current
3323
+ // 別のポインターが離れただけでドラッグを畳むと、指を置いたままのユーザーの手の下で掴みが解け、
3324
+ // さらに収め戻しが走って部品が確定位置へ戻る。持ち主の判定は平レールと同じ規則で行う
3325
+ if (!vCtx || e.pointerId !== vCtx.pointerId) return
3326
+
3327
+ endDragPresentation()
3328
+ lastEmittedMacroRangeRef.current = null
3329
+ lastEmittedMicroRangeRef.current = null
3330
+ vernierDragContextRef.current = null
3331
+ activeVernierHandleRef.current = null
3332
+ setActiveVernierHandle(null)
3333
+ // 予約したままドラッグを終えると、指を離した位置の値が発火されずに消える
3334
+ flushPendingEmit(macroEmitRef.current)
3335
+ flushPendingEmit(microEmitRef.current)
3336
+ return
3337
+ }
2751
3338
 
2752
- const finalVals = latestDraggingValuesRef.current ?? draggingValues
2753
- if (finalVals) {
2754
- notifyChange(finalVals[0], finalVals[1], true)
2755
- setUncontrolledValues(finalVals)
2756
- }
3339
+ const ctx = dragContextRef.current
3340
+ if (!ctx || e.pointerId !== ctx.pointerId) return
2757
3341
 
2758
- latestDraggingValuesRef.current = null
2759
- setDraggingValues(null)
2760
- dragContextRef.current = null
2761
- activeHandleRef.current = null
2762
- setActiveHandle(null)
2763
- },
2764
- [isVernierMode, draggingValues, notifyChange, flushPendingEmit],
2765
- )
3342
+ endDragPresentation()
2766
3343
 
2767
- const handlePointerMoveRef = useRef(handleGlobalPointerMove)
2768
- handlePointerMoveRef.current = handleGlobalPointerMove
3344
+ const finalVals = latestDraggingValuesRef.current ?? draggingValues
3345
+ if (finalVals) {
3346
+ notifyChange(finalVals[0], finalVals[1], true)
3347
+ setUncontrolledValues(finalVals)
3348
+ }
3349
+
3350
+ latestDraggingValuesRef.current = null
3351
+ setDraggingValues(null)
3352
+ dragContextRef.current = null
3353
+ activeHandleRef.current = null
3354
+ setActiveHandle(null)
3355
+ }
2769
3356
 
3357
+ const handlePointerMoveRef = useRef(handleGlobalPointerMove)
2770
3358
  const handlePointerUpRef = useRef(handleGlobalPointerUp)
2771
- handlePointerUpRef.current = handleGlobalPointerUp
3359
+
3360
+ useLayoutEffect(() => {
3361
+ handlePointerMoveRef.current = handleGlobalPointerMove
3362
+ handlePointerUpRef.current = handleGlobalPointerUp
3363
+ })
2772
3364
 
2773
3365
  const isDragging = activeHandle !== null || activeVernierHandle !== null
2774
3366
 
2775
3367
  useEffect(() => {
2776
3368
  if (!isDragging) return
2777
3369
 
3370
+ // 事象を配送するのは、このスライダーが描かれている文書の window (ホイールの登録と同じ規則)。
3371
+ // モジュールの window へ張ると、別文書へポータルされたスライダーには移動も解放も 1 度も届かず、
3372
+ // 掴みが永久に生き続けてホイール・矢印キー・ステッパーを締め出したままになる (6.3)
3373
+ const view = rootRef.current?.ownerDocument.defaultView
3374
+ if (!view) return
3375
+
2778
3376
  const onMove = (e: PointerEvent) => handlePointerMoveRef.current(e)
2779
3377
  const onUp = (e: PointerEvent) => handlePointerUpRef.current(e)
2780
3378
 
2781
- window.addEventListener("pointermove", onMove)
2782
- window.addEventListener("pointerup", onUp)
2783
- window.addEventListener("pointercancel", onUp)
3379
+ view.addEventListener("pointermove", onMove)
3380
+ view.addEventListener("pointerup", onUp)
3381
+ view.addEventListener("pointercancel", onUp)
3382
+ // 掴んだ要素が操作中に外されると捕捉は解除され、以後の移動も解放もこの window へは届かない。
3383
+ // 終わりを受け取らないと掴みが永久に生き続け、値を動かせる他の経路すべてが戻り続ける
3384
+ view.addEventListener("lostpointercapture", onUp)
2784
3385
 
2785
3386
  return () => {
2786
- window.removeEventListener("pointermove", onMove)
2787
- window.removeEventListener("pointerup", onUp)
2788
- window.removeEventListener("pointercancel", onUp)
3387
+ view.removeEventListener("pointermove", onMove)
3388
+ view.removeEventListener("pointerup", onUp)
3389
+ view.removeEventListener("pointercancel", onUp)
3390
+ view.removeEventListener("lostpointercapture", onUp)
2789
3391
  }
2790
3392
  }, [isDragging])
2791
3393
 
2792
3394
  const startDrag = useCallback(
2793
- (pointerId: number, handle: "low" | "high" | "connect", startPointerPos: number) => {
3395
+ (grabbed: Element, pointerId: number, handle: "low" | "high" | "connect", startPointerPos: number) => {
3396
+ cancelSnapBack()
3397
+ captureGesturePointer(grabbed, pointerId)
2794
3398
  dragContextRef.current = {
2795
3399
  pointerId,
2796
3400
  handle,
2797
3401
  startPointerPos,
2798
3402
  startLowVal: currentLowVal,
2799
3403
  startHighVal: currentHighVal,
3404
+ // 表示の出発点は「いま描かれている位置」。値を基準にすると、時間比例スナップのように
3405
+ // 値と位置が線形でないレールで、掴んでいない側の支点が実際の描画位置からずれる
3406
+ startLowRatio: valueToPct(currentLowVal) / 100,
3407
+ startHighRatio: valueToPct(currentHighVal) / 100,
2800
3408
  }
2801
3409
  activeHandleRef.current = handle
2802
3410
  setActiveHandle(handle)
@@ -2804,13 +3412,15 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2804
3412
  setFrontHandle(handle)
2805
3413
  }
2806
3414
  },
2807
- [currentLowVal, currentHighVal],
3415
+ [currentLowVal, currentHighVal, valueToPct],
2808
3416
  )
2809
3417
 
2810
3418
  const startVernierDrag = useCallback(
2811
- (pointerId: number, handle: VernierHandle, startPointerRatio: number) => {
3419
+ (grabbed: Element, pointerId: number, handle: VernierHandle, startPointerRatio: number) => {
2812
3420
  const p = propsRef.current
2813
3421
  if (p.mode !== "vernier") return
3422
+ cancelSnapBack()
3423
+ captureGesturePointer(grabbed, pointerId)
2814
3424
  vernierDragContextRef.current = {
2815
3425
  pointerId,
2816
3426
  handle,
@@ -2834,12 +3444,12 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2834
3444
  )
2835
3445
 
2836
3446
  const handleKnobPointerDown = (handle: "low" | "high") => (e: React.PointerEvent<HTMLDivElement>) => {
2837
- if (disabled) return
3447
+ if (disabled || isGestureLive()) return
2838
3448
  e.stopPropagation()
2839
3449
  e.preventDefault()
2840
3450
  setFrontHandle(handle)
2841
3451
  const pos = isVertical ? e.clientY : e.clientX
2842
- startDrag(e.pointerId, handle, pos)
3452
+ startDrag(e.currentTarget, e.pointerId, handle, pos)
2843
3453
  }
2844
3454
 
2845
3455
  /**
@@ -2872,26 +3482,26 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2872
3482
  }
2873
3483
 
2874
3484
  const handleVernierKnobPointerDown = (handle: VernierHandle) => (e: React.PointerEvent<HTMLDivElement>) => {
2875
- if (disabled) return
3485
+ if (disabled || isGestureLive()) return
2876
3486
  e.stopPropagation()
2877
3487
  e.preventDefault()
2878
3488
  const el = trackRef.current
2879
3489
  if (!el) return
2880
3490
  const pointerRatio = calcRatioFromPos(e.clientX, e.clientY, el.getBoundingClientRect())
2881
3491
  if (pointerRatio === null) return
2882
- startVernierDrag(e.pointerId, handle, pointerRatio)
3492
+ startVernierDrag(e.currentTarget, e.pointerId, handle, pointerRatio)
2883
3493
  }
2884
3494
 
2885
3495
  const handleConnectPointerDown = (e: React.PointerEvent<HTMLDivElement>) => {
2886
- if (disabled || hideConnectBar) return
3496
+ if (disabled || hideConnectBar || isGestureLive()) return
2887
3497
  e.stopPropagation()
2888
3498
  e.preventDefault()
2889
3499
  const pos = isVertical ? e.clientY : e.clientX
2890
- startDrag(e.pointerId, "connect", pos)
3500
+ startDrag(e.currentTarget, e.pointerId, "connect", pos)
2891
3501
  }
2892
3502
 
2893
3503
  const handleTrackPointerDown = (e: React.PointerEvent<HTMLDivElement>) => {
2894
- if (disabled) return
3504
+ if (disabled || isGestureLive()) return
2895
3505
 
2896
3506
  if (isVernierMode) {
2897
3507
  const el = trackRef.current
@@ -2902,7 +3512,11 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2902
3512
  const pointerCrossAxisOffset = isVertical ? e.clientX - (rect.left + rect.width / 2) : e.clientY - (rect.top + rect.height / 2)
2903
3513
  // 帯を隠したまま帯ドラッグだけ残ると、描かれていない当たり判定が生き続ける
2904
3514
  const targetHandle = resolveVernierTargetHandle(pointerRatio, pointerCrossAxisOffset, macroLowRatio, macroHighRatio, microLowRatio, microHighRatio, vernierOrientation, undefined, !hideConnectBar, isMicroPointShape ? "point" : "range")
2905
- startVernierDrag(e.pointerId, targetHandle, pointerRatio)
3515
+ startVernierDrag(e.currentTarget, e.pointerId, targetHandle, pointerRatio)
3516
+ // 押しただけで指を動かさない操作にも、単一ポインターの経路が要る (WCAG 2.2 SC 2.5.7。キーボードでは満たせない)。
3517
+ // 押下をその操作の最初の移動として同じ規則へ通すことで、平レールと同じ「押した所へ寄る」動きになり、
3518
+ // 幅を保つ帯の押下は移動量 0 の平行移動として何も動かさない
3519
+ handlePointerMoveRef.current(e.nativeEvent)
2906
3520
  return
2907
3521
  }
2908
3522
 
@@ -2929,11 +3543,19 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2929
3543
  notifyChange(nextLow, nextHigh, true)
2930
3544
 
2931
3545
  const pos = isVertical ? e.clientY : e.clientX
2932
- startDrag(e.pointerId, chosenHandle, pos)
3546
+ startDrag(e.currentTarget, e.pointerId, chosenHandle, pos)
2933
3547
  }
2934
3548
 
2935
- const handleTrackPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
2936
- if (disabled || activeHandle !== null) return
3549
+ /**
3550
+ * Tracks the value under the pointer for the hover guide while no knob is being dragged; vernier mode draws no hover guide, so it tracks nothing.
3551
+ * つまみのドラッグ中でない間、ホバーガイド用にポインターの下の値を追跡するハンドラ (ノギスはホバーガイドを描かないため追跡しない)。
3552
+ *
3553
+ * @param e - Pointer move over the track / トラック上のポインター移動
3554
+ * @returns Nothing / 戻り値なし
3555
+ */
3556
+ const handleTrackPointerMove = (e: React.PointerEvent<HTMLDivElement>): void => {
3557
+ // ノギスはホバーガイドを描かない。状態だけ更新すると移動のたびに矩形の読み取りと再描画が走る
3558
+ if (disabled || isVernierMode || activeHandle !== null) return
2937
3559
  const pct = getTrackPctFromPointer(e.clientX, e.clientY)
2938
3560
  if (pct === null) return
2939
3561
  const val = pctToValue(pct)
@@ -2950,12 +3572,13 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2950
3572
  // H. キーボードとステッパー操作
2951
3573
  // ------------------------------------------------------------------
2952
3574
  const handleKeyDown = (handle: "low" | "high") => (e: React.KeyboardEvent<HTMLDivElement>) => {
2953
- if (disabled) return
3575
+ if (disabled || isGestureLive()) return
2954
3576
  setFrontHandle(handle)
2955
3577
 
2956
3578
  const res = calculateKeyboardActionValues(e.key, handle, currentLowVal, currentHighVal, rangeMin, rangeMax, isPointMode, 1)
2957
3579
  if (res) {
2958
3580
  e.preventDefault()
3581
+ cancelSnapBack()
2959
3582
  if (!isControlled) {
2960
3583
  setUncontrolledValues(res)
2961
3584
  }
@@ -2989,12 +3612,10 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2989
3612
  const nextMicroMaxEnc = encode(microUnit, nextWindowEnd)
2990
3613
  const nextCandidates = microIsDiscrete ? narrowMicroCandidatesToWindow(nextMicroMinEnc, nextMicroMaxEnc) : []
2991
3614
  // 出発点は利用側が保持している選択そのもの。レールへ載せた表示値から出発すると、新しい窓が選択を
2992
- // 完全に含む場合でも古い窓の端へ引き戻し、比較の両辺が同じ端になって訂正自体が発火しなくなる
2993
- const currentLowEnc = encode(microUnit, vernierMicroSelection[0])
2994
- const currentHighEnc = encode(microUnit, vernierMicroSelection[1])
3615
+ // 完全に含む場合でも古い窓の端へ引き戻し、比較の両辺が同じ端になって訂正自体が発火しなくなる。
3616
+ // 動いていない選択を鳴らさない判定は notifyMicroSelection が全経路分まとめて持つ
2995
3617
  const nextLowEnc = resolveMicroRailEnc(vernierMicroSelection[0], nextCandidates, nextMicroMinEnc, nextMicroMaxEnc)
2996
3618
  const nextHighEnc = Math.max(nextLowEnc, resolveMicroRailEnc(vernierMicroSelection[1], nextCandidates, nextMicroMinEnc, nextMicroMaxEnc))
2997
- if (nextLowEnc === currentLowEnc && nextHighEnc === currentHighEnc) return
2998
3619
  notifyMicroSelection(decode(microUnit, nextLowEnc), decode(microUnit, nextHighEnc), true)
2999
3620
  }
3000
3621
 
@@ -3010,7 +3631,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3010
3631
  * @returns Keyboard event handler for the given handle / 指定ハンドル用のキーボードイベントハンドラ
3011
3632
  */
3012
3633
  const handleVernierKeyDown = (handle: "macro-low" | "macro-high" | "micro-low" | "micro-high" | "micro-point") => (e: React.KeyboardEvent<HTMLDivElement>) => {
3013
- if (disabled || !isVernierMode || props.mode !== "vernier") return
3634
+ if (disabled || !isVernierMode || props.mode !== "vernier" || isGestureLive()) return
3014
3635
  setFrontVernierHandle(handle)
3015
3636
  let delta = 0
3016
3637
  let isHome = false
@@ -3040,6 +3661,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3040
3661
  return
3041
3662
  }
3042
3663
  e.preventDefault()
3664
+ cancelSnapBack()
3043
3665
 
3044
3666
  if (handle === "macro-low") {
3045
3667
  const currentLow = decode(macroUnit, vernierMacroLowEnc)
@@ -3143,6 +3765,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3143
3765
  */
3144
3766
  const shiftMacroWindow = (delta: number): void => {
3145
3767
  if (props.mode !== "vernier") return
3768
+ cancelSnapBack()
3146
3769
 
3147
3770
  if (macroIsDiscreteScale) {
3148
3771
  const maxIdx = sortedMacroAllowedDates.length - 1
@@ -3186,7 +3809,8 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3186
3809
  const shift = useCallback(
3187
3810
  (delta: number) => {
3188
3811
  const p = propsRef.current
3189
- if (p.disabled) return
3812
+ if (p.disabled || isGestureLive()) return
3813
+ cancelSnapBack()
3190
3814
 
3191
3815
  if (p.mode === "point") {
3192
3816
  const nextVal = Math.max(rangeMin, Math.min(rangeMax, currentLowVal + delta))
@@ -3268,17 +3892,69 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3268
3892
  sortedMicroAllowedDates,
3269
3893
  vernierMicroLowDate,
3270
3894
  vernierMicroHighDate,
3895
+ cancelSnapBack,
3271
3896
  ],
3272
3897
  )
3273
3898
 
3274
3899
  /**
3275
- * Shifts the scale the pointer is over by one unit when the wheel is turned with Shift held.
3276
- * Shift 押下中のホイール操作で、ポインターが載っているスケールを 1 単位だけ平行移動するハンドラ。
3900
+ * Tells whether a wheel gesture's hit target is a part this slider draws.
3901
+ * ホイール操作のヒットテストの相手が、このスライダーが描く部品かを返す関数。
3277
3902
  *
3278
- * Shift is required so that an ordinary wheel over the slider keeps scrolling the page, and the page
3279
- * scroll is only taken for a gesture that is actually aimed at the rail.
3280
- * Shift を要求するのは、スライダー上の素のホイールがページスクロールであり続けるため。
3281
- * ページのスクロールを奪うのはレールへ向けられた操作のときだけ。
3903
+ * A disabled slider draws parts but owns no point, exactly as it owns no point of its range area: the gesture has
3904
+ * to reach whatever lies under it, and a slider that cannot move must not swallow it.
3905
+ * 無効なスライダーは部品を描くがどの点も持たない (範囲領域のどの点も持たないのと同じ)。操作は下にあるものへ
3906
+ * 届かなければならず、動けないスライダーがそれを飲み込んではならない。
3907
+ *
3908
+ * The target is narrowed structurally (`containsEventTarget`) rather than with `instanceof`, so the rule keeps
3909
+ * answering for the slider this per-document registry exists for: one portalled into another document.
3910
+ * 相手の絞り込みは `instanceof` ではなく構造で行う (`containsEventTarget`)。文書ごとの登録簿が存在する理由である
3911
+ * 「別文書へポータルされたスライダー」でも、この規則が答え続けるため。
3912
+ *
3913
+ * @param target - Hit target the wheel event carries / ホイールイベントが運ぶヒットテストの相手
3914
+ * @returns Whether the target is inside this slider and this slider can move / 相手がこのスライダーの中にあり、かつこのスライダーが動けるか
3915
+ */
3916
+ const ownsWheelHit = (target: EventTarget | null): boolean => !disabled && containsEventTarget(rootRef.current, target)
3917
+
3918
+ /**
3919
+ * Resolves how far a pointer sits from the rail centre line while it is over this slider's range area.
3920
+ * ポインターがこのスライダーの範囲領域の上にある間、トラック中心線からどれだけ離れているかを解決する関数。
3921
+ *
3922
+ * Across the rail the area is the rectangle the stylesheet lays out (`.period-slider-range-area`), measured rather
3923
+ * than recomputed, so the region that answers the wheel is the same box the stylesheet composes from the lane and
3924
+ * the anchor line; along the rail `ownsPaintedPoint` inflates that measured rectangle by the label reach instead,
3925
+ * because an element grown past the root would add that overhang as scrollable overflow to a tight host for a
3926
+ * region that draws nothing. The element draws nothing and answers no hit test, so the measurement costs the area
3927
+ * no pointer ownership. A disabled slider, an unmeasurable area and a slider that is not painted own no point.
3928
+ * 交差軸では、領域はスタイルシートが組み立てた矩形 (`.period-slider-range-area`) を計算し直さずに実測したもの
3929
+ * (ホイールに答える領域は、レーンと基準線からスタイルシートが組む箱そのもの)。レール方向は代わりに実測した矩形を
3930
+ * `ownsPaintedPoint` がラベル到達距離だけ膨らませる。ルートの外へ大きくした要素は、何も描かない領域のために
3931
+ * 余裕のないホストへそのはみ出し量のスクロールを足すため。この要素は何も描かずヒットテストにも答えないため、
3932
+ * 実測しても領域が押下の持ち主になることはない。無効なスライダー・寸法を持たない領域・描かれていないスライダーは
3933
+ * どの点も持たない。
3934
+ *
3935
+ * @param clientX - Pointer x in client coordinates / ポインターのクライアント座標 x
3936
+ * @param clientY - Pointer y in client coordinates / ポインターのクライアント座標 y
3937
+ * @returns Distance from the rail centre line, or null when the pointer is outside the area / トラック中心線からの距離 (領域の外なら null)
3938
+ */
3939
+ const distanceToRailPx = (clientX: number, clientY: number): number | null => {
3940
+ const areaEl = rangeAreaRef.current
3941
+ const trackEl = trackRef.current
3942
+ const rootEl = rootRef.current
3943
+ if (disabled || areaEl === null || trackEl === null || rootEl === null) return null
3944
+ if (!ownsPaintedPoint(areaEl, rootEl, labelReachMainRef.current, isVertical, clientX, clientY)) return null
3945
+ const rail = trackEl.getBoundingClientRect()
3946
+ return Math.abs(isVertical ? clientX - (rail.left + rail.width / 2) : clientY - (rail.top + rail.height / 2))
3947
+ }
3948
+
3949
+ /**
3950
+ * Shifts the scale the pointer is over by one unit when the wheel is turned with Shift held anywhere over the range area.
3951
+ * 範囲領域のどこかで Shift 押下中のホイール操作が行われたとき、ポインターが載っているスケールを 1 単位だけ平行移動するハンドラ。
3952
+ *
3953
+ * The range area is the rectangle the stylesheet lays out (the lane around the rail plus every drawn label) together
3954
+ * with every part this slider draws; the pointer does not have to be over a knob or its label. The shared listener
3955
+ * has already decided that this slider owns the point, and that the gesture carries Shift and is still cancelable.
3956
+ * 範囲領域はスタイルシートが組み立てた矩形 (レール周りのレーンと描かれた全ラベル) と、このスライダーが描く全ての部品の和。
3957
+ * ポインターがつまみやラベルの真上にある必要はない。Shift の有無・取り消し可能かと、この点の持ち主が誰かは共有リスナーが決めている。
3282
3958
  *
3283
3959
  * In vernier mode the track carries two rails, so the wheel moves the scale under the pointer: the
3284
3960
  * macro window on the macro rail, the micro selection on the micro rail. Moving the micro selection
@@ -3287,16 +3963,25 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3287
3963
  * (マクロレールならマクロ窓、ミクロレールならミクロ選択)。マクロレール上でミクロ選択が動くのは、
3288
3964
  * ポインターが何の上に居るかについての嘘になる。
3289
3965
  *
3290
- * @param event - Wheel event delivered by the non-passive track listener / 非パッシブなトラックリスナーが受け取るホイールイベント
3966
+ * Over a stepper the wheel does what the stepper's click does (the micro selection), because the button stands
3967
+ * across the centre line and reading the side would move two scales from one highlighted control.
3968
+ * ステッパーの上ではクリックと同じもの (ミクロ選択) を動かす。ボタンは中心線を跨いで立つため、側で読むと
3969
+ * 強調表示された 1 つのボタンの上下で別のスケールが動く。
3970
+ *
3971
+ * @param event - Wheel event the shared listener handed to this slider / 共有リスナーがこのスライダーへ渡したホイールイベント
3291
3972
  * @returns Nothing / 戻り値なし
3292
3973
  */
3293
- const handleTrackWheel = (event: WheelEvent): void => {
3294
- if (disabled || !event.shiftKey) return
3974
+ const stepFromRangeAreaWheel = (event: WheelEvent): void => {
3975
+ // 掴んでいる間はポインターが値の持ち主。ここで取り消すと、ドラッグが押下時の控えから計算し直した対が
3976
+ // ホイールの 1 段を無言で取り消すうえ、ページのスクロールまで奪ったまま何も動かないことになる
3977
+ if (disabled || isGestureLive()) return
3295
3978
  const step = resolveWheelStep(event.deltaX, event.deltaY, isVertical)
3296
3979
  if (step === 0) return
3297
3980
  event.preventDefault()
3298
3981
 
3299
- if (!isVernierMode) {
3982
+ const target = event.target
3983
+ const isOverStepper = containsEventTarget(decreaseStepperRef.current, target) || containsEventTarget(increaseStepperRef.current, target)
3984
+ if (!isVernierMode || isOverStepper) {
3300
3985
  shift(step)
3301
3986
  return
3302
3987
  }
@@ -3312,20 +3997,24 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3312
3997
  shift(step)
3313
3998
  }
3314
3999
 
3315
- // ハンドラは毎レンダー作り直されるが、リスナーは 1 度だけ張る。ref 経由で最新を呼ぶことで、
4000
+ // ハンドラは毎レンダー作り直されるが、登録は 1 度だけ行う。ref 経由で最新を呼ぶことで、
3316
4001
  // 登録し直しによる取りこぼしも、閉じ込めた古い値も起こらない (ポインター移動と同じ手)
3317
- const handleTrackWheelRef = useRef(handleTrackWheel)
3318
- handleTrackWheelRef.current = handleTrackWheel
4002
+ const rangeAreaWheelRef = useRef({ ownsWheelHit, distanceToRailPx, stepFromRangeAreaWheel })
3319
4003
 
3320
- useEffect(() => {
3321
- const el = trackRef.current
3322
- if (!el) return
4004
+ useLayoutEffect(() => {
4005
+ rangeAreaWheelRef.current = { ownsWheelHit, distanceToRailPx, stepFromRangeAreaWheel }
4006
+ })
3323
4007
 
3324
- // React は wheel をルートへパッシブ登録するため、onWheel からは preventDefault できない。
3325
- // ページのスクロールを止めるには、非パッシブなリスナーを自前で張るしかない
3326
- const onWheel = (event: WheelEvent) => handleTrackWheelRef.current(event)
3327
- el.addEventListener("wheel", onWheel, { passive: false })
3328
- return () => el.removeEventListener("wheel", onWheel)
4008
+ useEffect(() => {
4009
+ // 事象を配送するのは、このスライダーが描かれている文書の window。別文書へポータルされたスライダーが
4010
+ // モジュールの window へ登録すると、操作は 1 度も届かない
4011
+ const view = rootRef.current?.ownerDocument.defaultView
4012
+ if (!view) return
4013
+ return registerRangeAreaWheelParticipant(view, {
4014
+ ownsHit: (target) => rangeAreaWheelRef.current.ownsWheelHit(target),
4015
+ distanceToRailPx: (clientX, clientY) => rangeAreaWheelRef.current.distanceToRailPx(clientX, clientY),
4016
+ step: (event) => rangeAreaWheelRef.current.stepFromRangeAreaWheel(event),
4017
+ })
3329
4018
  }, [])
3330
4019
 
3331
4020
  // ------------------------------------------------------------------
@@ -3337,42 +4026,14 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3337
4026
  const lowDate = valueToDate(currentLowVal)
3338
4027
  const highDate = valueToDate(currentHighVal)
3339
4028
 
3340
- // Point モードはラベルが 1 枚で、その 1 枚の実寸がそのまま直立基準の高さになる。
3341
- // 対になる 2 枚の規則 (片方でも未実測なら寸法なし) は buildPairSlantConfig が一手に持つ
3342
- const labelSlantConfig: LabelSlantConfig | undefined = useMemo(() => {
3343
- if (isPointMode) return lowLabelBox === null ? undefined : { estimatedWidthPx: lowLabelBox.widthPx, estimatedHeightPx: lowLabelBox.heightPx }
3344
- return buildPairSlantConfig(lowLabelBox, highLabelBox)
3345
- }, [isPointMode, lowLabelBox, highLabelBox])
3346
-
3347
- // 値が一致するとき 2 枚のラベルは文字列まで同一になる (valueToDate が純粋なので構造的に保証される)。
3348
- // ピクセル距離では別日と区別できないため判定は必ず値で行う。
3349
- // point モードは上限値を下限値へ寄せるため素の一致判定が恒真になり、!isPointMode で外さないと成立しない
3350
- const isLabelMerged = !isPointMode && currentLowVal === currentHighVal
3351
-
3352
- const slantResult: LabelSlantResult = useMemo(() => {
3353
- // 縦向きは X 軸オフセットしか返さない幾何を適用できない。Point モードは避ける相手そのものが居ない
3354
- if (isPointMode || !autoSlantLabels || isVertical) return buildHorizontalSlantResult(labelPosition, labelSlantConfig)
3355
-
3356
- const solved = calculateLabelSlant(lowPct, highPct, trackLength, labelPosition, labelSlantConfig)
3357
- if (!isLabelMerged) return solved
3358
-
3359
- // 併合時に残る 1 枚は前面側であり、front は焦点・押下・交差のたび入れ替わる。押し退けを残すと
3360
- // 唯一のラベルが ±shiftX の間を飛び、離す相手も居ない。角度と垂直オフセットは 90deg のラベルを
3361
- // つまみから逃がすために必要なので保持し、接近から一致まで角度も位置も連続させる
3362
- return withoutHorizontalPush(solved)
3363
- }, [isPointMode, isLabelMerged, autoSlantLabels, isVertical, lowPct, highPct, trackLength, labelPosition, labelSlantConfig])
4029
+ // ラベルの配置は位置に対する純粋な幾何であり、掴んでいる間は毎コミット入力が変わるためメモ化しても必ず外れる。
4030
+ // React は style を値で比較するため、同値の新しいオブジェクトは DOM への書き込みを 1 つも生まない
4031
+ const flatPlacement = solveFlatPairPlacement(lowPct, highPct, flatPlacementInput)
4032
+ const slantResult: LabelSlantResult = flatPlacement.slant
3364
4033
 
3365
4034
  const isLowFront = activeHandle === "low" || (activeHandle !== "high" && frontHandle === "low")
3366
4035
  const isHighFront = !isPointMode && (activeHandle === "high" || (activeHandle !== "low" && frontHandle === "high"))
3367
4036
 
3368
- // ノギスの 2 対も Range と同じ根拠で畳む。マクロ・ミクロとも符号化値から復元した日付を整形するため、
3369
- // 符号化値が一致すればラベルは文字列まで一致する。しかもノギスには押し退けが無く 2 枚が同一矩形へ
3370
- // 完全に重なるため、畳まないと同じ値が二重に読み上げられるだけで視覚的な情報も増えない
3371
- const isVernierMacroLabelMerged = vernierMacroLowEnc === vernierMacroHighEnc
3372
- // 時点形態のミクロラベルは 1 枚しか無い。畳み込み判定は恒真になるため、Point モードの !isPointMode と
3373
- // 同じ理由で形態ごと外す (外さないと唯一のラベルが重複として隠れる)
3374
- const isVernierMicroLabelMerged = !isMicroPointShape && vernierMicroLowEnc === vernierMicroHighEnc
3375
-
3376
4037
  // 生存者は対の内側だけで決める。frontVernierHandle は 4 つのつまみで 1 本しか無く、相手の対や
3377
4038
  // 連結バーを操作している間は対の両方が非 front になるため、「front でない方を隠す」では両方消える。
3378
4039
  // 下限が front のときだけ下限を残し、それ以外は上限を残す (Range の初期前面と同じ上限優先) 全域規則
@@ -3381,81 +4042,38 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3381
4042
  const isVernierMicroLowLabelDuplicate = isVernierMicroLabelMerged && frontVernierHandle !== "micro-low"
3382
4043
  const isVernierMicroHighLabelDuplicate = isVernierMicroLabelMerged && frontVernierHandle === "micro-low"
3383
4044
 
3384
- // ラベルが載る面はつまみと同じ側であり、JSX の data-vernier-pos が示す面と必ず一致する
3385
- const macroRailLabelPosition: PeriodSliderLabelPosition = isMacroFirstRail ? "top" : "bottom"
3386
- const microRailLabelPosition: PeriodSliderLabelPosition = isMacroFirstRail ? "bottom" : "top"
3387
-
3388
- // マクロとミクロは同じトラックの上で比率も単位空間もラベル幅も異なる。1 つの計算を共有すると
3389
- // 一方の押し退け量が他方の実寸で決まってしまうため、対ごとに独立して解く
3390
- const macroLabelSlantConfig = useMemo(() => buildPairSlantConfig(macroLowLabelBox, macroHighLabelBox), [macroLowLabelBox, macroHighLabelBox])
3391
- const microLabelSlantConfig = useMemo(() => buildPairSlantConfig(microLowLabelBox, microHighLabelBox), [microLowLabelBox, microHighLabelBox])
3392
-
3393
- // 傾斜可否はレール単位で決まる。縦向きノギスは縦向き Range と同じ理由で外す (solveVernierPairPlacement 参照)
3394
- const isVernierSlantable = autoSlantLabels && !isVertical
3395
-
3396
- const macroPairPlacement = useMemo(
3397
- () => solveVernierPairPlacement(macroLowRatio, macroHighRatio, trackLength, macroRailLabelPosition, macroLabelSlantConfig, isVernierMacroLabelMerged, isVernierSlantable),
3398
- [macroLowRatio, macroHighRatio, trackLength, macroRailLabelPosition, macroLabelSlantConfig, isVernierMacroLabelMerged, isVernierSlantable],
3399
- )
3400
-
3401
- // 傾斜は接近した対を離すための機構であり、時点形態には離す相手が居ない。Point モードが
3402
- // buildHorizontalSlantResult へ落ちるのと同じく、直立のまま置く
3403
- const isMicroPairSlantable = isVernierSlantable && !isMicroPointShape
3404
-
3405
- const microPairPlacement = useMemo(
3406
- () => solveVernierPairPlacement(microLowRatio, microHighRatio, trackLength, microRailLabelPosition, microLabelSlantConfig, isVernierMicroLabelMerged, isMicroPairSlantable),
3407
- [microLowRatio, microHighRatio, trackLength, microRailLabelPosition, microLabelSlantConfig, isVernierMicroLabelMerged, isMicroPairSlantable],
3408
- )
3409
-
3410
- const lowTooltipStyle: CSSProperties = useMemo(() => {
3411
- if (isVertical) {
3412
- return {
3413
- "--ps-tooltip-origin": "100% 50%",
3414
- "--ps-tooltip-tx": "0px",
3415
- "--ps-tooltip-ty": "-50%",
3416
- "--ps-tooltip-rot": "0deg",
3417
- } as CSSProperties
3418
- }
3419
-
3420
- return {
3421
- "--ps-tooltip-origin": "50% 50%",
3422
- "--ps-tooltip-tx": `calc(-50% + ${slantResult.lowOffsetX}px)`,
3423
- "--ps-tooltip-ty": `calc(-50% + ${slantResult.lowOffsetY}px)`,
3424
- "--ps-tooltip-rot": `${slantResult.lowAngleDeg}deg`,
3425
- } as CSSProperties
3426
- }, [isVertical, slantResult.lowOffsetX, slantResult.lowOffsetY, slantResult.lowAngleDeg])
3427
-
3428
- const highTooltipStyle: CSSProperties = useMemo(() => {
3429
- if (isVertical) {
3430
- return {
3431
- "--ps-tooltip-origin": "100% 50%",
3432
- "--ps-tooltip-tx": "0px",
3433
- "--ps-tooltip-ty": "-50%",
3434
- "--ps-tooltip-rot": "0deg",
3435
- } as CSSProperties
3436
- }
3437
-
3438
- return {
3439
- "--ps-tooltip-origin": "50% 50%",
3440
- "--ps-tooltip-tx": `calc(-50% + ${slantResult.highOffsetX}px)`,
3441
- "--ps-tooltip-ty": `calc(-50% + ${slantResult.highOffsetY}px)`,
3442
- "--ps-tooltip-rot": `${slantResult.highAngleDeg}deg`,
3443
- } as CSSProperties
3444
- }, [isVertical, slantResult.highOffsetX, slantResult.highOffsetY, slantResult.highAngleDeg])
4045
+ const macroPairPlacement = solveVernierPairPlacement("macro", macroLowRatio, macroHighRatio, macroPairInput)
4046
+ const microPairPlacement = solveVernierPairPlacement("micro", microLowRatio, microHighRatio, microPairInput)
3445
4047
 
3446
4048
  const minPct = Math.min(lowPct, highPct)
3447
4049
  const maxPct = Math.max(lowPct, highPct)
4050
+
4051
+ // 位置は「いま指が居る場所」を読み、まだ誰も掴んでいない間は確定位置が既定値として描かれる。
4052
+ // 幅は 2 つの端の差として書くため、帯が収め戻される間も両端が別々の位置へ落ちることがない
4053
+ const [flatLowVariable, flatHighVariable] = DRAG_PRESENTATION_VARIABLES.flat
4054
+ const [macroLowVariable, macroHighVariable] = DRAG_PRESENTATION_VARIABLES.macro
4055
+ const [microLowVariable, microHighVariable] = DRAG_PRESENTATION_VARIABLES.micro
4056
+ const flatLowPosition = dragPresentationValue(flatLowVariable, lowPct)
4057
+ const flatHighPosition = dragPresentationValue(flatHighVariable, highPct)
4058
+ const flatBandStart = dragPresentationValue(flatLowVariable, minPct)
4059
+ const flatBandEnd = dragPresentationValue(flatHighVariable, maxPct)
4060
+ const flatBandSpan = `calc(${flatBandEnd} - ${flatBandStart})`
4061
+ const macroLowPosition = dragPresentationValue(macroLowVariable, macroLowRatio * 100)
4062
+ const macroHighPosition = dragPresentationValue(macroHighVariable, macroHighRatio * 100)
4063
+ const microLowPosition = dragPresentationValue(microLowVariable, microLowRatio * 100)
4064
+ const microHighPosition = dragPresentationValue(microHighVariable, microHighRatio * 100)
4065
+
3448
4066
  const connectStyle: CSSProperties = isVertical
3449
4067
  ? {
3450
- bottom: `${minPct}%`,
3451
- height: `${maxPct - minPct}%`,
4068
+ bottom: flatBandStart,
4069
+ height: flatBandSpan,
3452
4070
  top: "auto",
3453
4071
  left: "0",
3454
4072
  right: "0",
3455
4073
  }
3456
4074
  : {
3457
- left: `${minPct}%`,
3458
- width: `${maxPct - minPct}%`,
4075
+ left: flatBandStart,
4076
+ width: flatBandSpan,
3459
4077
  top: "0",
3460
4078
  bottom: "0",
3461
4079
  }
@@ -3464,9 +4082,9 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3464
4082
  const macroSpanRatio = Math.max(0.01, macroHighRatio - macroLowRatio)
3465
4083
  const targetMicroOpacity = Math.max(0.06, Math.min(0.25, 0.28 * Math.sqrt(macroSpanRatio)))
3466
4084
 
3467
- const lowHandleStyle: CSSProperties = isVertical ? { bottom: `${lowPct}%`, left: "50%", transform: "translate(-50%, 50%)", zIndex: isLowFront ? 40 : 30 } : { left: `${lowPct}%`, top: "50%", transform: "translate(-50%, -50%)", zIndex: isLowFront ? 40 : 30 }
4085
+ const lowHandleStyle: CSSProperties = isVertical ? { bottom: flatLowPosition, left: "50%", transform: "translate(-50%, 50%)", zIndex: isLowFront ? 40 : 30 } : { left: flatLowPosition, top: "50%", transform: "translate(-50%, -50%)", zIndex: isLowFront ? 40 : 30 }
3468
4086
 
3469
- const highHandleStyle: CSSProperties = isVertical ? { bottom: `${highPct}%`, left: "50%", transform: "translate(-50%, 50%)", zIndex: isHighFront ? 40 : 30 } : { left: `${highPct}%`, top: "50%", transform: "translate(-50%, -50%)", zIndex: isHighFront ? 40 : 30 }
4087
+ const highHandleStyle: CSSProperties = isVertical ? { bottom: flatHighPosition, left: "50%", transform: "translate(-50%, 50%)", zIndex: isHighFront ? 40 : 30 } : { left: flatHighPosition, top: "50%", transform: "translate(-50%, -50%)", zIndex: isHighFront ? 40 : 30 }
3470
4088
 
3471
4089
  const hoverGuideStyle: CSSProperties = isVertical ? { bottom: `${hoverPct}%`, left: "50%", transform: "translate(-50%, 50%)" } : { left: `${hoverPct}%`, top: "50%", transform: "translate(-50%, -50%)" }
3472
4090
 
@@ -3482,8 +4100,42 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3482
4100
  const microStepFloorEnc = microIsDiscreteScale ? encode(microUnit, sortedMicroAllowedDates[0]) : vernierMicroMinEnc
3483
4101
  const microStepCeilEnc = microIsDiscreteScale ? encode(microUnit, sortedMicroAllowedDates[sortedMicroAllowedDates.length - 1]) : vernierMicroMaxEnc
3484
4102
 
3485
- const stepperDecreaseDisabled = disabled || (isVernierMode ? vernierMicroLowEnc <= microStepFloorEnc : isPointMode ? currentLowVal <= rangeMin : currentLowVal <= rangeMin && currentHighVal <= rangeMin)
3486
- const stepperIncreaseDisabled = disabled || (isVernierMode ? vernierMicroHighEnc >= microStepCeilEnc : isPointMode ? currentHighVal >= rangeMax : currentLowVal >= rangeMax && currentHighVal >= rangeMax)
4103
+ // 押しても動かないステッパーを押せるように見せると、ホバーの強調が起こらない動作を約束する。幅を保つ平行移動は
4104
+ // 進む向きの縁が境界に着いた時点で動けない (Point は幅 0 の同じ規則)
4105
+ const canStepDecrease = isVernierMode ? vernierMicroLowEnc > microStepFloorEnc : currentLowVal > rangeMin
4106
+ const canStepIncrease = isVernierMode ? vernierMicroHighEnc < microStepCeilEnc : currentHighVal < rangeMax
4107
+
4108
+ // 範囲領域の厚みは、いま描かれているラベルの外縁で決まる。未実測のラベルは寸法を捏造せず層に数えない
4109
+ const labelReach = resolveLabelReach(
4110
+ isVernierMode
4111
+ ? [
4112
+ {
4113
+ side: isMacroFirstRail ? "before" : "after",
4114
+ box: resolvePairBox(macroLowLabelBox, macroHighLabelBox),
4115
+ ...(isVertical ? ({ reach: "inline-size" } as const) : ({ reach: "rotated", angleDeg: macroPairPlacement.slant.lowAngleDeg, centreOffsetPx: null, alongPushPx: macroPairPlacement.slant.lowOffsetX } as const)),
4116
+ },
4117
+ {
4118
+ side: isMacroFirstRail ? "after" : "before",
4119
+ box: isMicroPointShape ? microLowLabelBox : resolvePairBox(microLowLabelBox, microHighLabelBox),
4120
+ ...(isVertical ? ({ reach: "inline-size" } as const) : ({ reach: "rotated", angleDeg: microPairPlacement.slant.lowAngleDeg, centreOffsetPx: null, alongPushPx: microPairPlacement.slant.lowOffsetX } as const)),
4121
+ },
4122
+ ]
4123
+ : [
4124
+ {
4125
+ // 縦向きのラベルは labelPosition に関わらずスタイルシートが左へ置く
4126
+ side: isVertical || labelPosition === "top" ? "before" : "after",
4127
+ box: isPointMode ? lowLabelBox : resolvePairBox(lowLabelBox, highLabelBox),
4128
+ ...(isVertical ? ({ reach: "inline-size" } as const) : ({ reach: "rotated", angleDeg: slantResult.lowAngleDeg, centreOffsetPx: slantResult.lowOffsetY, alongPushPx: slantResult.lowOffsetX } as const)),
4129
+ },
4130
+ ],
4131
+ )
4132
+ const rootStyle = labelReach === undefined ? props.style : { ...props.style, ...labelReach.style }
4133
+
4134
+ // レール方向の到達距離はホイールの持ち主判定だけが読む。事象の時点で読み直すため、持ち替えはコミット後に行う。
4135
+ // ラベルが 1 枚も実測されていない間はレール方向へ伸びない (スタイルシートが交差軸で持つ既定と同じ 0)
4136
+ useLayoutEffect(() => {
4137
+ labelReachMainRef.current = labelReach === undefined ? 0 : labelReach.mainPx
4138
+ })
3487
4139
 
3488
4140
  // ミクロレールの主つまみ。期間形態では下限つまみ、時点形態では唯一の時点つまみが同じ枠に立つ
3489
4141
  const microPrimaryHandle: "micro-low" | "micro-point" = isMicroPointShape ? "micro-point" : "micro-low"
@@ -3497,36 +4149,51 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3497
4149
  * Renders one stepper button identified by what it does to the value, never by where it sits.
3498
4150
  * 配置ではなく値への作用で識別したステッパーボタン 1 つを描画する関数。
3499
4151
  *
4152
+ * The arrow points along the rail (left / right, or down / up when vertical); the button takes its explicit cell
4153
+ * in the root grid (leading or trailing) and registers its element so the range-area wheel can tell a stepper
4154
+ * from the band it stands across. A disabled slider disables the button natively; a stepper whose step cannot move
4155
+ * stays focusable and only becomes unavailable.
4156
+ * 矢印はレールに沿って向き (横は左右、縦は下上)、ボタンはルートのグリッドの明示セル (先頭 / 末尾) に置かれ、
4157
+ * 範囲領域のホイールがステッパーと跨いでいる帯とを区別できるよう要素を登録する。スライダー全体の無効時はネイティブに無効化し、
4158
+ * 1 単位も動けないだけのステッパーはフォーカス可能なまま使用不可になる。
4159
+ *
3500
4160
  * @param direction - "decrease" steps toward minDate, "increase" steps toward maxDate / "decrease" は minDate 方向、"increase" は maxDate 方向へ 1 単位
3501
4161
  * @returns Stepper button element / ステッパーボタン要素
3502
4162
  */
3503
4163
  const renderStepperButton = (direction: StepDirection): React.JSX.Element => {
3504
4164
  const axis = isVertical ? "vertical" : "horizontal"
3505
4165
  const isDecrease = direction === "decrease"
3506
- const positionClass = STEPPER_POSITION_CLASSES[axis][direction]
4166
+ // 横向きは左端が下限なので減少が先頭、縦向きは上端が上限なので増加が先頭
4167
+ const isLeading = isVertical ? !isDecrease : isDecrease
3507
4168
 
3508
4169
  return (
3509
- <button
3510
- type="button"
3511
- className={`period-slider-stepper-btn relative after:absolute after:inset-[-11px] after:content-[''] ${positionClass} flex h-6 w-6 shrink-0 items-center justify-center rounded-md border border-slate-300 bg-white font-bold text-[10px] text-slate-700 leading-none shadow-2xs transition-all hover:bg-slate-100 hover:text-indigo-600 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 active:scale-95 disabled:cursor-not-allowed disabled:opacity-30 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200 dark:hover:bg-slate-700 ${cursorClass}`}
3512
- onClick={() => shift(isDecrease ? -1 : 1)}
3513
- disabled={isDecrease ? stepperDecreaseDisabled : stepperIncreaseDisabled}
3514
- aria-label={isDecrease ? decreaseAriaLabel : increaseAriaLabel}>
3515
- {STEPPER_GLYPHS[axis][direction]}
3516
- </button>
4170
+ <StepperButton
4171
+ ref={isDecrease ? decreaseStepperRef : increaseStepperRef}
4172
+ neighbour="rail"
4173
+ direction={STEPPER_ARROWS[axis][direction]}
4174
+ disabled={disabled}
4175
+ canStep={isDecrease ? canStepDecrease : canStepIncrease}
4176
+ onStep={() => shift(isDecrease ? -1 : 1)}
4177
+ ariaLabel={isDecrease ? decreaseAriaLabel : increaseAriaLabel}
4178
+ className={`period-slider-stepper-btn ${STEPPER_POSITION_CLASSES[axis][direction]} ${ROOT_GRID_CELL_CLASSES[axis][isLeading ? "leading" : "trailing"]}`}
4179
+ />
3517
4180
  )
3518
4181
  }
3519
4182
 
3520
4183
  return (
3521
4184
  <div
3522
- style={props.style}
3523
- className={`period-slider flex select-none items-center gap-2 ${isVertical ? "flex-col" : "flex-row"} ${className}`}
4185
+ ref={rootRef}
4186
+ style={rootStyle}
4187
+ className={`period-slider grid select-none place-items-center ${ROOT_GRID_CLASSES[isVertical ? "vertical" : "horizontal"][showStepper ? "withSteppers" : "railOnly"]} ${className}`}
3524
4188
  data-disabled={disabled ? "true" : undefined}
3525
4189
  data-unit={unit}
3526
4190
  data-mode={props.mode}
3527
4191
  data-orientation={isVertical ? "vertical" : "horizontal"}
3528
4192
  data-label-position={labelPosition}
3529
4193
  data-color-scheme={colorScheme}>
4194
+ {/* 範囲領域: Shift + ホイールの持ち主を幾何で決めるための矩形。描画もヒットテストも持たない (6.2) */}
4195
+ <div ref={rangeAreaRef} data-range-area="true" aria-hidden="true" className="period-slider-range-area" />
4196
+
3530
4197
  {/* 先頭のステッパー: 横向きは左端が定義域の下限なので減少、縦向きは上端が上限なので増加 */}
3531
4198
  {showStepper && renderStepperButton(isVertical ? "increase" : "decrease")}
3532
4199
 
@@ -3536,7 +4203,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3536
4203
  data-testid="period-slider-track"
3537
4204
  data-orientation={isVertical ? "vertical" : "horizontal"}
3538
4205
  data-vernier-orientation={isVernierMode ? vernierOrientation : undefined}
3539
- className={`period-slider-track relative flex-1 touch-none rounded-full bg-slate-200 dark:bg-slate-700 ${isVertical ? "h-48 w-2" : "h-2 w-full"} ${cursorClass}`}
4206
+ className={`period-slider-track relative touch-none rounded-full ${ROOT_GRID_CELL_CLASSES[isVertical ? "vertical" : "horizontal"][showStepper ? "rail" : "railOnly"]} ${cursorClass}`}
3540
4207
  onPointerDown={handleTrackPointerDown}
3541
4208
  onPointerMove={handleTrackPointerMove}
3542
4209
  onPointerLeave={handleTrackPointerLeave}>
@@ -3552,7 +4219,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3552
4219
  <stop offset="100%" stopColor={isMacroFirstRail ? palette.micro : palette.macro} stopOpacity={targetMicroOpacity} />
3553
4220
  </linearGradient>
3554
4221
  </defs>
3555
- <polygon points={isMacroFirstRail ? `12,${(1 - macroHighRatio) * 100} 12,${(1 - macroLowRatio) * 100} 20,100 20,0` : `12,0 12,100 20,${(1 - macroLowRatio) * 100} 20,${(1 - macroHighRatio) * 100}`} fill={`url(#${vernierGradId})`} />
4222
+ <path ref={projectionRef} data-testid="period-slider-vernier-projection" d={buildVernierProjectionPath(macroLowRatio, macroHighRatio, isVertical, isMacroFirstRail)} fill={`url(#${vernierGradId})`} />
3556
4223
  </svg>
3557
4224
  ) : (
3558
4225
  <svg className="period-slider-vernier-projection" role="presentation" aria-hidden="true" width="100%" height="32" viewBox="0 0 100 32" preserveAspectRatio="none">
@@ -3562,7 +4229,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3562
4229
  <stop offset="100%" stopColor={isMacroFirstRail ? palette.micro : palette.macro} stopOpacity={targetMicroOpacity} />
3563
4230
  </linearGradient>
3564
4231
  </defs>
3565
- <polygon points={isMacroFirstRail ? `${macroLowRatio * 100},12 ${macroHighRatio * 100},12 100,20 0,20` : `0,12 100,12 ${macroHighRatio * 100},20 ${macroLowRatio * 100},20`} fill={`url(#${vernierGradId})`} />
4232
+ <path ref={projectionRef} data-testid="period-slider-vernier-projection" d={buildVernierProjectionPath(macroLowRatio, macroHighRatio, isVertical, isMacroFirstRail)} fill={`url(#${vernierGradId})`} />
3566
4233
  </svg>
3567
4234
  ))}
3568
4235
 
@@ -3575,12 +4242,12 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3575
4242
  style={
3576
4243
  isVertical
3577
4244
  ? {
3578
- bottom: `calc(${macroLowRatio * 100}% - 8px)`,
3579
- height: `calc(${Math.max(0, (macroHighRatio - macroLowRatio) * 100)}% + 16px)`,
4245
+ bottom: `calc(${macroLowPosition} - 8px)`,
4246
+ height: `calc(${macroHighPosition} - ${macroLowPosition} + 16px)`,
3580
4247
  }
3581
4248
  : {
3582
- left: `calc(${macroLowRatio * 100}% - 8px)`,
3583
- width: `calc(${Math.max(0, (macroHighRatio - macroLowRatio) * 100)}% + 16px)`,
4249
+ left: `calc(${macroLowPosition} - 8px)`,
4250
+ width: `calc(${macroHighPosition} - ${macroLowPosition} + 16px)`,
3584
4251
  }
3585
4252
  }
3586
4253
  onPointerDown={handleVernierKnobPointerDown("macro-connect")}
@@ -3593,12 +4260,12 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3593
4260
  style={
3594
4261
  isVertical
3595
4262
  ? {
3596
- bottom: `calc(${microLowRatio * 100}% - 8px)`,
3597
- height: `calc(${Math.max(0, (microHighRatio - microLowRatio) * 100)}% + 16px)`,
4263
+ bottom: `calc(${microLowPosition} - 8px)`,
4264
+ height: `calc(${microHighPosition} - ${microLowPosition} + 16px)`,
3598
4265
  }
3599
4266
  : {
3600
- left: `calc(${microLowRatio * 100}% - 8px)`,
3601
- width: `calc(${Math.max(0, (microHighRatio - microLowRatio) * 100)}% + 16px)`,
4267
+ left: `calc(${microLowPosition} - 8px)`,
4268
+ width: `calc(${microHighPosition} - ${microLowPosition} + 16px)`,
3602
4269
  }
3603
4270
  }
3604
4271
  onPointerDown={handleVernierKnobPointerDown("micro-connect")}
@@ -3633,23 +4300,23 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3633
4300
  className={`period-slider-handle period-slider-handle-vernier ${isVertical ? "is-vertical" : ""} group absolute touch-none ${
3634
4301
  isVertical
3635
4302
  ? isMacroFirstRail
3636
- ? "after:absolute after:-inset-y-3 after:right-0 after:-left-4"
3637
- : "after:absolute after:-inset-y-3 after:-right-4 after:left-0"
4303
+ ? "after:absolute after:inset-y-[calc((100%-var(--ps-target-size))/2)] after:right-0 after:-left-4"
4304
+ : "after:absolute after:inset-y-[calc((100%-var(--ps-target-size))/2)] after:-right-4 after:left-0"
3638
4305
  : isMacroFirstRail
3639
- ? "after:absolute after:-inset-x-3 after:-top-4 after:bottom-0"
3640
- : "after:absolute after:-inset-x-3 after:top-0 after:-bottom-4"
3641
- } after:content-[''] focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-offset-2 ${cursorClass}`}
4306
+ ? "after:absolute after:inset-x-[calc((100%-var(--ps-target-size))/2)] after:-top-4 after:bottom-0"
4307
+ : "after:absolute after:inset-x-[calc((100%-var(--ps-target-size))/2)] after:top-0 after:-bottom-4"
4308
+ } after:content-[''] focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-offset-2 dark:focus-visible:ring-blue-400 ${cursorClass}`}
3642
4309
  style={
3643
4310
  isVertical
3644
4311
  ? {
3645
- bottom: `${macroLowRatio * 100}%`,
4312
+ bottom: macroLowPosition,
3646
4313
  left: isMacroFirstRail ? 0 : "auto",
3647
4314
  right: isMacroFirstRail ? "auto" : 0,
3648
4315
  transform: isMacroFirstRail ? "translate(-100%, 50%)" : "translate(100%, 50%)",
3649
4316
  zIndex: activeVernierHandle === "macro-low" || frontVernierHandle === "macro-low" ? 30 : 15,
3650
4317
  }
3651
4318
  : {
3652
- left: `${macroLowRatio * 100}%`,
4319
+ left: macroLowPosition,
3653
4320
  top: isMacroFirstRail ? 0 : "auto",
3654
4321
  bottom: isMacroFirstRail ? "auto" : 0,
3655
4322
  transform: isMacroFirstRail ? "translate(-50%, -100%)" : "translate(-50%, 100%)",
@@ -3664,7 +4331,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3664
4331
  data-vernier-pos={isVertical ? (isMacroFirstRail ? "left" : "right") : isMacroFirstRail ? "top" : "bottom"}
3665
4332
  data-handle-type="macro-low">
3666
4333
  <VernierKnobSvg type="macro" isTop={isMacroFirstRail} isVertical={isVertical} isLeft={isMacroFirstRail} />
3667
- {showHairline && <div className="period-slider-hairline" />}
4334
+ {showHairline && <div data-testid="period-slider-hairline" className="period-slider-hairline" />}
3668
4335
  {tooltipStyle !== "hover" && (
3669
4336
  <div
3670
4337
  className={`period-slider-tooltip absolute whitespace-nowrap font-medium shadow-md ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
@@ -3692,23 +4359,23 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3692
4359
  className={`period-slider-handle period-slider-handle-vernier ${isVertical ? "is-vertical" : ""} group absolute touch-none ${
3693
4360
  isVertical
3694
4361
  ? isMacroFirstRail
3695
- ? "after:absolute after:-inset-y-3 after:right-0 after:-left-4"
3696
- : "after:absolute after:-inset-y-3 after:-right-4 after:left-0"
4362
+ ? "after:absolute after:inset-y-[calc((100%-var(--ps-target-size))/2)] after:right-0 after:-left-4"
4363
+ : "after:absolute after:inset-y-[calc((100%-var(--ps-target-size))/2)] after:-right-4 after:left-0"
3697
4364
  : isMacroFirstRail
3698
- ? "after:absolute after:-inset-x-3 after:-top-4 after:bottom-0"
3699
- : "after:absolute after:-inset-x-3 after:top-0 after:-bottom-4"
3700
- } after:content-[''] focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-offset-2 ${cursorClass}`}
4365
+ ? "after:absolute after:inset-x-[calc((100%-var(--ps-target-size))/2)] after:-top-4 after:bottom-0"
4366
+ : "after:absolute after:inset-x-[calc((100%-var(--ps-target-size))/2)] after:top-0 after:-bottom-4"
4367
+ } after:content-[''] focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-offset-2 dark:focus-visible:ring-blue-400 ${cursorClass}`}
3701
4368
  style={
3702
4369
  isVertical
3703
4370
  ? {
3704
- bottom: `${macroHighRatio * 100}%`,
4371
+ bottom: macroHighPosition,
3705
4372
  left: isMacroFirstRail ? 0 : "auto",
3706
4373
  right: isMacroFirstRail ? "auto" : 0,
3707
4374
  transform: isMacroFirstRail ? "translate(-100%, 50%)" : "translate(100%, 50%)",
3708
4375
  zIndex: activeVernierHandle === "macro-high" || frontVernierHandle === "macro-high" ? 30 : 15,
3709
4376
  }
3710
4377
  : {
3711
- left: `${macroHighRatio * 100}%`,
4378
+ left: macroHighPosition,
3712
4379
  top: isMacroFirstRail ? 0 : "auto",
3713
4380
  bottom: isMacroFirstRail ? "auto" : 0,
3714
4381
  transform: isMacroFirstRail ? "translate(-50%, -100%)" : "translate(-50%, 100%)",
@@ -3723,7 +4390,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3723
4390
  data-vernier-pos={isVertical ? (isMacroFirstRail ? "left" : "right") : isMacroFirstRail ? "top" : "bottom"}
3724
4391
  data-handle-type="macro-high">
3725
4392
  <VernierKnobSvg type="macro" isTop={isMacroFirstRail} isVertical={isVertical} isLeft={isMacroFirstRail} />
3726
- {showHairline && <div className="period-slider-hairline" />}
4393
+ {showHairline && <div data-testid="period-slider-hairline" className="period-slider-hairline" />}
3727
4394
  {tooltipStyle !== "hover" && (
3728
4395
  <div
3729
4396
  className={`period-slider-tooltip absolute whitespace-nowrap font-medium shadow-md ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
@@ -3751,23 +4418,23 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3751
4418
  className={`period-slider-handle period-slider-handle-vernier ${isVertical ? "is-vertical" : ""} group absolute touch-none ${
3752
4419
  isVertical
3753
4420
  ? isMacroFirstRail
3754
- ? "after:absolute after:-inset-y-3 after:-right-4 after:left-0"
3755
- : "after:absolute after:-inset-y-3 after:right-0 after:-left-4"
4421
+ ? "after:absolute after:inset-y-[calc((100%-var(--ps-target-size))/2)] after:-right-4 after:left-0"
4422
+ : "after:absolute after:inset-y-[calc((100%-var(--ps-target-size))/2)] after:right-0 after:-left-4"
3756
4423
  : isMacroFirstRail
3757
- ? "after:absolute after:-inset-x-3 after:top-0 after:-bottom-4"
3758
- : "after:absolute after:-inset-x-3 after:-top-4 after:bottom-0"
3759
- } after:content-[''] focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-offset-2 ${cursorClass}`}
4424
+ ? "after:absolute after:inset-x-[calc((100%-var(--ps-target-size))/2)] after:top-0 after:-bottom-4"
4425
+ : "after:absolute after:inset-x-[calc((100%-var(--ps-target-size))/2)] after:-top-4 after:bottom-0"
4426
+ } after:content-[''] focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-offset-2 dark:focus-visible:ring-blue-400 ${cursorClass}`}
3760
4427
  style={
3761
4428
  isVertical
3762
4429
  ? {
3763
- bottom: `${microLowRatio * 100}%`,
4430
+ bottom: microLowPosition,
3764
4431
  left: isMacroFirstRail ? "auto" : 0,
3765
4432
  right: isMacroFirstRail ? 0 : "auto",
3766
4433
  transform: isMacroFirstRail ? "translate(100%, 50%)" : "translate(-100%, 50%)",
3767
4434
  zIndex: activeVernierHandle === microPrimaryHandle || frontVernierHandle === microPrimaryHandle ? 30 : 20,
3768
4435
  }
3769
4436
  : {
3770
- left: `${microLowRatio * 100}%`,
4437
+ left: microLowPosition,
3771
4438
  top: isMacroFirstRail ? "auto" : 0,
3772
4439
  bottom: isMacroFirstRail ? 0 : "auto",
3773
4440
  transform: isMacroFirstRail ? "translate(-50%, 100%)" : "translate(-50%, -100%)",
@@ -3782,7 +4449,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3782
4449
  data-vernier-pos={isVertical ? (isMacroFirstRail ? "right" : "left") : isMacroFirstRail ? "bottom" : "top"}
3783
4450
  data-handle-type={microPrimaryHandle}>
3784
4451
  <VernierKnobSvg type="micro" isTop={!isMacroFirstRail} isVertical={isVertical} isLeft={!isMacroFirstRail} />
3785
- {showHairline && <div className="period-slider-hairline" />}
4452
+ {showHairline && <div data-testid="period-slider-hairline" className="period-slider-hairline" />}
3786
4453
  {tooltipStyle !== "hover" && (
3787
4454
  <div
3788
4455
  className={`period-slider-tooltip absolute whitespace-nowrap font-medium shadow-md ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
@@ -3811,23 +4478,23 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3811
4478
  className={`period-slider-handle period-slider-handle-vernier ${isVertical ? "is-vertical" : ""} group absolute touch-none ${
3812
4479
  isVertical
3813
4480
  ? isMacroFirstRail
3814
- ? "after:absolute after:-inset-y-3 after:-right-4 after:left-0"
3815
- : "after:absolute after:-inset-y-3 after:right-0 after:-left-4"
4481
+ ? "after:absolute after:inset-y-[calc((100%-var(--ps-target-size))/2)] after:-right-4 after:left-0"
4482
+ : "after:absolute after:inset-y-[calc((100%-var(--ps-target-size))/2)] after:right-0 after:-left-4"
3816
4483
  : isMacroFirstRail
3817
- ? "after:absolute after:-inset-x-3 after:top-0 after:-bottom-4"
3818
- : "after:absolute after:-inset-x-3 after:-top-4 after:bottom-0"
3819
- } after:content-[''] focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-offset-2 ${cursorClass}`}
4484
+ ? "after:absolute after:inset-x-[calc((100%-var(--ps-target-size))/2)] after:top-0 after:-bottom-4"
4485
+ : "after:absolute after:inset-x-[calc((100%-var(--ps-target-size))/2)] after:-top-4 after:bottom-0"
4486
+ } after:content-[''] focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-offset-2 dark:focus-visible:ring-blue-400 ${cursorClass}`}
3820
4487
  style={
3821
4488
  isVertical
3822
4489
  ? {
3823
- bottom: `${microHighRatio * 100}%`,
4490
+ bottom: microHighPosition,
3824
4491
  left: isMacroFirstRail ? "auto" : 0,
3825
4492
  right: isMacroFirstRail ? 0 : "auto",
3826
4493
  transform: isMacroFirstRail ? "translate(100%, 50%)" : "translate(-100%, 50%)",
3827
4494
  zIndex: activeVernierHandle === "micro-high" || frontVernierHandle === "micro-high" ? 30 : 20,
3828
4495
  }
3829
4496
  : {
3830
- left: `${microHighRatio * 100}%`,
4497
+ left: microHighPosition,
3831
4498
  top: isMacroFirstRail ? "auto" : 0,
3832
4499
  bottom: isMacroFirstRail ? 0 : "auto",
3833
4500
  transform: isMacroFirstRail ? "translate(-50%, 100%)" : "translate(-50%, -100%)",
@@ -3842,7 +4509,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3842
4509
  data-vernier-pos={isVertical ? (isMacroFirstRail ? "right" : "left") : isMacroFirstRail ? "bottom" : "top"}
3843
4510
  data-handle-type="micro-high">
3844
4511
  <VernierKnobSvg type="micro" isTop={!isMacroFirstRail} isVertical={isVertical} isLeft={!isMacroFirstRail} />
3845
- {showHairline && <div className="period-slider-hairline" />}
4512
+ {showHairline && <div data-testid="period-slider-hairline" className="period-slider-hairline" />}
3846
4513
  {tooltipStyle !== "hover" && (
3847
4514
  <div
3848
4515
  className={`period-slider-tooltip absolute whitespace-nowrap font-medium shadow-md ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
@@ -3869,7 +4536,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3869
4536
  const enc = encode(unit, d)
3870
4537
  const pct = valueToPct(idx)
3871
4538
  const tickStyle: CSSProperties = isVertical ? { bottom: `${pct}%`, left: "50%", transform: "translate(-50%, 50%)" } : { left: `${pct}%`, top: "50%", transform: "translate(-50%, -50%)" }
3872
- return <div key={`tick-${enc}`} data-testid="period-slider-tick" className="period-slider-tick absolute h-1.5 w-1.5 rounded-full bg-slate-400/60 dark:bg-slate-500/60" style={tickStyle} />
4539
+ return <div key={`tick-${enc}`} data-testid="period-slider-tick" className="period-slider-tick absolute h-1.5 w-1.5 rounded-full" style={tickStyle} />
3873
4540
  })}
3874
4541
  </div>
3875
4542
  )}
@@ -3898,7 +4565,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3898
4565
  aria-valuenow={currentLowVal}
3899
4566
  aria-valuetext={props.formatAriaValueText ? props.formatAriaValueText(lowDate, unit) : formatScreenReaderLabel(unit, lowDate, props.formatLabel, locale)}
3900
4567
  aria-orientation={isVertical ? "vertical" : "horizontal"}
3901
- className={`period-slider-handle group absolute h-4 w-4 touch-none after:absolute after:inset-[-14px] after:content-[''] focus:outline-none focus-visible:outline-none ${cursorClass}`}
4568
+ className={`period-slider-handle group absolute h-4 w-4 touch-none after:absolute after:inset-[calc((100%-var(--ps-target-size))/2)] after:content-[''] focus-visible:outline-hidden ${cursorClass}`}
3902
4569
  style={lowHandleStyle}
3903
4570
  onPointerDown={handleKnobPointerDown("low")}
3904
4571
  onKeyDown={handleKeyDown("low")}
@@ -3907,7 +4574,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3907
4574
  data-front={isLowFront ? "true" : undefined}>
3908
4575
  <div
3909
4576
  data-testid="period-slider-knob"
3910
- className={`period-slider-knob h-full w-full rounded-full border-2 border-white bg-[var(--aqps-accent-color)] group-focus-visible:ring-2 group-focus-visible:ring-blue-600 group-focus-visible:ring-offset-2 dark:border-slate-800 dark:bg-[var(--aqps-accent-light)] ${activeHandle === "low" ? "" : "shadow-md"}`}
4577
+ className={`period-slider-knob h-full w-full rounded-full border-2 border-white bg-[var(--aqps-accent-color)] group-focus-visible:ring-2 group-focus-visible:ring-blue-600 group-focus-visible:ring-offset-2 dark:border-slate-800 dark:bg-[var(--aqps-accent-light)] dark:group-focus-visible:ring-blue-400 ${activeHandle === "low" ? "" : "shadow-md"}`}
3911
4578
  />
3912
4579
  {tooltipStyle !== "hover" && (
3913
4580
  <div
@@ -3918,7 +4585,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3918
4585
  data-front={isLowFront ? "true" : undefined}
3919
4586
  data-duplicate={isLabelMerged && !isLowFront ? "true" : undefined}
3920
4587
  ref={lowLabelRef}
3921
- style={lowTooltipStyle}>
4588
+ style={flatPlacement.lowStyle}>
3922
4589
  {formatLabel(unit, lowDate, props.formatLabel, locale)}
3923
4590
  </div>
3924
4591
  )}
@@ -3936,7 +4603,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3936
4603
  aria-valuenow={currentHighVal}
3937
4604
  aria-valuetext={props.formatAriaValueText ? props.formatAriaValueText(highDate, unit) : formatScreenReaderLabel(unit, highDate, props.formatLabel, locale)}
3938
4605
  aria-orientation={isVertical ? "vertical" : "horizontal"}
3939
- className={`period-slider-handle group absolute h-4 w-4 touch-none after:absolute after:inset-[-14px] after:content-[''] focus:outline-none focus-visible:outline-none ${cursorClass}`}
4606
+ className={`period-slider-handle group absolute h-4 w-4 touch-none after:absolute after:inset-[calc((100%-var(--ps-target-size))/2)] after:content-[''] focus-visible:outline-hidden ${cursorClass}`}
3940
4607
  style={highHandleStyle}
3941
4608
  onPointerDown={handleKnobPointerDown("high")}
3942
4609
  onKeyDown={handleKeyDown("high")}
@@ -3945,7 +4612,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3945
4612
  data-front={isHighFront ? "true" : undefined}>
3946
4613
  <div
3947
4614
  data-testid="period-slider-knob"
3948
- className={`period-slider-knob h-full w-full rounded-full border-2 border-white bg-[var(--aqps-accent-color)] group-focus-visible:ring-2 group-focus-visible:ring-blue-600 group-focus-visible:ring-offset-2 dark:border-slate-800 dark:bg-[var(--aqps-accent-light)] ${activeHandle === "high" ? "" : "shadow-md"}`}
4615
+ className={`period-slider-knob h-full w-full rounded-full border-2 border-white bg-[var(--aqps-accent-color)] group-focus-visible:ring-2 group-focus-visible:ring-blue-600 group-focus-visible:ring-offset-2 dark:border-slate-800 dark:bg-[var(--aqps-accent-light)] dark:group-focus-visible:ring-blue-400 ${activeHandle === "high" ? "" : "shadow-md"}`}
3949
4616
  />
3950
4617
  {tooltipStyle !== "hover" && (
3951
4618
  <div
@@ -3956,7 +4623,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3956
4623
  data-front={isHighFront ? "true" : undefined}
3957
4624
  data-duplicate={isLabelMerged && !isHighFront ? "true" : undefined}
3958
4625
  ref={highLabelRef}
3959
- style={highTooltipStyle}>
4626
+ style={flatPlacement.highStyle}>
3960
4627
  {formatLabel(unit, highDate, props.formatLabel, locale)}
3961
4628
  </div>
3962
4629
  )}