@aiquants/period-slider 0.4.1 → 0.5.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.
@@ -210,7 +210,7 @@ export interface BasePeriodSliderProps extends AccessibleSliderLabels {
210
210
  tooltipStyle?: "always" | "hover" | "balloon"
211
211
  /** Label position: "top" (default) or "bottom" / ラベル表示位置("top": 上側 [既定], "bottom": 下側) */
212
212
  labelPosition?: PeriodSliderLabelPosition
213
- /** Whether to automatically slant labels when close in range mode (default: true) / Rangeモードで接近時に自動斜め表示するか(既定: true) */
213
+ /** Whether to automatically slant labels when a pair comes close, in range mode and on both vernier rails (default: true) / Range モードとノギスの両レールで、対が接近した時に自動斜め表示するか (既定: true) */
214
214
  autoSlantLabels?: boolean
215
215
  /** Renders the slider along the vertical axis (default: false) / 垂直方向レイアウト (既定: false) */
216
216
  isVertical?: boolean
@@ -235,7 +235,7 @@ export interface PeriodSliderRangeProps extends BasePeriodSliderProps {
235
235
  mode: "range"
236
236
  /** Controlled selected date range tuple [lower, upper] / 制御時の選択期間タプル */
237
237
  range?: [Date, Date]
238
- /** Initial date range tuple for uncontrolled usage / 非制御時の初期選択期間タプル */
238
+ /** Initial date range tuple for uncontrolled usage; with `range` also omitted the selection starts at the domain bounds / 非制御時の初期選択期間タプル。`range` ともに未指定なら選択は定義域の両端から開始 */
239
239
  defaultRange?: [Date, Date]
240
240
  /** Callback triggered when the selected range changes / 期間変更時コールバック */
241
241
  onChangeRange?: (lower: Date, upper: Date) => void
@@ -260,7 +260,7 @@ export interface PeriodSliderPointProps extends BasePeriodSliderProps {
260
260
  mode: "point"
261
261
  /** Controlled selected point date / 制御時の選択日付 */
262
262
  value?: Date
263
- /** Initial point date for uncontrolled usage / 非制御時の初期選択日付 */
263
+ /** Initial point date for uncontrolled usage; with `value` also omitted the selection starts at the domain start / 非制御時の初期選択日付。`value` ともに未指定なら選択は定義域の先頭から開始 */
264
264
  defaultValue?: Date
265
265
  /** Callback triggered when the selected point changes / ポイント変更時コールバック */
266
266
  onChangePoint?: (value: Date) => void
@@ -402,7 +402,11 @@ export const encode = (unit: PeriodSliderUnit, d: Date): number => {
402
402
 
403
403
  if (unit === "year") return y
404
404
  if (unit === "month") return y * 12 + (m - 1)
405
- return Math.floor(Date.UTC(y, m - 1, day) / (24 * 60 * 60 * 1000))
405
+ // Date.UTC は 0-99 年を 1900 年代へ写像するため、日キーだけ年が 1900 年ずれ、99 年から 100 年へ跨いだ瞬間に単調性まで壊れる
406
+ const utcMidnight = new Date(0)
407
+ utcMidnight.setUTCFullYear(y, m - 1, day)
408
+ utcMidnight.setUTCHours(0, 0, 0, 0)
409
+ return Math.floor(utcMidnight.getTime() / (24 * 60 * 60 * 1000))
406
410
  }
407
411
 
408
412
  /**
@@ -414,14 +418,23 @@ export const encode = (unit: PeriodSliderUnit, d: Date): number => {
414
418
  * @returns Date pinned to the start of the encoded unit / エンコード単位の先頭に揃えた Date
415
419
  */
416
420
  export const decode = (unit: PeriodSliderUnit, val: number): Date => {
417
- if (unit === "year") return new Date(val, 0, 1)
421
+ // Date コンストラクタは 0-99 年を 1900 年代へ写像するため、年は必ず setFullYear で書き戻す
422
+ const restored = new Date(0)
423
+ restored.setHours(0, 0, 0, 0)
424
+ if (unit === "year") {
425
+ restored.setFullYear(val, 0, 1)
426
+ return restored
427
+ }
418
428
  if (unit === "month") {
419
429
  const y = Math.floor(val / 12)
420
- const m = val % 12
421
- return new Date(y, m, 1)
430
+ // 剰余演算子は負のキーで負の月を返し、年が 1 つ繰り下がって encode と往復しなくなる
431
+ const m = val - y * 12
432
+ restored.setFullYear(y, m, 1)
433
+ return restored
422
434
  }
423
435
  const utcDate = new Date(val * 24 * 60 * 60 * 1000)
424
- return new Date(utcDate.getUTCFullYear(), utcDate.getUTCMonth(), utcDate.getUTCDate())
436
+ restored.setFullYear(utcDate.getUTCFullYear(), utcDate.getUTCMonth(), utcDate.getUTCDate())
437
+ return restored
425
438
  }
426
439
 
427
440
  /**
@@ -642,6 +655,56 @@ export const getSortedAllowedDates = (allowedDates: Date[] | undefined, unit: Pe
642
655
  .map((enc) => encMap.get(enc) as Date)
643
656
  }
644
657
 
658
+ /**
659
+ * Maps a date onto its 0-1 position on a rail whose value space is a discrete candidate list.
660
+ * 離散候補日付を値空間とするレール上で、日付を 0-1 の位置比率へ写す関数。
661
+ *
662
+ * Inverse of railRatioToDiscreteIndex: "index" gives every candidate an equal share of the rail, "time"
663
+ * places it proportionally to the elapsed time between the first and the last candidate.
664
+ * railRatioToDiscreteIndex の逆写像 ("index" は等間隔配置、"time" は先頭・末尾候補間の実時間比例配置)。
665
+ *
666
+ * @param dates - Ascending, deduplicated candidate dates / 昇順・重複排除済みの候補日付一覧
667
+ * @param unit - Time resolution unit used to locate the entry / 要素の特定に用いる時間解像度単位
668
+ * @param snapMode - Placement strategy for the candidates / 候補日付の配置方式
669
+ * @param d - Date to place / 配置対象の日付
670
+ * @returns Position ratio between 0 and 1 / 0 から 1 の位置比率
671
+ */
672
+ const discreteDateToRailRatio = (dates: Date[], unit: PeriodSliderUnit, snapMode: PeriodSliderSnapMode, d: Date): number => {
673
+ const maxIdx = dates.length - 1
674
+ if (maxIdx <= 0) return 0
675
+ const idx = findNearestDateIndex(dates, d, unit)
676
+ if (snapMode === "time") {
677
+ const firstMs = dates[0].getTime()
678
+ const totalMs = dates[maxIdx].getTime() - firstMs
679
+ if (totalMs <= 0) return 0
680
+ return Math.max(0, Math.min(1, (dates[idx].getTime() - firstMs) / totalMs))
681
+ }
682
+ return idx / maxIdx
683
+ }
684
+
685
+ /**
686
+ * Resolves the candidate index a 0-1 rail position points at, in the space discreteDateToRailRatio renders.
687
+ * discreteDateToRailRatio が描画する空間で、0-1 の位置比率が指す候補日付のインデックスを解決する関数。
688
+ *
689
+ * @param dates - Ascending, deduplicated candidate dates / 昇順・重複排除済みの候補日付一覧
690
+ * @param unit - Time resolution unit used to locate the entry / 要素の特定に用いる時間解像度単位
691
+ * @param snapMode - Placement strategy for the candidates / 候補日付の配置方式
692
+ * @param ratio - Position ratio between 0 and 1 / 0 から 1 の位置比率
693
+ * @returns Index of the candidate the ratio resolves to / 比率が解決する候補日付のインデックス
694
+ */
695
+ const railRatioToDiscreteIndex = (dates: Date[], unit: PeriodSliderUnit, snapMode: PeriodSliderSnapMode, ratio: number): number => {
696
+ const maxIdx = dates.length - 1
697
+ if (maxIdx <= 0) return 0
698
+ const clamped = Math.max(0, Math.min(1, ratio))
699
+ if (snapMode === "time") {
700
+ const firstMs = dates[0].getTime()
701
+ const totalMs = dates[maxIdx].getTime() - firstMs
702
+ if (totalMs <= 0) return 0
703
+ return findNearestDateIndex(dates, new Date(firstMs + clamped * totalMs), unit)
704
+ }
705
+ return Math.max(0, Math.min(maxIdx, Math.round(clamped * maxIdx)))
706
+ }
707
+
645
708
  /**
646
709
  * Calculates dragging values when dragging knob handles.
647
710
  * ハンドルドラッグ時の数値を算出します。
@@ -966,6 +1029,21 @@ export const calculateLabelSlant = (lowPct: number, highPct: number, trackWidthP
966
1029
  }
967
1030
  }
968
1031
 
1032
+ /**
1033
+ * Drops the push-apart of a label pair that shows only one label, keeping rotation and clearance.
1034
+ * ラベルが 1 枚しか見えていない対から押し退けだけを取り除き、回転とクリアランスは保持する関数。
1035
+ *
1036
+ * `calculateLabelSlant` is right to separate two labels that sit at distance 0, because both of them
1037
+ * are normally shown. A merged pair is the one case where they are not, and the caller — never the
1038
+ * pure function — knows it.
1039
+ * 距離 0 の 2 ラベルを押し退ける `calculateLabelSlant` の挙動は、2 枚とも表示される通常時には正しい。
1040
+ * 畳んだ対だけが例外であり、それを知るのは純粋関数ではなく呼び出し側。
1041
+ *
1042
+ * @param geometry - Slant geometry solved for the pair / 対に対して解決した傾斜幾何
1043
+ * @returns Same geometry with both horizontal offsets zeroed / 水平オフセットのみ 0 にした同一幾何
1044
+ */
1045
+ const withoutHorizontalPush = (geometry: LabelSlantResult): LabelSlantResult => ({ ...geometry, lowOffsetX: 0, highOffsetX: 0 })
1046
+
969
1047
  /**
970
1048
  * Grabbable part of a vernier slider, naming both the rail and the element on it.
971
1049
  * ノギススライダーで掴める部位 (レールと要素の組)。
@@ -975,6 +1053,17 @@ export type VernierHandle = "macro-low" | "macro-high" | "macro-connect" | "micr
975
1053
  /**
976
1054
  * Resolves the target Vernier handle based on pointer primary-axis ratio and cross-axis offset relative to track center.
977
1055
  * トラック中心線に対するポインターの直交軸オフセットと主軸比率から、操作対象となるノギスハンドル(マクロまたはミクロ)を判定します。
1056
+ *
1057
+ * @param pointerPrimaryRatio - Pointer position along the track as a 0-1 ratio / トラック主軸上のポインター位置比率 (0-1)
1058
+ * @param pointerCrossAxisOffset - Signed pointer offset from the track center line in pixels / トラック中心線からのポインター直交軸オフセット (ピクセル、符号付き)
1059
+ * @param macroLowRatio - Macro window start position as a 0-1 ratio / マクロ窓開始位置の比率 (0-1)
1060
+ * @param macroHighRatio - Macro window end position as a 0-1 ratio / マクロ窓終了位置の比率 (0-1)
1061
+ * @param microLowRatio - Micro selection start position as a 0-1 ratio / ミクロ選択開始位置の比率 (0-1)
1062
+ * @param microHighRatio - Micro selection end position as a 0-1 ratio / ミクロ選択終了位置の比率 (0-1)
1063
+ * @param orientation - Which rail the macro scale is drawn on (default: "macro-top") / マクロスケールを描くレール (既定: "macro-top")
1064
+ * @param handleHitSlopRatio - Hit slop around a knob as a 0-1 ratio (default: 0.05) / つまみ周辺の当たり判定余裕 (0-1 比率、既定: 0.05)
1065
+ * @param allowConnectHandles - Whether a press inside a band may grab the band itself (default: true) / 帯の内側の押下で帯自体を掴めるか (既定: true)
1066
+ * @returns Handle the press targets / 押下が対象とするハンドル
978
1067
  */
979
1068
  export function resolveVernierTargetHandle(
980
1069
  pointerPrimaryRatio: number,
@@ -985,6 +1074,7 @@ export function resolveVernierTargetHandle(
985
1074
  microHighRatio: number,
986
1075
  orientation: "macro-top" | "macro-bottom" | "macro-left" | "macro-right" = "macro-top",
987
1076
  handleHitSlopRatio: number = 0.05,
1077
+ allowConnectHandles: boolean = true,
988
1078
  ): VernierHandle {
989
1079
  // orientation に応じて第一レール(上段または左段)がマクロかミクロかを決定
990
1080
  const isFirstRailMacro = orientation === "macro-top" || orientation === "macro-left"
@@ -1001,7 +1091,7 @@ export function resolveVernierTargetHandle(
1001
1091
  if (distHigh <= handleHitSlopRatio && distHigh < distLow) {
1002
1092
  return "macro-high"
1003
1093
  }
1004
- if (pointerPrimaryRatio >= macroLowRatio && pointerPrimaryRatio <= macroHighRatio) {
1094
+ if (allowConnectHandles && pointerPrimaryRatio >= macroLowRatio && pointerPrimaryRatio <= macroHighRatio) {
1005
1095
  return "macro-connect"
1006
1096
  }
1007
1097
  return distLow < distHigh ? "macro-low" : "macro-high"
@@ -1017,7 +1107,7 @@ export function resolveVernierTargetHandle(
1017
1107
  if (distHigh <= handleHitSlopRatio && distHigh < distLow) {
1018
1108
  return "micro-high"
1019
1109
  }
1020
- if (pointerPrimaryRatio >= microLowRatio && pointerPrimaryRatio <= microHighRatio) {
1110
+ if (allowConnectHandles && pointerPrimaryRatio >= microLowRatio && pointerPrimaryRatio <= microHighRatio) {
1021
1111
  return "micro-connect"
1022
1112
  }
1023
1113
  return distLow < distHigh ? "micro-low" : "micro-high"
@@ -1167,6 +1257,76 @@ const assertDateRangeTuple = (propName: string, value: unknown): void => {
1167
1257
  }
1168
1258
  }
1169
1259
 
1260
+ /**
1261
+ * Validates an optional scalar Date prop and fails fast on an unusable value.
1262
+ * 任意のスカラー日付 Props を検証し、利用不能な値で即座に失敗させる関数。
1263
+ *
1264
+ * @param propName - Prop name quoted in the error message / エラーメッセージへ埋め込む Props 名
1265
+ * @param value - Raw prop value supplied by the consumer / 利用側が指定した生の Props 値
1266
+ * @returns Nothing; the function only throws or returns normally / 戻り値なし (正常時は無返却)
1267
+ * @throws RangeError when the value is not a valid Date / 値が有効な Date でない場合
1268
+ */
1269
+ const assertSelectionDate = (propName: string, value: unknown): void => {
1270
+ if (!isValidDate(value)) throw new RangeError(`PeriodSlider: ${propName} must be a valid Date (received: ${describeDateValue(value)})`)
1271
+ }
1272
+
1273
+ /**
1274
+ * Validates that a selection date lies inside the declared slider domain.
1275
+ * 選択日付が宣言済みのスライダー定義域の内側にあることを検証する関数。
1276
+ *
1277
+ * An out-of-domain selection makes the slider report aria-valuenow outside aria-valuemin / aria-valuemax
1278
+ * and pin the knob to the rail end while its label shows a date the rail does not contain, so it is
1279
+ * rejected instead of being silently clamped.
1280
+ * 定義域外の選択は aria-valuenow が aria-valuemin / aria-valuemax の外側を指し、レール端に貼り付いたつまみが
1281
+ * レール上に存在しない日付を表示するため、黙ってクランプせず拒否。
1282
+ *
1283
+ * @param propName - Prop name quoted in the error message / エラーメッセージへ埋め込む Props 名
1284
+ * @param value - Selection date supplied by the consumer / 利用側が指定した選択日付
1285
+ * @param minDate - Lower domain boundary / 定義域下限
1286
+ * @param maxDate - Upper domain boundary / 定義域上限
1287
+ * @returns Nothing; the function only throws or returns normally / 戻り値なし (正常時は無返却)
1288
+ * @throws RangeError when the value lies outside [minDate, maxDate] / 値が [minDate, maxDate] の外にある場合
1289
+ */
1290
+ const assertSelectionWithinDomain = (propName: string, value: Date, minDate: Date, maxDate: Date): void => {
1291
+ if (value.getTime() < minDate.getTime() || value.getTime() > maxDate.getTime()) {
1292
+ throw new RangeError(`PeriodSlider: ${propName} must lie within [minDate, maxDate] (received: ${describeDateValue(value)}, minDate: ${describeDateValue(minDate)}, maxDate: ${describeDateValue(maxDate)})`)
1293
+ }
1294
+ }
1295
+
1296
+ /**
1297
+ * Validates the range and point selection props for tuple shape, Date validity and domain containment.
1298
+ * range / point モードの選択 Props について、タプル形状・Date 妥当性・定義域内包を検証する関数。
1299
+ *
1300
+ * An omitted prop keeps its specified meaning ("select the start of the domain") and is left alone; every
1301
+ * supplied value is validated, so a malformed one fails fast instead of silently selecting the domain start.
1302
+ * 未指定は仕様上の既定 (定義域先頭を選択) を保つため検証対象外。指定値は全て検証し、不正値が黙って定義域先頭へ化けることを防ぐ。
1303
+ *
1304
+ * @param props - Raw props the component was rendered with / コンポーネントへ渡された生の Props
1305
+ * @param minDate - Lower domain boundary / 定義域下限
1306
+ * @param maxDate - Upper domain boundary / 定義域上限
1307
+ * @returns Nothing; the function only throws or returns normally / 戻り値なし (正常時は無返却)
1308
+ * @throws RangeError when a supplied selection prop is malformed or lies outside the domain / 指定された選択 Props が不正または定義域外の場合
1309
+ */
1310
+ const assertSelectionProps = (props: PeriodSliderProps, minDate: Date, maxDate: Date): void => {
1311
+ if (props.mode === "range") {
1312
+ for (const propName of ["range", "defaultRange"] as const) {
1313
+ const value = props[propName]
1314
+ if (value === undefined) continue
1315
+ assertDateRangeTuple(propName, value)
1316
+ assertSelectionWithinDomain(`${propName}[0]`, value[0], minDate, maxDate)
1317
+ assertSelectionWithinDomain(`${propName}[1]`, value[1], minDate, maxDate)
1318
+ }
1319
+ return
1320
+ }
1321
+ if (props.mode !== "point") return
1322
+ for (const propName of ["value", "defaultValue"] as const) {
1323
+ const value = props[propName]
1324
+ if (value === undefined) continue
1325
+ assertSelectionDate(propName, value)
1326
+ assertSelectionWithinDomain(propName, value, minDate, maxDate)
1327
+ }
1328
+ }
1329
+
1170
1330
  /**
1171
1331
  * Validates the mandatory vernier props and resolves the micro selection that seeds the uncontrolled state.
1172
1332
  * ノギスモードの必須 Props を検証し、非制御ステートの初期値となるミクロ選択期間を解決する関数。
@@ -1191,8 +1351,13 @@ const assertVernierRanges = (macroRange: [Date, Date], microRange: [Date, Date]
1191
1351
  }
1192
1352
 
1193
1353
  /**
1194
- * Resolves the discrete date reached by one keyboard step inside a sorted allowed-date list.
1195
- * 昇順の離散候補日付一覧の中で、キーボード 1 操作分の移動先日付を解決する関数。
1354
+ * Resolves the candidate index reached by one keyboard step inside a sorted allowed-date list.
1355
+ * 昇順の離散候補日付一覧の中で、キーボード 1 操作分の移動先インデックスを解決する関数。
1356
+ *
1357
+ * The index rather than the date is returned so the caller can tell a step that moved from one that could
1358
+ * not, without re-deriving the current index from a date the rail may have rounded to a different unit.
1359
+ * 日付ではなくインデックスを返すことで、呼び出し側は「動いた押下」と「動けなかった押下」を、
1360
+ * 単位丸めで別日付になり得る現在値から再導出せずに判別可能。
1196
1361
  *
1197
1362
  * @param dates - Ascending, deduplicated allowed dates / 昇順・重複排除済みの候補日付一覧
1198
1363
  * @param unit - Time resolution unit used to locate the current entry / 現在値の特定に用いる時間解像度単位
@@ -1202,15 +1367,14 @@ const assertVernierRanges = (macroRange: [Date, Date], microRange: [Date, Date]
1202
1367
  * @param delta - Signed number of indices to move / 移動するインデックス数 (符号付き)
1203
1368
  * @param isHome - Whether the Home key was pressed / Home キー押下か
1204
1369
  * @param isEnd - Whether the End key was pressed / End キー押下か
1205
- * @returns Allowed date the handle moves to / つまみの移動先となる候補日付
1370
+ * @returns Index of the allowed date the handle moves to / つまみの移動先となる候補日付のインデックス
1206
1371
  */
1207
- const stepDiscreteDate = (dates: Date[], unit: PeriodSliderUnit, current: Date, lowerBound: Date, upperBound: Date, delta: number, isHome: boolean, isEnd: boolean): Date => {
1372
+ const stepDiscreteIndex = (dates: Date[], unit: PeriodSliderUnit, current: Date, lowerBound: Date, upperBound: Date, delta: number, isHome: boolean, isEnd: boolean): number => {
1208
1373
  const lowIdx = findNearestDateIndex(dates, lowerBound, unit)
1209
1374
  const highIdx = findNearestDateIndex(dates, upperBound, unit)
1210
- if (isHome) return dates[lowIdx]
1211
- if (isEnd) return dates[highIdx]
1212
- const nextIdx = Math.max(lowIdx, Math.min(highIdx, findNearestDateIndex(dates, current, unit) + delta))
1213
- return dates[nextIdx]
1375
+ if (isHome) return lowIdx
1376
+ if (isEnd) return highIdx
1377
+ return Math.max(lowIdx, Math.min(highIdx, findNearestDateIndex(dates, current, unit) + delta))
1214
1378
  }
1215
1379
 
1216
1380
  /**
@@ -1314,6 +1478,97 @@ const useMeasuredBorderBox = (): [(element: HTMLElement | null) => void, Measure
1314
1478
  return [measureRef, box]
1315
1479
  }
1316
1480
 
1481
+ /**
1482
+ * Builds the slant geometry config of one label pair out of the two measured boxes.
1483
+ * 実測済みの 2 ボックスから 1 対分の傾斜幾何設定を構築する関数。
1484
+ *
1485
+ * Collision avoidance is decided by the real size of both labels: with only one of them measured the
1486
+ * wider one is unknown, so the push-apart would be wrong and the slanted label would cut into the
1487
+ * track. An unmeasured pair therefore means "no size", never an invented default.
1488
+ * 衝突回避は 2 枚の実寸で決まる。片方だけでは広い方が分からず押し出し量を誤ってトラックへ食い込ませる
1489
+ * ため、片方でも未実測なら既定値を捏造せず「寸法なし」として扱う。
1490
+ *
1491
+ * @param lowBox - Measured box of the low label, or null while unmeasured / 下限ラベルの実測ボックス (未実測時は null)
1492
+ * @param highBox - Measured box of the high label, or null while unmeasured / 上限ラベルの実測ボックス (未実測時は null)
1493
+ * @returns Config built from the larger of the pair, or undefined while either box is missing / 対の大きい方から構築した設定 (片方でも欠ければ undefined)
1494
+ */
1495
+ const buildPairSlantConfig = (lowBox: MeasuredBoxPx | null, highBox: MeasuredBoxPx | null): LabelSlantConfig | undefined => {
1496
+ if (lowBox === null || highBox === null) return undefined
1497
+ return { estimatedWidthPx: Math.max(lowBox.widthPx, highBox.widthPx), estimatedHeightPx: Math.max(lowBox.heightPx, highBox.heightPx) }
1498
+ }
1499
+
1500
+ /**
1501
+ * Placement one vernier label pair resolved, as geometry plus the inline style of each label.
1502
+ * ノギスの 1 対が解決した配置 (幾何と各ラベルのインラインスタイル)。
1503
+ */
1504
+ interface VernierPairPlacement {
1505
+ /** Geometry solved for the pair / 対に対して解決した傾斜幾何 */
1506
+ slant: LabelSlantResult
1507
+ /** Inline placement of the low label, or undefined to keep the rail baseline / 下限ラベルのインライン配置 (undefined はレール基準配置のまま) */
1508
+ lowStyle: CSSProperties | undefined
1509
+ /** Inline placement of the high label, or undefined to keep the rail baseline / 上限ラベルのインライン配置 (undefined はレール基準配置のまま) */
1510
+ highStyle: CSSProperties | undefined
1511
+ }
1512
+
1513
+ /**
1514
+ * Expresses one vernier label placement as a delta from the upright baseline of its own rail.
1515
+ * ノギスのラベル 1 枚の配置を、自レールの直立基準からの差分として表現する関数。
1516
+ *
1517
+ * @param offsetX - Horizontal push in pixels / 水平押し出し量 (ピクセル)
1518
+ * @param offsetYDelta - Extra vertical push the rotation adds, in pixels / 回転により増える垂直押し出し量 (ピクセル)
1519
+ * @param angleDeg - Rotation in degrees / 回転角 (度)
1520
+ * @returns Custom properties the stylesheet substitutes into the tooltip transform / スタイルシートがツールチップの transform へ代入するカスタムプロパティ
1521
+ */
1522
+ const buildVernierTooltipStyle = (offsetX: number, offsetYDelta: number, angleDeg: number): CSSProperties =>
1523
+ ({
1524
+ "--ps-tooltip-tx": `calc(-50% + ${offsetX}px)`,
1525
+ "--ps-tooltip-ty": `${offsetYDelta}px`,
1526
+ "--ps-tooltip-rot": `${angleDeg}deg`,
1527
+ }) as CSSProperties
1528
+
1529
+ /**
1530
+ * Solves the anti-collision placement of one vernier label pair.
1531
+ * ノギスの 1 対分について、ラベル衝突回避の配置を解決する関数。
1532
+ *
1533
+ * The rail stylesheet already stands an upright label off its own knob (`top` / `bottom: calc(100% + 8px)`
1534
+ * with `--ps-tooltip-ty: 0px`), so only the extra push the rotation adds belongs inline. Taking that
1535
+ * extra as the difference against the upright baseline of the same label size cancels the clearance
1536
+ * constant, which is why this never has to know the rail gap.
1537
+ * レール側 CSS は直立ラベルを既につまみから離して置いているため、インラインで与えるべきは回転で増える
1538
+ * 分だけ。同寸法の直立基準との差を取ると離隔定数が相殺されるので、この関数はレールの隙間量を知らなくてよい。
1539
+ *
1540
+ * The vertical rails ("macro-left" / "macro-right") are excluded for the same reason vertical range is:
1541
+ * the geometry is X-axis only (`lowOffsetX` / `highOffsetX`, distance derived from `ratio * trackLength`),
1542
+ * and their CSS baseline is a different placement (`--ps-tooltip-tx: 0px` / `--ps-tooltip-ty: -50%`),
1543
+ * so writing this result there would displace the label instead of separating the pair.
1544
+ * 縦向きレール ("macro-left" / "macro-right") は縦向き Range と同じ理由で除外する。幾何が X 軸専用であり、
1545
+ * かつ縦レールの CSS 基準配置が別物 (tx: 0px / ty: -50%) のため、ここの結果を書くと対を離すのではなく
1546
+ * ラベルを移動させてしまう。
1547
+ *
1548
+ * @param lowRatio - Low handle position along the track as a 0-1 ratio / トラック上の下限つまみ位置比率 (0-1)
1549
+ * @param highRatio - High handle position along the track as a 0-1 ratio / トラック上の上限つまみ位置比率 (0-1)
1550
+ * @param trackLengthPx - Measured track length in pixels / 実測トラック長 (ピクセル)
1551
+ * @param labelPosition - Side of the track this rail draws its labels on / このレールがラベルを描くトラックの側
1552
+ * @param config - Measured geometry of this pair, or undefined while unmeasured / この対の実測幾何 (未実測時は undefined)
1553
+ * @param isMerged - Whether the pair holds one value and therefore shows one label / 対が同一値で 1 枚だけ見えている状態か
1554
+ * @param isSlantable - Whether this rail may slant at all / このレールが傾斜してよいか
1555
+ * @returns Geometry of the pair and the inline placement of each of its two labels / 対の幾何と 2 枚それぞれのインライン配置
1556
+ */
1557
+ const solveVernierPairPlacement = (lowRatio: number, highRatio: number, trackLengthPx: number, labelPosition: PeriodSliderLabelPosition, config: LabelSlantConfig | undefined, isMerged: boolean, isSlantable: boolean): VernierPairPlacement => {
1558
+ const baseline = buildHorizontalSlantResult(labelPosition, config)
1559
+
1560
+ if (!isSlantable) return { slant: baseline, lowStyle: undefined, highStyle: undefined }
1561
+
1562
+ const solved = calculateLabelSlant(lowRatio * 100, highRatio * 100, trackLengthPx, labelPosition, config)
1563
+ const slant = isMerged ? withoutHorizontalPush(solved) : solved
1564
+
1565
+ return {
1566
+ slant,
1567
+ lowStyle: buildVernierTooltipStyle(slant.lowOffsetX, slant.lowOffsetY - baseline.lowOffsetY, slant.lowAngleDeg),
1568
+ highStyle: buildVernierTooltipStyle(slant.highOffsetX, slant.highOffsetY - baseline.highOffsetY, slant.highAngleDeg),
1569
+ }
1570
+ }
1571
+
1317
1572
  /**
1318
1573
  * What a stepper button does to the selected value.
1319
1574
  * ステッパーボタンが選択値へ与える作用。
@@ -1358,6 +1613,9 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1358
1613
  // 定義域が欠けたまま描画すると全ての位置計算が無根拠になるため、フック呼び出し前に失敗させる
1359
1614
  assertDomainBounds(minDate, maxDate)
1360
1615
 
1616
+ // 選択 Props も同じ地点で検証する。素通しすると空タプルや null が黙って定義域先頭の選択へ化ける
1617
+ assertSelectionProps(props, minDate, maxDate)
1618
+
1361
1619
  // 不正なロケールを黙って ISO 表記へ落とすと、利用側は翻訳が効かない理由に気付けない
1362
1620
  if (locale !== undefined) assertLocaleTag("locale", locale)
1363
1621
 
@@ -1464,6 +1722,11 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1464
1722
  const currentLowVal = draggingValues ? draggingValues[0] : isControlled ? initLow : uncontrolledValues[0]
1465
1723
  const currentHighVal = draggingValues ? draggingValues[1] : isControlled ? initHigh : uncontrolledValues[1]
1466
1724
 
1725
+ // 重複発火の判定基準。「最後に発火した値」を覚えると、利用側が別経路で選択を戻した瞬間に基準が実態から外れ、
1726
+ // その値へ二度と戻れなくなる。いま確定している選択そのものを基準にすればずれようがない
1727
+ const committedValuesRef = useRef<[number, number]>([currentLowVal, currentHighVal])
1728
+ committedValuesRef.current = [currentLowVal, currentHighVal]
1729
+
1467
1730
  // ------------------------------------------------------------------
1468
1731
  // C-2. ノギススケールの境界とドラッグ状態
1469
1732
  // ------------------------------------------------------------------
@@ -1523,6 +1786,11 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1523
1786
  return encode(macroUnit, props.macroRange[1])
1524
1787
  }, [props.mode, macroRangeEndMs, vernierMacroMaxEnc, macroUnit])
1525
1788
 
1789
+ // 位置と ARIA は正規化済みエンコード値、表示だけ生 prop という二重の真実を解消する。
1790
+ // 同じ値なら表示も一致することが構造的に保証される
1791
+ const vernierMacroLowDate = useMemo(() => decode(macroUnit, vernierMacroLowEnc), [macroUnit, vernierMacroLowEnc])
1792
+ const vernierMacroHighDate = useMemo(() => decode(macroUnit, vernierMacroHighEnc), [macroUnit, vernierMacroHighEnc])
1793
+
1526
1794
  // ミクロ境界 (マクロ窓がミクロのスケール範囲)。
1527
1795
  // マクロ窓は macroUnit 単位へ丸められるうえ末尾期間全体まで広げられるため、そのままでは定義域の外側まで伸びる。
1528
1796
  // レール自体を [minDate, maxDate] で切り落とさないと、aria-valuemin/max もドラッグ端も定義域外の日付を指す
@@ -1548,6 +1816,10 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1548
1816
  })
1549
1817
  }, [isVernierMode, microAllowedDates, microUnit, minTime, maxTime, vernierMicroMinEnc, vernierMicroMaxEnc])
1550
1818
 
1819
+ // 離散指定は窓内に候補が 1 つでも残っているときだけ成立する。空配列のままでは窓内の連続値として扱う
1820
+ const macroIsDiscreteScale = macroIsDiscrete && sortedMacroAllowedDates.length > 0
1821
+ const microIsDiscreteScale = microIsDiscrete && sortedMicroAllowedDates.length > 0
1822
+
1551
1823
  const vernierMicroLowEnc = useMemo(() => {
1552
1824
  if (vernierMicroSelection === null) return vernierMicroMinEnc
1553
1825
  return encode(microUnit, vernierMicroSelection[0])
@@ -1562,14 +1834,14 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1562
1834
  const vernierMicroLowDate = useMemo(() => decode(microUnit, vernierMicroLowEnc), [microUnit, vernierMicroLowEnc])
1563
1835
  const vernierMicroHighDate = useMemo(() => decode(microUnit, vernierMicroHighEnc), [microUnit, vernierMicroHighEnc])
1564
1836
 
1565
- // 比率 (0.0 〜 1.0)
1837
+ // 比率 (0.0 〜 1.0)。離散レールは当たり判定と同じ候補空間で描かないと、つまみがポインターから離れて飛ぶ
1566
1838
  const macroSpan = Math.max(1, vernierMacroMaxEnc - vernierMacroMinEnc)
1567
- const macroLowRatio = Math.max(0, Math.min(1, (vernierMacroLowEnc - vernierMacroMinEnc) / macroSpan))
1568
- const macroHighRatio = Math.max(macroLowRatio, Math.min(1, (vernierMacroHighEnc - vernierMacroMinEnc) / macroSpan))
1839
+ const macroLowRatio = macroIsDiscreteScale ? discreteDateToRailRatio(sortedMacroAllowedDates, macroUnit, snapMode, vernierMacroLowDate) : Math.max(0, Math.min(1, (vernierMacroLowEnc - vernierMacroMinEnc) / macroSpan))
1840
+ const macroHighRatio = Math.max(macroLowRatio, macroIsDiscreteScale ? discreteDateToRailRatio(sortedMacroAllowedDates, macroUnit, snapMode, vernierMacroHighDate) : Math.min(1, (vernierMacroHighEnc - vernierMacroMinEnc) / macroSpan))
1569
1841
 
1570
1842
  const microSpan = Math.max(1, vernierMicroMaxEnc - vernierMicroMinEnc)
1571
- const microLowRatio = Math.max(0, Math.min(1, (vernierMicroLowEnc - vernierMicroMinEnc) / microSpan))
1572
- const microHighRatio = Math.max(microLowRatio, Math.min(1, (vernierMicroHighEnc - vernierMicroMinEnc) / microSpan))
1843
+ const microLowRatio = microIsDiscreteScale ? discreteDateToRailRatio(sortedMicroAllowedDates, microUnit, snapMode, vernierMicroLowDate) : Math.max(0, Math.min(1, (vernierMicroLowEnc - vernierMicroMinEnc) / microSpan))
1844
+ const microHighRatio = Math.max(microLowRatio, microIsDiscreteScale ? discreteDateToRailRatio(sortedMicroAllowedDates, microUnit, snapMode, vernierMicroHighDate) : Math.min(1, (vernierMicroHighEnc - vernierMicroMinEnc) / microSpan))
1573
1845
 
1574
1846
  // ------------------------------------------------------------------
1575
1847
  // D. デバウンスとコールバック通知
@@ -1635,22 +1907,22 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1635
1907
  */
1636
1908
  const clampToDomain = useCallback((d: Date): Date => new Date(Math.min(Math.max(d.getTime(), minTime), maxTime)), [minTime, maxTime])
1637
1909
 
1638
- const lastEmittedKeyRef = useRef<string | null>(null)
1639
-
1640
1910
  const notifyChange = useCallback(
1641
1911
  (nextLow: number, nextHigh: number, immediate = false) => {
1642
- const lowDate = valueToDate(nextLow)
1643
- const highDate = valueToDate(nextHigh)
1644
-
1645
- const key = propsRef.current.mode === "point" ? `${lowDate.getTime()}` : `${lowDate.getTime()}-${highDate.getTime()}`
1912
+ const [committedLow, committedHigh] = committedValuesRef.current
1913
+ const isUnchanged = propsRef.current.mode === "point" ? nextLow === committedLow : nextLow === committedLow && nextHigh === committedHigh
1646
1914
 
1647
- if (key === lastEmittedKeyRef.current && rangeEmitRef.current.timerId === null) {
1915
+ // 選択が動いていない確定値でコールバックを撃つと、変更駆動の消費側が無意味な再取得を行う。
1916
+ // デバウンス保留中だけは例外で、予約済みの古い値を確定値で上書きしないと指を離した位置が消える
1917
+ if (isUnchanged && rangeEmitRef.current.timerId === null) {
1648
1918
  return
1649
1919
  }
1650
1920
 
1921
+ const lowDate = valueToDate(nextLow)
1922
+ const highDate = valueToDate(nextHigh)
1923
+
1651
1924
  // ノギスモードは値空間 (rangeMin/rangeMax) が別系統のため、この経路ではなく notifyMicroRange / notifyMacroRange を使う
1652
1925
  const doEmit = () => {
1653
- lastEmittedKeyRef.current = key
1654
1926
  // 予約から発火までの間に利用側が別のハンドラへ差し替えることがある。
1655
1927
  // 予約時点のスナップショットを閉じ込めると、既に捨てられたクロージャだけが呼ばれる
1656
1928
  const p = propsRef.current
@@ -1781,6 +2053,13 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1781
2053
  const [lowLabelRef, lowLabelBox] = useMeasuredBorderBox()
1782
2054
  const [highLabelRef, highLabelBox] = useMeasuredBorderBox()
1783
2055
 
2056
+ // ノギスの 4 枚も同じ経路で測る。マクロとミクロは書式も単位も違うため実寸も違い、片方の幅で
2057
+ // 他方の押し出しを決めると必ずどちらかが外れる。測っていない対は「寸法なし」= 直立のまま
2058
+ const [macroLowLabelRef, macroLowLabelBox] = useMeasuredBorderBox()
2059
+ const [macroHighLabelRef, macroHighLabelBox] = useMeasuredBorderBox()
2060
+ const [microLowLabelRef, microLowLabelBox] = useMeasuredBorderBox()
2061
+ const [microHighLabelRef, microHighLabelBox] = useMeasuredBorderBox()
2062
+
1784
2063
  useEffect(() => {
1785
2064
  const el = trackRef.current
1786
2065
  if (!el) return
@@ -1887,10 +2166,9 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1887
2166
 
1888
2167
  let nextMacroLowDate: Date
1889
2168
  let nextMacroHighDate: Date
1890
- if (macroIsDiscrete && sortedMacroAllowedDates.length > 0) {
1891
- const maxIdx = sortedMacroAllowedDates.length - 1
1892
- const lowIdx = Math.max(0, Math.min(maxIdx, Math.round(nextMacroLowRatio * maxIdx)))
1893
- const highIdx = Math.max(lowIdx, Math.min(maxIdx, Math.round(nextMacroHighRatio * maxIdx)))
2169
+ if (macroIsDiscreteScale) {
2170
+ const lowIdx = railRatioToDiscreteIndex(sortedMacroAllowedDates, macroUnit, snapMode, nextMacroLowRatio)
2171
+ const highIdx = Math.max(lowIdx, railRatioToDiscreteIndex(sortedMacroAllowedDates, macroUnit, snapMode, nextMacroHighRatio))
1894
2172
  nextMacroLowDate = sortedMacroAllowedDates[lowIdx]
1895
2173
  nextMacroHighDate = sortedMacroAllowedDates[highIdx]
1896
2174
  } else {
@@ -1977,10 +2255,9 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1977
2255
 
1978
2256
  let nextMicroLowDate: Date
1979
2257
  let nextMicroHighDate: Date
1980
- if (microIsDiscrete && sortedMicroAllowedDates.length > 0) {
1981
- const maxIdx = sortedMicroAllowedDates.length - 1
1982
- const lowIdx = Math.max(0, Math.min(maxIdx, Math.round(nextMicroLowRatio * maxIdx)))
1983
- const highIdx = Math.max(lowIdx, Math.min(maxIdx, Math.round(nextMicroHighRatio * maxIdx)))
2258
+ if (microIsDiscreteScale) {
2259
+ const lowIdx = railRatioToDiscreteIndex(sortedMicroAllowedDates, microUnit, snapMode, nextMicroLowRatio)
2260
+ const highIdx = Math.max(lowIdx, railRatioToDiscreteIndex(sortedMicroAllowedDates, microUnit, snapMode, nextMicroHighRatio))
1984
2261
  nextMicroLowDate = sortedMicroAllowedDates[lowIdx]
1985
2262
  nextMicroHighDate = sortedMicroAllowedDates[highIdx]
1986
2263
  } else {
@@ -2058,8 +2335,8 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2058
2335
  isVertical,
2059
2336
  macroUnit,
2060
2337
  microUnit,
2061
- macroIsDiscrete,
2062
- microIsDiscrete,
2338
+ macroIsDiscreteScale,
2339
+ microIsDiscreteScale,
2063
2340
  sortedMacroAllowedDates,
2064
2341
  sortedMicroAllowedDates,
2065
2342
  vernierMacroMinEnc,
@@ -2193,6 +2470,35 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2193
2470
  startDrag(e.pointerId, handle, pos)
2194
2471
  }
2195
2472
 
2473
+ /**
2474
+ * Brings the focused range handle to the front so the surviving label follows the keyboard.
2475
+ * 焦点の当たった Range つまみを前面へ出し、生存ラベルをキーボード操作へ追従させるハンドラ生成関数。
2476
+ *
2477
+ * @param handle - Handle that received focus / 焦点を受け取ったつまみ
2478
+ * @returns Focus event handler for the given handle / 指定つまみ用の focus イベントハンドラ
2479
+ */
2480
+ const handleKnobFocus = (handle: "low" | "high") => () => {
2481
+ // 値が重なるとラベルは前面側の 1 枚しか見えない。焦点の当たったつまみを前面へ出さないと、
2482
+ // Tab で到達したつまみだけが値を表示しないまま操作されることになる。
2483
+ // ドラッグ中に限り前面はポインターが掴んだつまみの専権事項で、focus に譲ると交差時に掴んでいない側が前面へ出る
2484
+ if (disabled || activeHandleRef.current !== null) return
2485
+ setFrontHandle(handle)
2486
+ }
2487
+
2488
+ /**
2489
+ * Brings the focused Vernier handle to the front, mirroring the range-mode focus contract.
2490
+ * 焦点の当たったノギスつまみを前面へ出す、Range モードと同契約の focus ハンドラ生成関数。
2491
+ *
2492
+ * @param handle - Knob handle that received focus / 焦点を受け取ったつまみ
2493
+ * @returns Focus event handler for the given handle / 指定つまみ用の focus イベントハンドラ
2494
+ */
2495
+ const handleVernierKnobFocus = (handle: VernierHandle) => () => {
2496
+ // 同値で畳んだ対は前面側の 1 枚しか見えない。Tab で到達した側を前面へ出さないと、
2497
+ // これから操作するつまみだけが値を表示しない状態で残る
2498
+ if (disabled || activeVernierHandleRef.current !== null) return
2499
+ setFrontVernierHandle(handle)
2500
+ }
2501
+
2196
2502
  const handleVernierKnobPointerDown = (handle: VernierHandle) => (e: React.PointerEvent<HTMLDivElement>) => {
2197
2503
  if (disabled) return
2198
2504
  e.stopPropagation()
@@ -2222,7 +2528,8 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2222
2528
  const pointerRatio = calcRatioFromPos(e.clientX, e.clientY, rect)
2223
2529
  if (pointerRatio === null) return
2224
2530
  const pointerCrossAxisOffset = isVertical ? e.clientX - (rect.left + rect.width / 2) : e.clientY - (rect.top + rect.height / 2)
2225
- const targetHandle = resolveVernierTargetHandle(pointerRatio, pointerCrossAxisOffset, macroLowRatio, macroHighRatio, microLowRatio, microHighRatio, vernierOrientation)
2531
+ // 帯を隠したまま帯ドラッグだけ残ると、描かれていない当たり判定が生き続ける
2532
+ const targetHandle = resolveVernierTargetHandle(pointerRatio, pointerCrossAxisOffset, macroLowRatio, macroHighRatio, microLowRatio, microHighRatio, vernierOrientation, undefined, !hideConnectBar)
2226
2533
  startVernierDrag(e.pointerId, targetHandle, pointerRatio)
2227
2534
  return
2228
2535
  }
@@ -2284,11 +2591,34 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2284
2591
  }
2285
2592
  }
2286
2593
 
2594
+ /**
2595
+ * Re-contains the micro selection into a newly resolved macro window and emits it only when it moved.
2596
+ * 新しく確定したマクロ窓へミクロ選択を収め直し、実際に動いた場合のみ発火する関数。
2597
+ *
2598
+ * @param nextMacroLow - Start date of the macro window just resolved / 確定直後のマクロ窓開始日付
2599
+ * @param nextMacroHigh - End date of the macro window just resolved / 確定直後のマクロ窓終了日付
2600
+ * @returns Nothing / 戻り値なし
2601
+ */
2602
+ const containMicroRangeIntoMacroWindow = (nextMacroLow: Date, nextMacroHigh: Date): void => {
2603
+ // 次のレンダーでミクロレール端はこの式へ置き換わる。同じ式で収め直さないと aria-valuenow が aria-valuemax の外を指し続ける
2604
+ const nextMicroMinEnc = Math.max(encode(microUnit, nextMacroLow), encode(microUnit, minDate))
2605
+ const nextMicroMaxEnc = Math.min(encode(microUnit, getMacroWindowEndDate(macroUnit, microUnit, nextMacroHigh)), encode(microUnit, maxDate))
2606
+ const clampedLowEnc = Math.max(nextMicroMinEnc, Math.min(nextMicroMaxEnc, vernierMicroLowEnc))
2607
+ const clampedHighEnc = Math.max(clampedLowEnc, Math.min(nextMicroMaxEnc, vernierMicroHighEnc))
2608
+ if (clampedLowEnc === vernierMicroLowEnc && clampedHighEnc === vernierMicroHighEnc) return
2609
+ notifyMicroRange(decode(microUnit, clampedLowEnc), decode(microUnit, clampedHighEnc), true)
2610
+ }
2611
+
2287
2612
  /**
2288
2613
  * Handles keyboard navigation (ArrowLeft, ArrowRight, PageUp, PageDown, Home, End) for Vernier Caliper handles.
2289
2614
  * ノギス (Vernier Caliper) ハンドルのキーボード操作 (ArrowLeft, ArrowRight, PageUp, PageDown, Home, End) を処理するハンドラ。
2290
2615
  *
2291
- * @param handle - The Vernier handle being manipulated
2616
+ * A press that cannot move the handle emits nothing, and a macro window change re-contains the micro
2617
+ * selection, so keyboard and pointer leave the component in the same state.
2618
+ * 動けない押下は無発火とし、マクロ窓変更時はミクロ選択を窓内へ収め直すことで、キーボードとポインターの終状態を一致。
2619
+ *
2620
+ * @param handle - The Vernier handle being manipulated / 操作対象のノギスハンドル
2621
+ * @returns Keyboard event handler for the given handle / 指定ハンドル用のキーボードイベントハンドラ
2292
2622
  */
2293
2623
  const handleVernierKeyDown = (handle: "macro-low" | "macro-high" | "micro-low" | "micro-high") => (e: React.KeyboardEvent<HTMLDivElement>) => {
2294
2624
  if (disabled || !isVernierMode || props.mode !== "vernier") return
@@ -2322,57 +2652,75 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2322
2652
  }
2323
2653
  e.preventDefault()
2324
2654
 
2325
- // 離散指定時はポインター操作と同じ候補集合の上を移動しないと、キーボードだけが候補外の日付を発火する
2326
- const macroIsDiscreteScale = macroIsDiscrete && sortedMacroAllowedDates.length > 0
2327
- const microIsDiscreteScale = microIsDiscrete && sortedMicroAllowedDates.length > 0
2328
-
2329
2655
  if (handle === "macro-low") {
2330
2656
  const currentLow = decode(macroUnit, vernierMacroLowEnc)
2331
2657
  const currentHigh = decode(macroUnit, vernierMacroHighEnc)
2658
+ // 離散指定時はポインター操作と同じ候補集合の上を移動しないと、キーボードだけが候補外の日付を発火する
2332
2659
  if (macroIsDiscreteScale) {
2333
- notifyMacroRange(stepDiscreteDate(sortedMacroAllowedDates, macroUnit, currentLow, sortedMacroAllowedDates[0], currentHigh, delta, isHome, isEnd), currentHigh, true)
2660
+ const nextIdx = stepDiscreteIndex(sortedMacroAllowedDates, macroUnit, currentLow, sortedMacroAllowedDates[0], currentHigh, delta, isHome, isEnd)
2661
+ // 動けなかった押下で確定値を撃つと、変更駆動の消費側が無意味な再取得を行う
2662
+ if (nextIdx === findNearestDateIndex(sortedMacroAllowedDates, currentLow, macroUnit)) return
2663
+ const nextLow = sortedMacroAllowedDates[nextIdx]
2664
+ notifyMacroRange(nextLow, currentHigh, true)
2665
+ containMicroRangeIntoMacroWindow(nextLow, currentHigh)
2334
2666
  return
2335
2667
  }
2336
2668
  let next: number
2337
2669
  if (isHome) next = vernierMacroMinEnc
2338
2670
  else if (isEnd) next = vernierMacroHighEnc
2339
2671
  else next = Math.max(vernierMacroMinEnc, Math.min(vernierMacroHighEnc, vernierMacroLowEnc + delta))
2340
- notifyMacroRange(decode(macroUnit, next), currentHigh, true)
2672
+ if (next === vernierMacroLowEnc) return
2673
+ const nextLow = decode(macroUnit, next)
2674
+ notifyMacroRange(nextLow, currentHigh, true)
2675
+ containMicroRangeIntoMacroWindow(nextLow, currentHigh)
2341
2676
  } else if (handle === "macro-high") {
2342
2677
  const currentLow = decode(macroUnit, vernierMacroLowEnc)
2343
2678
  const currentHigh = decode(macroUnit, vernierMacroHighEnc)
2344
2679
  if (macroIsDiscreteScale) {
2345
- notifyMacroRange(currentLow, stepDiscreteDate(sortedMacroAllowedDates, macroUnit, currentHigh, currentLow, sortedMacroAllowedDates[sortedMacroAllowedDates.length - 1], delta, isHome, isEnd), true)
2680
+ const nextIdx = stepDiscreteIndex(sortedMacroAllowedDates, macroUnit, currentHigh, currentLow, sortedMacroAllowedDates[sortedMacroAllowedDates.length - 1], delta, isHome, isEnd)
2681
+ if (nextIdx === findNearestDateIndex(sortedMacroAllowedDates, currentHigh, macroUnit)) return
2682
+ const nextHigh = sortedMacroAllowedDates[nextIdx]
2683
+ notifyMacroRange(currentLow, nextHigh, true)
2684
+ containMicroRangeIntoMacroWindow(currentLow, nextHigh)
2346
2685
  return
2347
2686
  }
2348
2687
  let next: number
2349
2688
  if (isHome) next = vernierMacroLowEnc
2350
2689
  else if (isEnd) next = vernierMacroMaxEnc
2351
2690
  else next = Math.max(vernierMacroLowEnc, Math.min(vernierMacroMaxEnc, vernierMacroHighEnc + delta))
2352
- notifyMacroRange(currentLow, decode(macroUnit, next), true)
2691
+ if (next === vernierMacroHighEnc) return
2692
+ const nextHigh = decode(macroUnit, next)
2693
+ notifyMacroRange(currentLow, nextHigh, true)
2694
+ containMicroRangeIntoMacroWindow(currentLow, nextHigh)
2353
2695
  } else if (handle === "micro-low") {
2354
2696
  const currentLow = decode(microUnit, vernierMicroLowEnc)
2355
2697
  const currentHigh = decode(microUnit, vernierMicroHighEnc)
2356
2698
  if (microIsDiscreteScale) {
2357
- notifyMicroRange(stepDiscreteDate(sortedMicroAllowedDates, microUnit, currentLow, sortedMicroAllowedDates[0], currentHigh, delta, isHome, isEnd), currentHigh, true)
2699
+ const nextIdx = stepDiscreteIndex(sortedMicroAllowedDates, microUnit, currentLow, sortedMicroAllowedDates[0], currentHigh, delta, isHome, isEnd)
2700
+ if (nextIdx === findNearestDateIndex(sortedMicroAllowedDates, currentLow, microUnit)) return
2701
+ notifyMicroRange(sortedMicroAllowedDates[nextIdx], currentHigh, true)
2358
2702
  return
2359
2703
  }
2360
2704
  let next: number
2361
2705
  if (isHome) next = vernierMicroMinEnc
2362
2706
  else if (isEnd) next = vernierMicroHighEnc
2363
2707
  else next = Math.max(vernierMicroMinEnc, Math.min(vernierMicroHighEnc, vernierMicroLowEnc + delta))
2708
+ if (next === vernierMicroLowEnc) return
2364
2709
  notifyMicroRange(decode(microUnit, next), currentHigh, true)
2365
2710
  } else if (handle === "micro-high") {
2366
2711
  const currentLow = decode(microUnit, vernierMicroLowEnc)
2367
2712
  const currentHigh = decode(microUnit, vernierMicroHighEnc)
2368
2713
  if (microIsDiscreteScale) {
2369
- notifyMicroRange(currentLow, stepDiscreteDate(sortedMicroAllowedDates, microUnit, currentHigh, currentLow, sortedMicroAllowedDates[sortedMicroAllowedDates.length - 1], delta, isHome, isEnd), true)
2714
+ const nextIdx = stepDiscreteIndex(sortedMicroAllowedDates, microUnit, currentHigh, currentLow, sortedMicroAllowedDates[sortedMicroAllowedDates.length - 1], delta, isHome, isEnd)
2715
+ if (nextIdx === findNearestDateIndex(sortedMicroAllowedDates, currentHigh, microUnit)) return
2716
+ notifyMicroRange(currentLow, sortedMicroAllowedDates[nextIdx], true)
2370
2717
  return
2371
2718
  }
2372
2719
  let next: number
2373
2720
  if (isHome) next = vernierMicroLowEnc
2374
2721
  else if (isEnd) next = vernierMicroMaxEnc
2375
2722
  else next = Math.max(vernierMicroLowEnc, Math.min(vernierMicroMaxEnc, vernierMicroHighEnc + delta))
2723
+ if (next === vernierMicroHighEnc) return
2376
2724
  notifyMicroRange(currentLow, decode(microUnit, next), true)
2377
2725
  }
2378
2726
  }
@@ -2389,6 +2737,26 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2389
2737
  }
2390
2738
  notifyChange(nextVal, nextVal, true)
2391
2739
  } else if (p.mode === "vernier") {
2740
+ // 離散指定時はポインター操作・キーボード操作と同じ候補集合の上を移動しないと、ステッパーだけが候補外の日付を発火する
2741
+ if (microIsDiscreteScale) {
2742
+ const maxIdx = sortedMicroAllowedDates.length - 1
2743
+ const curLowIdx = findNearestDateIndex(sortedMicroAllowedDates, vernierMicroLowDate, microUnit)
2744
+ const curHighIdx = findNearestDateIndex(sortedMicroAllowedDates, vernierMicroHighDate, microUnit)
2745
+ const idxSpan = curHighIdx - curLowIdx
2746
+ let nextLowIdx = curLowIdx + delta
2747
+ let nextHighIdx = curHighIdx + delta
2748
+ if (delta < 0 && nextLowIdx < 0) {
2749
+ nextLowIdx = 0
2750
+ nextHighIdx = Math.min(maxIdx, idxSpan)
2751
+ } else if (delta > 0 && nextHighIdx > maxIdx) {
2752
+ nextHighIdx = maxIdx
2753
+ nextLowIdx = Math.max(0, maxIdx - idxSpan)
2754
+ }
2755
+ if (nextLowIdx !== curLowIdx || nextHighIdx !== curHighIdx) {
2756
+ notifyMicroRange(sortedMicroAllowedDates[nextLowIdx], sortedMicroAllowedDates[nextHighIdx], true)
2757
+ }
2758
+ return
2759
+ }
2392
2760
  const curLowEnc = vernierMicroLowEnc
2393
2761
  const curHighEnc = vernierMicroHighEnc
2394
2762
  const minEnc = vernierMicroMinEnc
@@ -2425,7 +2793,24 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2425
2793
  }
2426
2794
  }
2427
2795
  },
2428
- [currentLowVal, currentHighVal, rangeMin, rangeMax, isControlled, notifyChange, notifyMicroRange, vernierMicroLowEnc, vernierMicroHighEnc, vernierMicroMinEnc, vernierMicroMaxEnc, microUnit],
2796
+ [
2797
+ currentLowVal,
2798
+ currentHighVal,
2799
+ rangeMin,
2800
+ rangeMax,
2801
+ isControlled,
2802
+ notifyChange,
2803
+ notifyMicroRange,
2804
+ vernierMicroLowEnc,
2805
+ vernierMicroHighEnc,
2806
+ vernierMicroMinEnc,
2807
+ vernierMicroMaxEnc,
2808
+ microUnit,
2809
+ microIsDiscreteScale,
2810
+ sortedMicroAllowedDates,
2811
+ vernierMicroLowDate,
2812
+ vernierMicroHighDate,
2813
+ ],
2429
2814
  )
2430
2815
 
2431
2816
  // ------------------------------------------------------------------
@@ -2437,25 +2822,70 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2437
2822
  const lowDate = valueToDate(currentLowVal)
2438
2823
  const highDate = valueToDate(currentHighVal)
2439
2824
 
2440
- // 衝突回避は 2 枚のラベルの実寸で決まる。片方でも未実測なら広い方が分からず、押し出し量を誤って
2441
- // トラックへ食い込ませるため、point モード (ラベル 1 枚) 以外は両方揃うまで実寸なしとして扱う
2825
+ // Point モードはラベルが 1 枚で、その 1 枚の実寸がそのまま直立基準の高さになる。
2826
+ // 対になる 2 枚の規則 (片方でも未実測なら寸法なし) は buildPairSlantConfig が一手に持つ
2442
2827
  const labelSlantConfig: LabelSlantConfig | undefined = useMemo(() => {
2443
2828
  if (isPointMode) return lowLabelBox === null ? undefined : { estimatedWidthPx: lowLabelBox.widthPx, estimatedHeightPx: lowLabelBox.heightPx }
2444
- if (lowLabelBox === null || highLabelBox === null) return undefined
2445
- return {
2446
- estimatedWidthPx: Math.max(lowLabelBox.widthPx, highLabelBox.widthPx),
2447
- estimatedHeightPx: Math.max(lowLabelBox.heightPx, highLabelBox.heightPx),
2448
- }
2829
+ return buildPairSlantConfig(lowLabelBox, highLabelBox)
2449
2830
  }, [isPointMode, lowLabelBox, highLabelBox])
2450
2831
 
2832
+ // 値が一致するとき 2 枚のラベルは文字列まで同一になる (valueToDate が純粋なので構造的に保証される)。
2833
+ // ピクセル距離では別日と区別できないため判定は必ず値で行う。
2834
+ // point モードは上限値を下限値へ寄せるため素の一致判定が恒真になり、!isPointMode で外さないと成立しない
2835
+ const isLabelMerged = !isPointMode && currentLowVal === currentHighVal
2836
+
2451
2837
  const slantResult: LabelSlantResult = useMemo(() => {
2838
+ // 縦向きは X 軸オフセットしか返さない幾何を適用できない。Point モードは避ける相手そのものが居ない
2452
2839
  if (isPointMode || !autoSlantLabels || isVertical) return buildHorizontalSlantResult(labelPosition, labelSlantConfig)
2453
- return calculateLabelSlant(lowPct, highPct, trackLength, labelPosition, labelSlantConfig)
2454
- }, [isPointMode, autoSlantLabels, isVertical, lowPct, highPct, trackLength, labelPosition, labelSlantConfig])
2840
+
2841
+ const solved = calculateLabelSlant(lowPct, highPct, trackLength, labelPosition, labelSlantConfig)
2842
+ if (!isLabelMerged) return solved
2843
+
2844
+ // 併合時に残る 1 枚は前面側であり、front は焦点・押下・交差のたび入れ替わる。押し退けを残すと
2845
+ // 唯一のラベルが ±shiftX の間を飛び、離す相手も居ない。角度と垂直オフセットは 90deg のラベルを
2846
+ // つまみから逃がすために必要なので保持し、接近から一致まで角度も位置も連続させる
2847
+ return withoutHorizontalPush(solved)
2848
+ }, [isPointMode, isLabelMerged, autoSlantLabels, isVertical, lowPct, highPct, trackLength, labelPosition, labelSlantConfig])
2455
2849
 
2456
2850
  const isLowFront = activeHandle === "low" || (activeHandle !== "high" && frontHandle === "low")
2457
2851
  const isHighFront = !isPointMode && (activeHandle === "high" || (activeHandle !== "low" && frontHandle === "high"))
2458
2852
 
2853
+ // ノギスの 2 対も Range と同じ根拠で畳む。マクロ・ミクロとも符号化値から復元した日付を整形するため、
2854
+ // 符号化値が一致すればラベルは文字列まで一致する。しかもノギスには押し退けが無く 2 枚が同一矩形へ
2855
+ // 完全に重なるため、畳まないと同じ値が二重に読み上げられるだけで視覚的な情報も増えない
2856
+ const isVernierMacroLabelMerged = vernierMacroLowEnc === vernierMacroHighEnc
2857
+ const isVernierMicroLabelMerged = vernierMicroLowEnc === vernierMicroHighEnc
2858
+
2859
+ // 生存者は対の内側だけで決める。frontVernierHandle は 4 つのつまみで 1 本しか無く、相手の対や
2860
+ // 連結バーを操作している間は対の両方が非 front になるため、「front でない方を隠す」では両方消える。
2861
+ // 下限が front のときだけ下限を残し、それ以外は上限を残す (Range の初期前面と同じ上限優先) 全域規則
2862
+ const isVernierMacroLowLabelDuplicate = isVernierMacroLabelMerged && frontVernierHandle !== "macro-low"
2863
+ const isVernierMacroHighLabelDuplicate = isVernierMacroLabelMerged && frontVernierHandle === "macro-low"
2864
+ const isVernierMicroLowLabelDuplicate = isVernierMicroLabelMerged && frontVernierHandle !== "micro-low"
2865
+ const isVernierMicroHighLabelDuplicate = isVernierMicroLabelMerged && frontVernierHandle === "micro-low"
2866
+
2867
+ // ラベルが載る面はつまみと同じ側であり、JSX の data-vernier-pos が示す面と必ず一致する
2868
+ const macroRailLabelPosition: PeriodSliderLabelPosition = isMacroFirstRail ? "top" : "bottom"
2869
+ const microRailLabelPosition: PeriodSliderLabelPosition = isMacroFirstRail ? "bottom" : "top"
2870
+
2871
+ // マクロとミクロは同じトラックの上で比率も単位空間もラベル幅も異なる。1 つの計算を共有すると
2872
+ // 一方の押し退け量が他方の実寸で決まってしまうため、対ごとに独立して解く
2873
+ const macroLabelSlantConfig = useMemo(() => buildPairSlantConfig(macroLowLabelBox, macroHighLabelBox), [macroLowLabelBox, macroHighLabelBox])
2874
+ const microLabelSlantConfig = useMemo(() => buildPairSlantConfig(microLowLabelBox, microHighLabelBox), [microLowLabelBox, microHighLabelBox])
2875
+
2876
+ // 傾斜可否はレール単位で決まる。縦向きノギスは縦向き Range と同じ理由で外す (solveVernierPairPlacement 参照)
2877
+ const isVernierSlantable = autoSlantLabels && !isVertical
2878
+
2879
+ const macroPairPlacement = useMemo(
2880
+ () => solveVernierPairPlacement(macroLowRatio, macroHighRatio, trackLength, macroRailLabelPosition, macroLabelSlantConfig, isVernierMacroLabelMerged, isVernierSlantable),
2881
+ [macroLowRatio, macroHighRatio, trackLength, macroRailLabelPosition, macroLabelSlantConfig, isVernierMacroLabelMerged, isVernierSlantable],
2882
+ )
2883
+
2884
+ const microPairPlacement = useMemo(
2885
+ () => solveVernierPairPlacement(microLowRatio, microHighRatio, trackLength, microRailLabelPosition, microLabelSlantConfig, isVernierMicroLabelMerged, isVernierSlantable),
2886
+ [microLowRatio, microHighRatio, trackLength, microRailLabelPosition, microLabelSlantConfig, isVernierMicroLabelMerged, isVernierSlantable],
2887
+ )
2888
+
2459
2889
  const lowTooltipStyle: CSSProperties = useMemo(() => {
2460
2890
  if (isVertical) {
2461
2891
  return {
@@ -2521,8 +2951,12 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2521
2951
 
2522
2952
  const hoverDate = hoverValue !== null ? valueToDate(hoverValue) : null
2523
2953
 
2524
- const stepperDecreaseDisabled = disabled || (isVernierMode ? vernierMicroLowEnc <= vernierMicroMinEnc : isPointMode ? currentLowVal <= rangeMin : currentLowVal <= rangeMin && currentHighVal <= rangeMin)
2525
- const stepperIncreaseDisabled = disabled || (isVernierMode ? vernierMicroHighEnc >= vernierMicroMaxEnc : isPointMode ? currentHighVal >= rangeMax : currentLowVal >= rangeMax && currentHighVal >= rangeMax)
2954
+ // 離散ミクロでは先頭・末尾の候補が可動端。生の窓境界で判定すると、末尾候補を越えて候補外の日付を歩き続ける
2955
+ const microStepFloorEnc = microIsDiscreteScale ? encode(microUnit, sortedMicroAllowedDates[0]) : vernierMicroMinEnc
2956
+ const microStepCeilEnc = microIsDiscreteScale ? encode(microUnit, sortedMicroAllowedDates[sortedMicroAllowedDates.length - 1]) : vernierMicroMaxEnc
2957
+
2958
+ const stepperDecreaseDisabled = disabled || (isVernierMode ? vernierMicroLowEnc <= microStepFloorEnc : isPointMode ? currentLowVal <= rangeMin : currentLowVal <= rangeMin && currentHighVal <= rangeMin)
2959
+ const stepperIncreaseDisabled = disabled || (isVernierMode ? vernierMicroHighEnc >= microStepCeilEnc : isPointMode ? currentHighVal >= rangeMax : currentLowVal >= rangeMax && currentHighVal >= rangeMax)
2526
2960
 
2527
2961
  const cursorClass = disabled ? "cursor-not-allowed opacity-50" : "cursor-pointer"
2528
2962
 
@@ -2603,38 +3037,42 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2603
3037
  ))}
2604
3038
 
2605
3039
  {/* マクロ選択帯 & ミクロ選択帯 (ノギス時は半円つまみの直径16pxを完全に埋める長さに拡張) */}
2606
- <div
2607
- data-testid="period-slider-connect-macro"
2608
- className="period-slider-connect-macro"
2609
- style={
2610
- isVertical
2611
- ? {
2612
- bottom: `calc(${macroLowRatio * 100}% - 8px)`,
2613
- height: `calc(${Math.max(0, (macroHighRatio - macroLowRatio) * 100)}% + 16px)`,
2614
- }
2615
- : {
2616
- left: `calc(${macroLowRatio * 100}% - 8px)`,
2617
- width: `calc(${Math.max(0, (macroHighRatio - macroLowRatio) * 100)}% + 16px)`,
2618
- }
2619
- }
2620
- onPointerDown={handleVernierKnobPointerDown("macro-connect")}
2621
- />
2622
- <div
2623
- data-testid="period-slider-connect-micro"
2624
- className="period-slider-connect-micro"
2625
- style={
2626
- isVertical
2627
- ? {
2628
- bottom: `calc(${microLowRatio * 100}% - 8px)`,
2629
- height: `calc(${Math.max(0, (microHighRatio - microLowRatio) * 100)}% + 16px)`,
2630
- }
2631
- : {
2632
- left: `calc(${microLowRatio * 100}% - 8px)`,
2633
- width: `calc(${Math.max(0, (microHighRatio - microLowRatio) * 100)}% + 16px)`,
2634
- }
2635
- }
2636
- onPointerDown={handleVernierKnobPointerDown("micro-connect")}
2637
- />
3040
+ {!hideConnectBar && (
3041
+ <>
3042
+ <div
3043
+ data-testid="period-slider-connect-macro"
3044
+ className="period-slider-connect-macro"
3045
+ style={
3046
+ isVertical
3047
+ ? {
3048
+ bottom: `calc(${macroLowRatio * 100}% - 8px)`,
3049
+ height: `calc(${Math.max(0, (macroHighRatio - macroLowRatio) * 100)}% + 16px)`,
3050
+ }
3051
+ : {
3052
+ left: `calc(${macroLowRatio * 100}% - 8px)`,
3053
+ width: `calc(${Math.max(0, (macroHighRatio - macroLowRatio) * 100)}% + 16px)`,
3054
+ }
3055
+ }
3056
+ onPointerDown={handleVernierKnobPointerDown("macro-connect")}
3057
+ />
3058
+ <div
3059
+ data-testid="period-slider-connect-micro"
3060
+ className="period-slider-connect-micro"
3061
+ style={
3062
+ isVertical
3063
+ ? {
3064
+ bottom: `calc(${microLowRatio * 100}% - 8px)`,
3065
+ height: `calc(${Math.max(0, (microHighRatio - microLowRatio) * 100)}% + 16px)`,
3066
+ }
3067
+ : {
3068
+ left: `calc(${microLowRatio * 100}% - 8px)`,
3069
+ width: `calc(${Math.max(0, (microHighRatio - microLowRatio) * 100)}% + 16px)`,
3070
+ }
3071
+ }
3072
+ onPointerDown={handleVernierKnobPointerDown("micro-connect")}
3073
+ />
3074
+ </>
3075
+ )}
2638
3076
 
2639
3077
  {/* アダプティブ目盛線 (Ticks) */}
2640
3078
  {showVernierTicks && (
@@ -2657,7 +3095,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2657
3095
  aria-valuemin={vernierMacroMinEnc}
2658
3096
  aria-valuemax={vernierMacroHighEnc}
2659
3097
  aria-valuenow={vernierMacroLowEnc}
2660
- aria-valuetext={props.formatAriaValueText ? props.formatAriaValueText(props.macroRange[0], macroUnit) : formatScreenReaderLabel(macroUnit, props.macroRange[0], formatMacroLabel, locale)}
3098
+ aria-valuetext={props.formatAriaValueText ? props.formatAriaValueText(vernierMacroLowDate, macroUnit) : formatScreenReaderLabel(macroUnit, vernierMacroLowDate, formatMacroLabel, locale)}
2661
3099
  aria-orientation={isVertical ? "vertical" : "horizontal"}
2662
3100
  className={`period-slider-handle period-slider-handle-vernier ${isVertical ? "is-vertical" : ""} group absolute touch-none ${
2663
3101
  isVertical
@@ -2687,13 +3125,24 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2687
3125
  }
2688
3126
  onPointerDown={handleVernierKnobPointerDown("macro-low")}
2689
3127
  onKeyDown={handleVernierKeyDown("macro-low")}
3128
+ onFocus={handleVernierKnobFocus("macro-low")}
2690
3129
  data-active={activeVernierHandle === "macro-low" ? "true" : undefined}
2691
3130
  data-front={frontVernierHandle === "macro-low" ? "true" : undefined}
2692
3131
  data-vernier-pos={isVertical ? (isMacroFirstRail ? "left" : "right") : isMacroFirstRail ? "top" : "bottom"}
2693
3132
  data-handle-type="macro-low">
2694
3133
  <VernierKnobSvg type="macro" isTop={isMacroFirstRail} isVertical={isVertical} isLeft={isMacroFirstRail} />
2695
3134
  {showHairline && <div className="period-slider-hairline" />}
2696
- <div className="period-slider-tooltip absolute whitespace-nowrap rounded bg-slate-900 px-2 py-0.5 font-medium text-white text-xs shadow-md dark:bg-slate-800">{formatLabel(macroUnit, props.macroRange[0], formatMacroLabel, locale)}</div>
3135
+ {tooltipStyle !== "hover" && (
3136
+ <div
3137
+ className={`period-slider-tooltip absolute whitespace-nowrap rounded bg-slate-900 px-2 py-0.5 font-medium text-white text-xs shadow-md dark:bg-slate-800 ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
3138
+ data-tooltip-style={tooltipStyle}
3139
+ data-duplicate={isVernierMacroLowLabelDuplicate ? "true" : undefined}
3140
+ data-slanted={macroPairPlacement.slant.isSlanted ? "true" : undefined}
3141
+ ref={macroLowLabelRef}
3142
+ style={macroPairPlacement.lowStyle}>
3143
+ {formatLabel(macroUnit, vernierMacroLowDate, formatMacroLabel, locale)}
3144
+ </div>
3145
+ )}
2697
3146
  </div>
2698
3147
 
2699
3148
  {/* マクロ上限ハンドル (上半円爪 / 左半円爪) */}
@@ -2705,7 +3154,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2705
3154
  aria-valuemin={vernierMacroLowEnc}
2706
3155
  aria-valuemax={vernierMacroMaxEnc}
2707
3156
  aria-valuenow={vernierMacroHighEnc}
2708
- aria-valuetext={props.formatAriaValueText ? props.formatAriaValueText(props.macroRange[1], macroUnit) : formatScreenReaderLabel(macroUnit, props.macroRange[1], formatMacroLabel, locale)}
3157
+ aria-valuetext={props.formatAriaValueText ? props.formatAriaValueText(vernierMacroHighDate, macroUnit) : formatScreenReaderLabel(macroUnit, vernierMacroHighDate, formatMacroLabel, locale)}
2709
3158
  aria-orientation={isVertical ? "vertical" : "horizontal"}
2710
3159
  className={`period-slider-handle period-slider-handle-vernier ${isVertical ? "is-vertical" : ""} group absolute touch-none ${
2711
3160
  isVertical
@@ -2735,13 +3184,24 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2735
3184
  }
2736
3185
  onPointerDown={handleVernierKnobPointerDown("macro-high")}
2737
3186
  onKeyDown={handleVernierKeyDown("macro-high")}
3187
+ onFocus={handleVernierKnobFocus("macro-high")}
2738
3188
  data-active={activeVernierHandle === "macro-high" ? "true" : undefined}
2739
3189
  data-front={frontVernierHandle === "macro-high" ? "true" : undefined}
2740
3190
  data-vernier-pos={isVertical ? (isMacroFirstRail ? "left" : "right") : isMacroFirstRail ? "top" : "bottom"}
2741
3191
  data-handle-type="macro-high">
2742
3192
  <VernierKnobSvg type="macro" isTop={isMacroFirstRail} isVertical={isVertical} isLeft={isMacroFirstRail} />
2743
3193
  {showHairline && <div className="period-slider-hairline" />}
2744
- <div className="period-slider-tooltip absolute whitespace-nowrap rounded bg-slate-900 px-2 py-0.5 font-medium text-white text-xs shadow-md dark:bg-slate-800">{formatLabel(macroUnit, props.macroRange[1], formatMacroLabel, locale)}</div>
3194
+ {tooltipStyle !== "hover" && (
3195
+ <div
3196
+ className={`period-slider-tooltip absolute whitespace-nowrap rounded bg-slate-900 px-2 py-0.5 font-medium text-white text-xs shadow-md dark:bg-slate-800 ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
3197
+ data-tooltip-style={tooltipStyle}
3198
+ data-duplicate={isVernierMacroHighLabelDuplicate ? "true" : undefined}
3199
+ data-slanted={macroPairPlacement.slant.isSlanted ? "true" : undefined}
3200
+ ref={macroHighLabelRef}
3201
+ style={macroPairPlacement.highStyle}>
3202
+ {formatLabel(macroUnit, vernierMacroHighDate, formatMacroLabel, locale)}
3203
+ </div>
3204
+ )}
2745
3205
  </div>
2746
3206
 
2747
3207
  {/* ミクロ下限ハンドル (下半円爪 / 右半円爪) */}
@@ -2783,13 +3243,24 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2783
3243
  }
2784
3244
  onPointerDown={handleVernierKnobPointerDown("micro-low")}
2785
3245
  onKeyDown={handleVernierKeyDown("micro-low")}
3246
+ onFocus={handleVernierKnobFocus("micro-low")}
2786
3247
  data-active={activeVernierHandle === "micro-low" ? "true" : undefined}
2787
3248
  data-front={frontVernierHandle === "micro-low" ? "true" : undefined}
2788
3249
  data-vernier-pos={isVertical ? (isMacroFirstRail ? "right" : "left") : isMacroFirstRail ? "bottom" : "top"}
2789
3250
  data-handle-type="micro-low">
2790
3251
  <VernierKnobSvg type="micro" isTop={!isMacroFirstRail} isVertical={isVertical} isLeft={!isMacroFirstRail} />
2791
3252
  {showHairline && <div className="period-slider-hairline" />}
2792
- <div className="period-slider-tooltip absolute whitespace-nowrap rounded bg-slate-900 px-2 py-0.5 font-medium text-white text-xs shadow-md dark:bg-slate-800">{formatLabel(microUnit, vernierMicroLowDate, formatMicroLabel, locale)}</div>
3253
+ {tooltipStyle !== "hover" && (
3254
+ <div
3255
+ className={`period-slider-tooltip absolute whitespace-nowrap rounded bg-slate-900 px-2 py-0.5 font-medium text-white text-xs shadow-md dark:bg-slate-800 ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
3256
+ data-tooltip-style={tooltipStyle}
3257
+ data-duplicate={isVernierMicroLowLabelDuplicate ? "true" : undefined}
3258
+ data-slanted={microPairPlacement.slant.isSlanted ? "true" : undefined}
3259
+ ref={microLowLabelRef}
3260
+ style={microPairPlacement.lowStyle}>
3261
+ {formatLabel(microUnit, vernierMicroLowDate, formatMicroLabel, locale)}
3262
+ </div>
3263
+ )}
2793
3264
  </div>
2794
3265
 
2795
3266
  {/* ミクロ上限ハンドル (下半円爪 / 右半円爪) */}
@@ -2831,13 +3302,24 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2831
3302
  }
2832
3303
  onPointerDown={handleVernierKnobPointerDown("micro-high")}
2833
3304
  onKeyDown={handleVernierKeyDown("micro-high")}
3305
+ onFocus={handleVernierKnobFocus("micro-high")}
2834
3306
  data-active={activeVernierHandle === "micro-high" ? "true" : undefined}
2835
3307
  data-front={frontVernierHandle === "micro-high" ? "true" : undefined}
2836
3308
  data-vernier-pos={isVertical ? (isMacroFirstRail ? "right" : "left") : isMacroFirstRail ? "bottom" : "top"}
2837
3309
  data-handle-type="micro-high">
2838
3310
  <VernierKnobSvg type="micro" isTop={!isMacroFirstRail} isVertical={isVertical} isLeft={!isMacroFirstRail} />
2839
3311
  {showHairline && <div className="period-slider-hairline" />}
2840
- <div className="period-slider-tooltip absolute whitespace-nowrap rounded bg-slate-900 px-2 py-0.5 font-medium text-white text-xs shadow-md dark:bg-slate-800">{formatLabel(microUnit, vernierMicroHighDate, formatMicroLabel, locale)}</div>
3312
+ {tooltipStyle !== "hover" && (
3313
+ <div
3314
+ className={`period-slider-tooltip absolute whitespace-nowrap rounded bg-slate-900 px-2 py-0.5 font-medium text-white text-xs shadow-md dark:bg-slate-800 ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
3315
+ data-tooltip-style={tooltipStyle}
3316
+ data-duplicate={isVernierMicroHighLabelDuplicate ? "true" : undefined}
3317
+ data-slanted={microPairPlacement.slant.isSlanted ? "true" : undefined}
3318
+ ref={microHighLabelRef}
3319
+ style={microPairPlacement.highStyle}>
3320
+ {formatLabel(microUnit, vernierMicroHighDate, formatMicroLabel, locale)}
3321
+ </div>
3322
+ )}
2841
3323
  </div>
2842
3324
  </>
2843
3325
  ) : (
@@ -2883,6 +3365,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2883
3365
  style={lowHandleStyle}
2884
3366
  onPointerDown={handleKnobPointerDown("low")}
2885
3367
  onKeyDown={handleKeyDown("low")}
3368
+ onFocus={handleKnobFocus("low")}
2886
3369
  data-active={activeHandle === "low" ? "true" : undefined}
2887
3370
  data-front={isLowFront ? "true" : undefined}>
2888
3371
  <div
@@ -2896,6 +3379,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2896
3379
  data-label-position={labelPosition}
2897
3380
  data-slanted={slantResult.isSlanted ? "true" : undefined}
2898
3381
  data-front={isLowFront ? "true" : undefined}
3382
+ data-duplicate={isLabelMerged && !isLowFront ? "true" : undefined}
2899
3383
  ref={lowLabelRef}
2900
3384
  style={lowTooltipStyle}>
2901
3385
  {formatLabel(unit, lowDate, props.formatLabel, locale)}
@@ -2919,6 +3403,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2919
3403
  style={highHandleStyle}
2920
3404
  onPointerDown={handleKnobPointerDown("high")}
2921
3405
  onKeyDown={handleKeyDown("high")}
3406
+ onFocus={handleKnobFocus("high")}
2922
3407
  data-active={activeHandle === "high" ? "true" : undefined}
2923
3408
  data-front={isHighFront ? "true" : undefined}>
2924
3409
  <div
@@ -2932,6 +3417,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2932
3417
  data-label-position={labelPosition}
2933
3418
  data-slanted={slantResult.isSlanted ? "true" : undefined}
2934
3419
  data-front={isHighFront ? "true" : undefined}
3420
+ data-duplicate={isLabelMerged && !isHighFront ? "true" : undefined}
2935
3421
  ref={highLabelRef}
2936
3422
  style={highTooltipStyle}>
2937
3423
  {formatLabel(unit, highDate, props.formatLabel, locale)}