@aiquants/period-slider 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,10 @@
1
1
  /**
2
2
  * Period slider component: range, point and vernier dual-scale date selection on a single track.
3
+ * The vernier scale itself comes in two shapes - its micro rail selects either a period with two
4
+ * handles or a single point with one - so the component renders four selection shapes in total.
3
5
  * 1 本のトラック上で期間・時点・ノギス 2 段スケールの日付選択を行うコンポーネント本体。
6
+ * ノギスはさらに 2 形態 (ミクロレールが 2 つまみで期間を選ぶ形態と、1 つまみで時点を選ぶ形態) を持ち、
7
+ * 選択形態は全体で 4 つ。
4
8
  *
5
9
  * Holds the pure date encoding and geometry utilities shared by every mode, together with the
6
10
  * memoized React component and its prop-equality comparator.
@@ -163,11 +167,11 @@ export interface LabelSlantResult {
163
167
  * ステッパー名は配置ではなく値への作用で定義 (同じボタンが横向きでは左、縦向きでは下に立つため)。
164
168
  */
165
169
  export interface AccessibleSliderLabels {
166
- /** Accessible name for lower handle / 下限つまみのアクセシブル名 (既定: "Range start" / vernier モードでは "Micro range start") */
170
+ /** Accessible name for lower handle / 下限つまみのアクセシブル名 (既定: "Range start" / ノギスのミクロ期間形態では "Micro range start"。ミクロ時点形態には下限つまみが無く不活性) */
167
171
  lowerAriaLabel?: string
168
- /** Accessible name for upper handle / 上限つまみのアクセシブル名 (既定: "Range end" / vernier モードでは "Micro range end") */
172
+ /** Accessible name for upper handle / 上限つまみのアクセシブル名 (既定: "Range end" / ノギスのミクロ期間形態では "Micro range end"。ミクロ時点形態には上限つまみが無く不活性) */
169
173
  upperAriaLabel?: string
170
- /** Accessible name for single point handle / 単一選択つまみのアクセシブル名 (既定: "Selected date") */
174
+ /** Accessible name for the single selection handle of point mode and of the vernier micro point shape / 単一選択つまみのアクセシブル名 (既定: point モードでは "Selected date"、ノギスのミクロ時点形態では "Micro selected date") */
171
175
  pointAriaLabel?: string
172
176
  /** Accessible name for macro lower handle / マクロ下限つまみのアクセシブル名 (既定: "Macro range start") */
173
177
  macroLowerAriaLabel?: string
@@ -249,6 +253,9 @@ export interface PeriodSliderRangeProps extends BasePeriodSliderProps {
249
253
  microRange?: never
250
254
  defaultMicroRange?: never
251
255
  onChangeMicroRange?: never
256
+ microValue?: never
257
+ defaultMicroValue?: never
258
+ onChangeMicroPoint?: never
252
259
  }
253
260
 
254
261
  /**
@@ -274,13 +281,21 @@ export interface PeriodSliderPointProps extends BasePeriodSliderProps {
274
281
  microRange?: never
275
282
  defaultMicroRange?: never
276
283
  onChangeMicroRange?: never
284
+ microValue?: never
285
+ defaultMicroValue?: never
286
+ onChangeMicroPoint?: never
277
287
  }
278
288
 
279
289
  /**
280
- * Props of the vernier mode, where a macro window rail scopes the micro selection rail.
281
- * マクロ窓レールがミクロ選択レールの定義域となるノギスモードの Props。
290
+ * Props both vernier micro shapes share: the macro window rail and everything painted on either rail.
291
+ * ノギスの 2 形態が共有する Props (マクロ窓レールと両レールの描画設定)。
292
+ *
293
+ * The micro rail selects either a period or a point, and the props that express that choice live on the
294
+ * two shape interfaces below rather than here, so one shape's props can never be written on the other.
295
+ * ミクロレールの選択対象は期間か時点のいずれかであり、その選択を表す Props は本 interface ではなく
296
+ * 下の 2 形態 interface が持つため、一方の形態の Props をもう一方へ書くことは型として不可能。
282
297
  */
283
- export interface PeriodSliderVernierProps extends BasePeriodSliderProps {
298
+ export interface BasePeriodSliderVernierProps extends BasePeriodSliderProps {
284
299
  /** Vernier dual-scale integrated mode / ノギス型 2 段スケール一体型モード */
285
300
  mode: "vernier"
286
301
  /** Controlled macro window range [start, end] / マクロ側の広域表示窓 (必須・制御) */
@@ -288,13 +303,6 @@ export interface PeriodSliderVernierProps extends BasePeriodSliderProps {
288
303
  /** Callback triggered when the macro window changes / マクロ窓変更時コールバック */
289
304
  onChangeMacroRange?: (lower: Date, upper: Date) => void
290
305
 
291
- /** Controlled micro selected range tuple [lower, upper] / 制御時のミクロ選択期間タプル */
292
- microRange?: [Date, Date]
293
- /** Initial micro range tuple for uncontrolled usage / 非制御時の初期ミクロ選択期間タプル */
294
- defaultMicroRange?: [Date, Date]
295
- /** Callback triggered when the micro selected range changes / ミクロ選択範囲変更時コールバック */
296
- onChangeMicroRange?: (lower: Date, upper: Date) => void
297
-
298
306
  /** Vernier scale orientation; default is "macro-top" horizontally and "macro-left" when isVertical / ノギス配置方向 (既定: 横向き "macro-top"、isVertical 時 "macro-left") */
299
307
  vernierOrientation?: "macro-top" | "macro-bottom" | "macro-left" | "macro-right"
300
308
  /** Show semi-transparent trapezoid projection cone between macro and micro / 台形プロジェクション光の表示 (既定: true) */
@@ -330,6 +338,48 @@ export interface PeriodSliderVernierProps extends BasePeriodSliderProps {
330
338
  onChangePoint?: never
331
339
  }
332
340
 
341
+ /**
342
+ * Props of the vernier shape whose micro rail selects a period with two handles.
343
+ * ミクロレールが 2 つのつまみで期間を選ぶノギス形態の Props。
344
+ */
345
+ export interface PeriodSliderVernierRangeProps extends BasePeriodSliderVernierProps {
346
+ /** Controlled micro selected range tuple [lower, upper] / 制御時のミクロ選択期間タプル */
347
+ microRange?: [Date, Date]
348
+ /** Initial micro range tuple for uncontrolled usage / 非制御時の初期ミクロ選択期間タプル */
349
+ defaultMicroRange?: [Date, Date]
350
+ /** Callback triggered when the micro selected range changes / ミクロ選択範囲変更時コールバック */
351
+ onChangeMicroRange?: (lower: Date, upper: Date) => void
352
+
353
+ // ミクロ時点専用 Props の相互排他マーカー (ミクロが期間の形態では指定不可)
354
+ microValue?: never
355
+ defaultMicroValue?: never
356
+ onChangeMicroPoint?: never
357
+ }
358
+
359
+ /**
360
+ * Props of the vernier shape whose micro rail selects a single point with one handle.
361
+ * ミクロレールが 1 つのつまみで時点を選ぶノギス形態の Props。
362
+ */
363
+ export interface PeriodSliderVernierPointProps extends BasePeriodSliderVernierProps {
364
+ /** Controlled micro selected point / 制御時のミクロ選択時点 */
365
+ microValue?: Date
366
+ /** Initial micro point for uncontrolled usage / 非制御時の初期ミクロ選択時点 */
367
+ defaultMicroValue?: Date
368
+ /** Callback triggered when the micro selected point changes / ミクロ選択時点変更時コールバック */
369
+ onChangeMicroPoint?: (value: Date) => void
370
+
371
+ // ミクロ期間専用 Props の相互排他マーカー (ミクロが時点の形態では指定不可)
372
+ microRange?: never
373
+ defaultMicroRange?: never
374
+ onChangeMicroRange?: never
375
+ }
376
+
377
+ /**
378
+ * Discriminated union of both vernier micro shapes, keyed by which micro selection props are supplied.
379
+ * どちらのミクロ選択 Props を渡したかを判別子とする、ノギス 2 形態の判別可能合併型。
380
+ */
381
+ export type PeriodSliderVernierProps = PeriodSliderVernierRangeProps | PeriodSliderVernierPointProps
382
+
333
383
  /**
334
384
  * Discriminated union of every PeriodSlider mode, keyed by the mode prop.
335
385
  * mode Props を判別子とする全 PeriodSlider モードの判別可能合併型。
@@ -455,6 +505,33 @@ export const addUnit = (unit: PeriodSliderUnit, d: Date, amount: number): Date =
455
505
  return addDays(d, amount)
456
506
  }
457
507
 
508
+ /**
509
+ * Calculates the start boundary of a macro window in micro unit resolution.
510
+ * マクロ窓の開始境界を、ミクロ単位の解像度で算出する関数。
511
+ *
512
+ * The end boundary is expanded to the end of the terminal macro period (getMacroWindowEndDate), so the
513
+ * start must be collapsed to the head of the leading one: otherwise a window whose raw start sits mid
514
+ * period opens a rail that begins somewhere the macro handles never claim.
515
+ * 終了境界は末尾マクロ期間の末日まで広げられる (getMacroWindowEndDate) ため、開始境界も先頭マクロ期間の
516
+ * 先頭へ畳む必要がある。畳まないと、生の開始日が期間の途中にある窓で、マクロつまみが一度も名乗らない
517
+ * 位置からミクロレールが始まる。
518
+ *
519
+ * Normalising by the macro unit and then by the micro unit reproduces, for every unit pair, the mirror
520
+ * image of the end-side case table - including the pairs where the macro unit is the finer of the two.
521
+ * マクロ単位で正規化してからミクロ単位で正規化する形は、マクロ側が細かい組み合わせも含め、
522
+ * 全ての単位の組で終了側の場合分けの鏡像と一致する。
523
+ *
524
+ * @param macroUnit - Macro scale unit / マクロ側の時間解像度単位
525
+ * @param microUnit - Micro scale unit / ミクロ側の時間解像度単位
526
+ * @param d - Macro range start date / マクロ範囲の開始日付
527
+ * @returns Corrected boundary Date in micro unit resolution / 補正後のミクロ解像度開始日付
528
+ * @throws RangeError when d is absent or an Invalid Date / d が未指定または Invalid Date の場合
529
+ */
530
+ export const getMacroWindowStartDate = (macroUnit: PeriodSliderUnit, microUnit: PeriodSliderUnit, d: Date): Date => {
531
+ if (!isValidDate(d)) throw new RangeError(`getMacroWindowStartDate: d must be a valid Date (received: ${describeDateValue(d)})`)
532
+ return normalizeDateByUnit(microUnit, normalizeDateByUnit(macroUnit, d))
533
+ }
534
+
458
535
  /**
459
536
  * Calculates the end boundary of a macro window in micro unit resolution.
460
537
  * When the macro unit is coarser than the micro unit, expands the date to encompass
@@ -488,6 +565,48 @@ export const getMacroWindowEndDate = (macroUnit: PeriodSliderUnit, microUnit: Pe
488
565
  return normalizeDateByUnit(microUnit, d)
489
566
  }
490
567
 
568
+ /**
569
+ * Clamps a date into an inclusive boundary pair, returning the input itself when it already fits.
570
+ * 日付を境界の対の内側へ収める関数 (既に内側なら入力をそのまま返す)。
571
+ *
572
+ * @param date - Date to contain / 収める対象の日付
573
+ * @param min - Lower boundary / 下限
574
+ * @param max - Upper boundary / 上限
575
+ * @returns Date guaranteed to lie within [min, max] / [min, max] の内側であることが保証された日付
576
+ */
577
+ const clampDateInto = (date: Date, min: Date, max: Date): Date => (date < min ? min : date > max ? max : date)
578
+
579
+ /**
580
+ * Resolves the effective micro window: the macro window intersected with [minDate, maxDate].
581
+ * Both boundaries of a macro window are rounded outward to whole macro periods, so on its own the
582
+ * window reaches past the domain whenever minDate or maxDate falls mid period. The rails, the state
583
+ * hooks' containment and the micro selectors must all read the same intersected pair: when one of them
584
+ * uses the raw window instead, it commits a micro date that the component's own domain assertions then
585
+ * reject, and the tree throws during render.
586
+ * 実効ミクロ窓 (マクロ窓と [minDate, maxDate] の交差) を解決する関数。
587
+ * マクロ窓は両端ともマクロ期間の外側へ丸められるため、minDate / maxDate が期間の途中にあると窓単体では
588
+ * 定義域を越える。レール・ステートフックの収め込み・ミクロセレクタが同一の交差結果を共有しないと、
589
+ * 生の窓を見た側が定義域外のミクロ日付を確定させ、本体の定義域表明がそれを弾いて描画中に送出する。
590
+ *
591
+ * @param macroUnit - Macro scale unit / マクロ側の時間解像度単位
592
+ * @param microUnit - Micro scale unit / ミクロ側の時間解像度単位
593
+ * @param macroRange - Current macro window tuple / 現在のマクロ窓タプル
594
+ * @param minDate - Domain lower boundary / 定義域の下限
595
+ * @param maxDate - Domain upper boundary / 定義域の上限
596
+ * @returns Window tuple in micro unit resolution, guaranteed to lie inside [minDate, maxDate] / [minDate, maxDate] の内側であることが保証されたミクロ解像度の窓タプル
597
+ * @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
+ */
599
+ export const resolveMacroWindow = (macroUnit: PeriodSliderUnit, microUnit: PeriodSliderUnit, macroRange: [Date, Date], minDate: Date, maxDate: Date): [Date, Date] => {
600
+ // 公開関数であり、内部の呼び出し元が持つ表明の外からも呼ばれる。自分の引数は自分の名前で拒否する
601
+ assertDateRangeTuple("macroRange", macroRange, "resolveMacroWindow")
602
+ if (!isValidDate(minDate)) throw new RangeError(`resolveMacroWindow: minDate must be a valid Date (received: ${describeDateValue(minDate)})`)
603
+ if (!isValidDate(maxDate)) throw new RangeError(`resolveMacroWindow: maxDate must be a valid Date (received: ${describeDateValue(maxDate)})`)
604
+ if (maxDate.getTime() < minDate.getTime()) throw new RangeError(`resolveMacroWindow: maxDate must not precede minDate (minDate: ${describeDateValue(minDate)}, maxDate: ${describeDateValue(maxDate)})`)
605
+ // クランプの結果は生の minDate / maxDate になり得るため、ミクロ単位へ畳み直す。
606
+ // 畳まないと返り値は「ミクロ解像度」を名乗れず、日付で比較する呼び出し側が符号化で比較する側と食い違う
607
+ return [normalizeDateByUnit(microUnit, clampDateInto(getMacroWindowStartDate(macroUnit, microUnit, macroRange[0]), minDate, maxDate)), normalizeDateByUnit(microUnit, clampDateInto(getMacroWindowEndDate(macroUnit, microUnit, macroRange[1]), minDate, maxDate))]
608
+ }
609
+
491
610
  /**
492
611
  * Intl option set each unit is formatted with once a locale is supplied.
493
612
  * ロケール指定時に各単位を書式化する Intl オプション集合。
@@ -1048,7 +1167,59 @@ const withoutHorizontalPush = (geometry: LabelSlantResult): LabelSlantResult =>
1048
1167
  * Grabbable part of a vernier slider, naming both the rail and the element on it.
1049
1168
  * ノギススライダーで掴める部位 (レールと要素の組)。
1050
1169
  */
1051
- export type VernierHandle = "macro-low" | "macro-high" | "macro-connect" | "micro-low" | "micro-high" | "micro-connect"
1170
+ export type VernierHandle = "macro-low" | "macro-high" | "macro-connect" | "micro-low" | "micro-high" | "micro-connect" | "micro-point"
1171
+
1172
+ /**
1173
+ * What the vernier micro rail selects: a period spanned by two handles, or a point held by one.
1174
+ * ノギスのミクロレールが選ぶ対象 (2 つのつまみが張る期間か、1 つのつまみが指す時点か)。
1175
+ */
1176
+ export type VernierMicroShape = "range" | "point"
1177
+
1178
+ /**
1179
+ * Tells which vernier rail a cross-axis offset falls on.
1180
+ * 直交軸オフセットがノギスのどちらのレールに属するかを判定する関数。
1181
+ *
1182
+ * The track carries two rails separated by its centre line, so the sign of the offset - together with
1183
+ * which rail the macro scale was drawn on - is the whole rule. Every gesture that has to pick a scale
1184
+ * (a press, a wheel) reads it here rather than restating it.
1185
+ * トラックは中心線で分かれた 2 本のレールを載せるため、オフセットの符号とマクロレールの側だけが判定規則の全て。
1186
+ * スケールを選ぶ必要のある操作 (押下・ホイール) は、規則を再掲せず本関数を読む。
1187
+ *
1188
+ * @param pointerCrossAxisOffset - Signed pointer offset from the track center line in pixels / トラック中心線からのポインター直交軸オフセット (ピクセル、符号付き)
1189
+ * @param orientation - Which rail the macro scale is drawn on / マクロスケールを描くレール
1190
+ * @returns Rail the offset belongs to / オフセットが属するレール
1191
+ */
1192
+ export const resolveVernierRailZone = (pointerCrossAxisOffset: number, orientation: "macro-top" | "macro-bottom" | "macro-left" | "macro-right"): "macro" | "micro" => {
1193
+ // orientation に応じて第一レール (上段または左段) がマクロかミクロかを決定
1194
+ const isFirstRailMacro = orientation === "macro-top" || orientation === "macro-left"
1195
+ const isTargetingFirstRail = pointerCrossAxisOffset <= 0
1196
+ return (isFirstRailMacro && isTargetingFirstRail) || !(isFirstRailMacro || isTargetingFirstRail) ? "macro" : "micro"
1197
+ }
1198
+
1199
+ /**
1200
+ * Resolves the signed unit step a wheel gesture asks the rail for.
1201
+ * ホイール操作がレールへ要求する符号付き 1 単位ステップを解決する関数。
1202
+ *
1203
+ * Holding Shift makes some platforms report the gesture on deltaX and others on deltaY, so the dominant
1204
+ * component is read as the primary axis instead of trusting either field.
1205
+ * Shift 押下時に deltaX で報告する環境と deltaY で報告する環境があるため、いずれかを信じず支配的な成分を主軸として読む。
1206
+ *
1207
+ * Screen coordinates grow rightwards and downwards, while the rail grows rightwards when horizontal and
1208
+ * upwards when vertical - so the sign is flipped for a vertical rail. This is the axis, not a preference.
1209
+ * 画面座標は右・下方向へ増えるのに対し、レールは横向きなら右、縦向きなら上へ伸びるため、縦向きだけ符号が反転する。
1210
+ * これは好みではなく軸そのもの。
1211
+ *
1212
+ * @param deltaX - Horizontal wheel delta / ホイールの水平デルタ
1213
+ * @param deltaY - Vertical wheel delta / ホイールの垂直デルタ
1214
+ * @param isVertical - Whether the rail runs along the vertical axis / レールが垂直方向か
1215
+ * @returns +1 toward maxDate, -1 toward minDate, or 0 when the gesture carries no usable delta / maxDate 方向なら +1、minDate 方向なら -1、使えるデルタが無ければ 0
1216
+ */
1217
+ export const resolveWheelStep = (deltaX: number, deltaY: number, isVertical: boolean): number => {
1218
+ const dominant = Math.abs(deltaX) > Math.abs(deltaY) ? deltaX : deltaY
1219
+ if (!Number.isFinite(dominant) || dominant === 0) return 0
1220
+ const isTowardMax = isVertical ? dominant < 0 : dominant > 0
1221
+ return isTowardMax ? 1 : -1
1222
+ }
1052
1223
 
1053
1224
  /**
1054
1225
  * Resolves the target Vernier handle based on pointer primary-axis ratio and cross-axis offset relative to track center.
@@ -1063,6 +1234,7 @@ export type VernierHandle = "macro-low" | "macro-high" | "macro-connect" | "micr
1063
1234
  * @param orientation - Which rail the macro scale is drawn on (default: "macro-top") / マクロスケールを描くレール (既定: "macro-top")
1064
1235
  * @param handleHitSlopRatio - Hit slop around a knob as a 0-1 ratio (default: 0.05) / つまみ周辺の当たり判定余裕 (0-1 比率、既定: 0.05)
1065
1236
  * @param allowConnectHandles - Whether a press inside a band may grab the band itself (default: true) / 帯の内側の押下で帯自体を掴めるか (既定: true)
1237
+ * @param microShape - What the micro rail selects (default: "range") / ミクロレールの選択対象 (既定: "range")
1066
1238
  * @returns Handle the press targets / 押下が対象とするハンドル
1067
1239
  */
1068
1240
  export function resolveVernierTargetHandle(
@@ -1075,12 +1247,10 @@ export function resolveVernierTargetHandle(
1075
1247
  orientation: "macro-top" | "macro-bottom" | "macro-left" | "macro-right" = "macro-top",
1076
1248
  handleHitSlopRatio: number = 0.05,
1077
1249
  allowConnectHandles: boolean = true,
1250
+ microShape: VernierMicroShape = "range",
1078
1251
  ): VernierHandle {
1079
1252
  // orientation に応じて第一レール(上段または左段)がマクロかミクロかを決定
1080
- const isFirstRailMacro = orientation === "macro-top" || orientation === "macro-left"
1081
- const isTargetingFirstRail = pointerCrossAxisOffset <= 0
1082
-
1083
- if ((isFirstRailMacro && isTargetingFirstRail) || !(isFirstRailMacro || isTargetingFirstRail)) {
1253
+ if (resolveVernierRailZone(pointerCrossAxisOffset, orientation) === "macro") {
1084
1254
  // マクロ操作ゾーン
1085
1255
  const distLow = Math.abs(pointerPrimaryRatio - macroLowRatio)
1086
1256
  const distHigh = Math.abs(pointerPrimaryRatio - macroHighRatio)
@@ -1098,6 +1268,11 @@ export function resolveVernierTargetHandle(
1098
1268
  }
1099
1269
 
1100
1270
  // ミクロ操作ゾーン
1271
+ // 時点形態のミクロレールはつまみ 1 つで帯を持たない。掴める相手が 1 つなら選定という段階自体が存在しない
1272
+ if (microShape === "point") {
1273
+ return "micro-point"
1274
+ }
1275
+
1101
1276
  const distLow = Math.abs(pointerPrimaryRatio - microLowRatio)
1102
1277
  const distHigh = Math.abs(pointerPrimaryRatio - microHighRatio)
1103
1278
 
@@ -1150,14 +1325,28 @@ export function calculateVernierMacroDrag(handle: "macro-low" | "macro-high" | "
1150
1325
  * Calculates updated micro selection range when dragging a micro handle or connect bar, supporting crossover swapping.
1151
1326
  * ミクロハンドルまたはコネクトバードラッグ時の新ミクロ範囲を算出します (上限下限反転スワップ対応)。
1152
1327
  *
1153
- * @param handle - Dragged micro handle or connect bar
1328
+ * A point handle carries no width, so it resolves to the bare clamped pointer ratio in both tuple slots:
1329
+ * that is what keeps the degenerate selection degenerate for the whole drag.
1330
+ * 時点つまみは幅を持たないため、両スロットともクランプ済みポインター比率そのものとなり、ドラッグ中ずっと幅ゼロが保たれる。
1331
+ *
1332
+ * @param handle - Dragged micro handle, connect bar or point handle
1154
1333
  * @param pointerRatio - Current pointer ratio across track (0.0 - 1.0)
1155
1334
  * @param startPointerRatio - Initial pointer ratio at drag start
1156
1335
  * @param startMicroLowRatio - Initial micro low ratio at drag start
1157
1336
  * @param startMicroHighRatio - Initial micro high ratio at drag start
1158
1337
  * @returns Tuple of [nextLowRatio, nextHighRatio, activeHandle]
1159
1338
  */
1160
- export function calculateVernierMicroDrag(handle: "micro-low" | "micro-high" | "micro-connect", pointerRatio: number, startPointerRatio: number, startMicroLowRatio: number, startMicroHighRatio: number): [number, number, "micro-low" | "micro-high" | "micro-connect"] {
1339
+ export function calculateVernierMicroDrag(
1340
+ handle: "micro-low" | "micro-high" | "micro-connect" | "micro-point",
1341
+ pointerRatio: number,
1342
+ startPointerRatio: number,
1343
+ startMicroLowRatio: number,
1344
+ startMicroHighRatio: number,
1345
+ ): [number, number, "micro-low" | "micro-high" | "micro-connect" | "micro-point"] {
1346
+ if (handle === "micro-point") {
1347
+ const clamped = Math.max(0, Math.min(1, pointerRatio))
1348
+ return [clamped, clamped, "micro-point"]
1349
+ }
1161
1350
  if (handle === "micro-connect") {
1162
1351
  const delta = pointerRatio - startPointerRatio
1163
1352
  const width = startMicroHighRatio - startMicroLowRatio
@@ -1242,18 +1431,19 @@ const assertDomainBounds = (minDate: Date, maxDate: Date): void => {
1242
1431
  *
1243
1432
  * @param propName - Prop name quoted in the error message / エラーメッセージへ埋め込む Props 名
1244
1433
  * @param value - Raw prop value supplied by the consumer / 利用側が指定した生の Props 値
1434
+ * @param owner - API name the message blames (default: the component) / メッセージが名指しする API 名 (既定: コンポーネント)
1245
1435
  * @returns Nothing; the function only throws or returns normally / 戻り値なし (正常時は無返却)
1246
1436
  * @throws RangeError when the value is not a two-element tuple, holds an Invalid Date, or is inverted / 2 要素タプルでない場合、Invalid Date を含む場合、または開始と終了が逆転している場合
1247
1437
  */
1248
- const assertDateRangeTuple = (propName: string, value: unknown): void => {
1438
+ const assertDateRangeTuple = (propName: string, value: unknown, owner: string = "PeriodSlider"): void => {
1249
1439
  if (!Array.isArray(value) || value.length !== 2) {
1250
- throw new RangeError(`PeriodSlider: ${propName} is required and must be a [start, end] Date tuple (received: ${describeDateValue(value)})`)
1440
+ throw new RangeError(`${owner}: ${propName} is required and must be a [start, end] Date tuple (received: ${describeDateValue(value)})`)
1251
1441
  }
1252
1442
  const [start, end] = value
1253
- if (!isValidDate(start)) throw new RangeError(`PeriodSlider: ${propName}[0] must be a valid Date (received: ${describeDateValue(start)})`)
1254
- if (!isValidDate(end)) throw new RangeError(`PeriodSlider: ${propName}[1] must be a valid Date (received: ${describeDateValue(end)})`)
1443
+ if (!isValidDate(start)) throw new RangeError(`${owner}: ${propName}[0] must be a valid Date (received: ${describeDateValue(start)})`)
1444
+ if (!isValidDate(end)) throw new RangeError(`${owner}: ${propName}[1] must be a valid Date (received: ${describeDateValue(end)})`)
1255
1445
  if (end.getTime() < start.getTime()) {
1256
- throw new RangeError(`PeriodSlider: ${propName} must not be inverted (start: ${describeDateValue(start)}, end: ${describeDateValue(end)})`)
1446
+ throw new RangeError(`${owner}: ${propName} must not be inverted (start: ${describeDateValue(start)}, end: ${describeDateValue(end)})`)
1257
1447
  }
1258
1448
  }
1259
1449
 
@@ -1328,26 +1518,82 @@ const assertSelectionProps = (props: PeriodSliderProps, minDate: Date, maxDate:
1328
1518
  }
1329
1519
 
1330
1520
  /**
1331
- * Validates the mandatory vernier props and resolves the micro selection that seeds the uncontrolled state.
1332
- * ノギスモードの必須 Props を検証し、非制御ステートの初期値となるミクロ選択期間を解決する関数。
1521
+ * Micro selection a vernier slider was rendered with: the shape the props declare, and the tuple geometry reads.
1522
+ * ノギスが描画に用いるミクロ選択 (Props が宣言する形態と、幾何計算が読むタプル)。
1333
1523
  *
1334
- * @param macroRange - Macro window tuple; the micro rail spans exactly this window / マクロ窓タプル (ミクロレールの定義域そのもの)
1335
- * @param microRange - Controlled micro selection tuple, or undefined when uncontrolled / 制御時のミクロ選択タプル (非制御時は undefined)
1336
- * @param defaultMicroRange - Initial micro selection tuple for uncontrolled usage / 非制御時の初期ミクロ選択タプル
1337
- * @returns Validated micro selection tuple / 検証済みのミクロ選択タプル
1338
- * @throws RangeError when macroRange is unusable, or when neither micro selection prop is supplied / macroRange が利用不能な場合、またはミクロ選択 Props がいずれも未指定の場合
1524
+ * A point is carried as a zero-width tuple so that ratios, ticks, projection, window translation and the
1525
+ * stepper stay one implementation instead of two.
1526
+ * 時点は幅ゼロのタプルとして保持することで、比率・目盛・投影・窓平行移動・ステッパーの実装が 2 系統に分かれない。
1339
1527
  */
1340
- const assertVernierRanges = (macroRange: [Date, Date], microRange: [Date, Date] | undefined, defaultMicroRange: [Date, Date] | undefined): [Date, Date] => {
1341
- assertDateRangeTuple("macroRange", macroRange)
1342
- if (microRange !== undefined) {
1343
- assertDateRangeTuple("microRange", microRange)
1344
- return microRange
1528
+ interface VernierMicroSelection {
1529
+ /** Shape the supplied micro props declare / 指定されたミクロ Props が宣言する形態 */
1530
+ shape: VernierMicroShape
1531
+ /** Selection every rail computation reads / 全レール計算が読む選択 */
1532
+ selection: [Date, Date]
1533
+ }
1534
+
1535
+ /**
1536
+ * Validates the mandatory vernier props and resolves which micro shape the caller asked for.
1537
+ * ノギスモードの必須 Props を検証し、利用側が要求したミクロ形態を解決する関数。
1538
+ *
1539
+ * The two micro families are mutually exclusive: supplying both leaves the handle count undetermined, and
1540
+ * silently preferring one of them would leave the callback of the other silent forever.
1541
+ * ミクロ 2 系統は相互排他。両方指定するとつまみ数が決まらず、黙って片方を優先すれば他方のコールバックは永久に鳴らない。
1542
+ *
1543
+ * 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 とは扱いが異なる (レールは窓と定義域の積を取り、マクロ通知はクランプ済みの値を配る)。
1548
+ *
1549
+ * @param props - Raw vernier props the component was rendered with / コンポーネントへ渡された生のノギス Props
1550
+ * @param minDate - Lower domain boundary / 定義域下限
1551
+ * @param maxDate - Upper domain boundary / 定義域上限
1552
+ * @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 系統を同時指定した場合、いずれも未指定の場合、指定されたミクロ選択が定義域外の場合
1554
+ */
1555
+ const resolveVernierMicroSelection = (props: PeriodSliderVernierProps, minDate: Date, maxDate: Date): VernierMicroSelection => {
1556
+ assertDateRangeTuple("macroRange", props.macroRange)
1557
+
1558
+ const hasRangeProps = props.microRange !== undefined || props.defaultMicroRange !== undefined || props.onChangeMicroRange !== undefined
1559
+ const hasPointProps = props.microValue !== undefined || props.defaultMicroValue !== undefined || props.onChangeMicroPoint !== undefined
1560
+
1561
+ if (hasRangeProps && hasPointProps) {
1562
+ throw new RangeError("PeriodSlider: vernier mode takes either a micro range (microRange / defaultMicroRange / onChangeMicroRange) or a micro point (microValue / defaultMicroValue / onChangeMicroPoint), never both")
1345
1563
  }
1346
- if (defaultMicroRange !== undefined) {
1347
- assertDateRangeTuple("defaultMicroRange", defaultMicroRange)
1348
- return defaultMicroRange
1564
+
1565
+ if (hasPointProps) {
1566
+ if (props.microValue !== undefined) {
1567
+ assertSelectionDate("microValue", props.microValue)
1568
+ assertSelectionWithinDomain("microValue", props.microValue, minDate, maxDate)
1569
+ return { shape: "point", selection: [props.microValue, props.microValue] }
1570
+ }
1571
+ if (props.defaultMicroValue !== undefined) {
1572
+ assertSelectionDate("defaultMicroValue", props.defaultMicroValue)
1573
+ assertSelectionWithinDomain("defaultMicroValue", props.defaultMicroValue, minDate, maxDate)
1574
+ return { shape: "point", selection: [props.defaultMicroValue, props.defaultMicroValue] }
1575
+ }
1576
+ throw new RangeError("PeriodSlider: vernier point mode requires a micro selection; supply microValue (controlled) or defaultMicroValue (uncontrolled)")
1577
+ }
1578
+
1579
+ if (props.microRange !== undefined) {
1580
+ assertDateRangeTuple("microRange", props.microRange)
1581
+ assertSelectionWithinDomain("microRange[0]", props.microRange[0], minDate, maxDate)
1582
+ assertSelectionWithinDomain("microRange[1]", props.microRange[1], minDate, maxDate)
1583
+ return { shape: "range", selection: props.microRange }
1349
1584
  }
1350
- throw new RangeError("PeriodSlider: vernier mode requires a micro selection; supply microRange (controlled) or defaultMicroRange (uncontrolled)")
1585
+ if (props.defaultMicroRange !== undefined) {
1586
+ assertDateRangeTuple("defaultMicroRange", props.defaultMicroRange)
1587
+ assertSelectionWithinDomain("defaultMicroRange[0]", props.defaultMicroRange[0], minDate, maxDate)
1588
+ assertSelectionWithinDomain("defaultMicroRange[1]", props.defaultMicroRange[1], minDate, maxDate)
1589
+ return { shape: "range", selection: props.defaultMicroRange }
1590
+ }
1591
+ // 形態を宣言済みの呼び出し側へ他方の形態の救済を示すと、それは型エラーであり、
1592
+ // JavaScript から従えば相互排他の RangeError になる。辿れる救済だけを示す
1593
+ if (hasRangeProps) {
1594
+ throw new RangeError("PeriodSlider: vernier range mode requires a micro selection; supply microRange (controlled) or defaultMicroRange (uncontrolled)")
1595
+ }
1596
+ throw new RangeError("PeriodSlider: vernier mode requires a micro selection; supply microRange / defaultMicroRange for a period, or microValue / defaultMicroValue for a point")
1351
1597
  }
1352
1598
 
1353
1599
  /**
@@ -1619,8 +1865,11 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1619
1865
  // 不正なロケールを黙って ISO 表記へ落とすと、利用側は翻訳が効かない理由に気付けない
1620
1866
  if (locale !== undefined) assertLocaleTag("locale", locale)
1621
1867
 
1622
- // マクロ窓とミクロ選択もノギスの位置計算の根拠そのもの。欠ければ同じくフック前に失敗させる
1623
- const initialVernierMicroRange: [Date, Date] | null = props.mode === "vernier" ? assertVernierRanges(props.macroRange, props.microRange, props.defaultMicroRange) : null
1868
+ // マクロ窓とミクロ選択もノギスの位置計算の根拠そのもの。欠ければ同じくフック前に失敗させる。
1869
+ // 形態はステートへ写さず毎レンダー Props から解決する。写すと利用側が形態を差し替えた瞬間に、
1870
+ // 描かれるつまみ数と鳴るコールバックが食い違う
1871
+ const vernierMicro: VernierMicroSelection | null = props.mode === "vernier" ? resolveVernierMicroSelection(props, minDate, maxDate) : null
1872
+ const isMicroPointShape = vernierMicro !== null && vernierMicro.shape === "point"
1624
1873
 
1625
1874
  const palette = COLOR_SCHEME_PALETTES[colorScheme]
1626
1875
  const vernierGradId = useId()
@@ -1680,11 +1929,32 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1680
1929
  // ------------------------------------------------------------------
1681
1930
  // C. 内部ステートの初期化と同期
1682
1931
  // ------------------------------------------------------------------
1683
- // ノギス非制御時のミクロ選択。初期値は defaultMicroRange、以降は notifyMicroRange が唯一の書き込み経路
1684
- const [uncontrolledMicroRange, setUncontrolledMicroRange] = useState<[Date, Date] | null>(() => initialVernierMicroRange)
1932
+ // ノギス非制御時のミクロ選択。初期値は defaultMicroRange / defaultMicroValue、以降は notifyMicroSelection が唯一の書き込み経路
1933
+ const [uncontrolledMicroRangeState, setUncontrolledMicroRange] = useState<[Date, Date] | null>(() => (vernierMicro === null ? null : vernierMicro.selection))
1934
+
1935
+ // 形態が時点へ入れ替わると、期間として確定していた非制御ステートは幅を持ったまま残る。
1936
+ // 幅ゼロであることが時点形態の全計算 (とりわけステッパーの端判定) の前提なので、
1937
+ // frontVernierHandle と同じくレンダー中に畳み込む (残すのは描かれるつまみが指している下限側)
1938
+ // 初期化子は mount 時にしか走らないため、後から mode を vernier へ切り替えた木ではステートが null のまま残る。
1939
+ // 解決済みのミクロ選択は毎レンダー手に入るので、null はそこへ落とす (落とさないとレール両端まで開いた選択に化ける)
1940
+ let uncontrolledMicroRange = uncontrolledMicroRangeState ?? (vernierMicro === null ? null : vernierMicro.selection)
1941
+ if (isMicroPointShape && uncontrolledMicroRange !== null && uncontrolledMicroRange[0].getTime() !== uncontrolledMicroRange[1].getTime()) {
1942
+ const foldedMicroSelection: [Date, Date] = [uncontrolledMicroRange[0], uncontrolledMicroRange[0]]
1943
+ uncontrolledMicroRange = foldedMicroSelection
1944
+ setUncontrolledMicroRange(foldedMicroSelection)
1945
+ }
1946
+
1947
+ // 制御時の時点は毎レンダー新しいタプルになる。指している時刻が動かない限り同じ参照を返さないと、
1948
+ // これを依存に持つ下流の useMemo が毎レンダー再計算になる
1949
+ const controlledMicroPointMs = props.mode === "vernier" ? props.microValue?.getTime() : undefined
1950
+ const controlledMicroPoint = useMemo<[Date, Date] | null>(() => {
1951
+ if (props.mode !== "vernier" || props.microValue === undefined) return null
1952
+ return [props.microValue, props.microValue]
1953
+ }, [props.mode, controlledMicroPointMs])
1685
1954
 
1686
- // null はノギス以外を意味する。ノギスでは assertVernierRanges が値の存在を保証済み
1687
- const vernierMicroSelection: [Date, Date] | null = props.mode !== "vernier" ? null : props.microRange !== undefined ? props.microRange : uncontrolledMicroRange
1955
+ // null はノギス以外を意味する。ノギスでは resolveVernierMicroSelection が値の存在を保証済み。
1956
+ // 時点形態も同じ幅ゼロタプルで表すため、以降の全計算は形態を意識しない
1957
+ const vernierMicroSelection: [Date, Date] | null = props.mode !== "vernier" ? null : isMicroPointShape ? (controlledMicroPoint ?? uncontrolledMicroRange) : props.microRange !== undefined ? props.microRange : uncontrolledMicroRange
1688
1958
 
1689
1959
  const effectiveLowerDate: Date | undefined = props.mode === "range" ? (props.range?.[0] ?? props.defaultRange?.[0]) : props.mode === "vernier" ? vernierMicroSelection?.[0] : undefined
1690
1960
 
@@ -1706,7 +1976,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1706
1976
  }, [props.mode, propLowerMs, propUpperMs, dateToValue, effectivePointDate, effectiveLowerDate, effectiveUpperDate])
1707
1977
 
1708
1978
  // 非制御 (Uncontrolled) 運用時の自律ステート管理
1709
- const isControlled = props.mode === "point" ? props.value !== undefined : props.mode === "range" ? props.range !== undefined : props.microRange !== undefined
1979
+ const isControlled = props.mode === "point" ? props.value !== undefined : props.mode === "range" ? props.range !== undefined : isMicroPointShape ? props.microValue !== undefined : props.microRange !== undefined
1710
1980
 
1711
1981
  const [uncontrolledValues, setUncontrolledValues] = useState<[number, number]>(() => [initLow, initHigh])
1712
1982
 
@@ -1757,7 +2027,24 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1757
2027
  const [activeVernierHandle, setActiveVernierHandle] = useState<VernierHandle | null>(null)
1758
2028
  const activeVernierHandleRef = useRef<VernierHandle | null>(null)
1759
2029
  activeVernierHandleRef.current = activeVernierHandle
1760
- const [frontVernierHandle, setFrontVernierHandle] = useState<VernierHandle>("micro-high")
2030
+ // 初期前面は実在するつまみでなければならない。時点形態に micro-high は無く、
2031
+ // 描かれないハンドルを初期値にすると最初の 1 回だけ前面が誰も指さない状態になる
2032
+ const [frontVernierHandleState, setFrontVernierHandle] = useState<VernierHandle>(() => (isMicroPointShape ? "micro-point" : "micro-high"))
2033
+
2034
+ // ミクロ形態は実行中に入れ替わり得る。入れ替わった直後の前面は描かれないつまみを指したままになるため、
2035
+ // フックが包含の崩れたステートを畳むのと同じく、レンダー中にその形態へ実在するつまみへ畳み直す
2036
+ let frontVernierHandle = frontVernierHandleState
2037
+ const foldedFrontVernierHandle: VernierHandle | null = isMicroPointShape
2038
+ ? frontVernierHandleState === "micro-low" || frontVernierHandleState === "micro-high" || frontVernierHandleState === "micro-connect"
2039
+ ? "micro-point"
2040
+ : null
2041
+ : frontVernierHandleState === "micro-point"
2042
+ ? "micro-high"
2043
+ : null
2044
+ if (foldedFrontVernierHandle !== null) {
2045
+ frontVernierHandle = foldedFrontVernierHandle
2046
+ setFrontVernierHandle(foldedFrontVernierHandle)
2047
+ }
1761
2048
 
1762
2049
  // マクロ境界 (ノギス以外では読まれないが、定義域そのものなので分岐せず素直に求める)
1763
2050
  const vernierMacroMinEnc = useMemo(() => encode(macroUnit, minDate), [minTime, macroUnit])
@@ -1776,59 +2063,102 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1776
2063
  return getSortedAllowedDates(macroAllowedDates, macroUnit, minDate, maxDate)
1777
2064
  }, [isVernierMode, macroAllowedDates, macroUnit, minTime, maxTime])
1778
2065
 
2066
+ // macroRange は定義域をはみ出してよい窓なので、レールに載る対はここで一度だけ定義域へ畳む。
2067
+ // 生の値のまま使うと aria-valuenow が自分の aria-valuemin/max の外を指し、
2068
+ // 平行移動はみ出した分を戻そうとして操作と逆向きに動く
1779
2069
  const vernierMacroLowEnc = useMemo(() => {
1780
2070
  if (props.mode !== "vernier") return vernierMacroMinEnc
1781
- return encode(macroUnit, props.macroRange[0])
1782
- }, [props.mode, macroRangeStartMs, vernierMacroMinEnc, macroUnit])
2071
+ return Math.max(vernierMacroMinEnc, Math.min(vernierMacroMaxEnc, encode(macroUnit, props.macroRange[0])))
2072
+ }, [props.mode, macroRangeStartMs, vernierMacroMinEnc, vernierMacroMaxEnc, macroUnit])
1783
2073
 
1784
2074
  const vernierMacroHighEnc = useMemo(() => {
1785
2075
  if (props.mode !== "vernier") return vernierMacroMaxEnc
1786
- return encode(macroUnit, props.macroRange[1])
1787
- }, [props.mode, macroRangeEndMs, vernierMacroMaxEnc, macroUnit])
2076
+ return Math.max(vernierMacroMinEnc, Math.min(vernierMacroMaxEnc, encode(macroUnit, props.macroRange[1])))
2077
+ }, [props.mode, macroRangeEndMs, vernierMacroMinEnc, vernierMacroMaxEnc, macroUnit])
1788
2078
 
1789
2079
  // 位置と ARIA は正規化済みエンコード値、表示だけ生 prop という二重の真実を解消する。
1790
2080
  // 同じ値なら表示も一致することが構造的に保証される
1791
2081
  const vernierMacroLowDate = useMemo(() => decode(macroUnit, vernierMacroLowEnc), [macroUnit, vernierMacroLowEnc])
1792
2082
  const vernierMacroHighDate = useMemo(() => decode(macroUnit, vernierMacroHighEnc), [macroUnit, vernierMacroHighEnc])
1793
2083
 
1794
- // ミクロ境界 (マクロ窓がミクロのスケール範囲)。
1795
- // マクロ窓は macroUnit 単位へ丸められるうえ末尾期間全体まで広げられるため、そのままでは定義域の外側まで伸びる。
1796
- // レール自体を [minDate, maxDate] で切り落とさないと、aria-valuemin/max もドラッグ端も定義域外の日付を指す
1797
- const vernierMicroMinEnc = useMemo(() => {
1798
- if (props.mode !== "vernier") return encode(microUnit, minDate)
1799
- return Math.max(encode(microUnit, props.macroRange[0]), encode(microUnit, minDate))
1800
- }, [props.mode, macroRangeStartMs, microUnit, minTime])
1801
-
1802
- const vernierMicroMaxEnc = useMemo(() => {
1803
- if (props.mode !== "vernier") return encode(microUnit, maxDate)
1804
- // マクロ窓が 1 単位に収まる場合、ミクロ側の定義域も同じ 1 単位。広げるとマクロ窓外の日付を選択できてしまう
1805
- return Math.min(encode(microUnit, getMacroWindowEndDate(macroUnit, microUnit, props.macroRange[1])), encode(microUnit, maxDate))
1806
- }, [props.mode, macroRangeEndMs, macroUnit, microUnit, maxTime])
1807
-
1808
- // 候補日付はマクロ窓で切り出す。定義域全体のままではキーボードもポインターも窓の外の日付を発火する。
1809
- // 窓内に候補が 1 つも無い場合は空配列となり、各操作は離散分岐へ入らず窓内の連続値として扱われる
1810
- const sortedMicroAllowedDates = useMemo(() => {
2084
+ // ミクロレールが張る範囲。マクロ窓は macroUnit へ丸められたうえ末尾期間全体まで広げられるため、
2085
+ // 定義域と交差させないと aria-valuemin/max もドラッグ端も定義域外の日付を指す。
2086
+ // 出発点は生の macroRange ではなく、マクロつまみが実際に名乗る対 — 生の値から解決すると、
2087
+ // 窓が定義域の完全に外側にあるときレールと確定経路が別々の窓を見ることになる
2088
+ const vernierMicroWindow = useMemo<[Date, Date]>(() => {
2089
+ if (props.mode !== "vernier") return [minDate, maxDate]
2090
+ return resolveMacroWindow(macroUnit, microUnit, [vernierMacroLowDate, vernierMacroHighDate], minDate, maxDate)
2091
+ }, [props.mode, vernierMacroLowDate, vernierMacroHighDate, macroUnit, microUnit, minTime, maxTime])
2092
+
2093
+ const vernierMicroMinEnc = useMemo(() => encode(microUnit, vernierMicroWindow[0]), [microUnit, vernierMicroWindow])
2094
+
2095
+ // マクロ窓が 1 単位に収まる場合、ミクロ側の定義域も同じ 1 単位。広げるとマクロ窓外の日付を選択できてしまう
2096
+ const vernierMicroMaxEnc = useMemo(() => encode(microUnit, vernierMicroWindow[1]), [microUnit, vernierMicroWindow])
2097
+
2098
+ // 候補は定義域で解決してからマクロ窓で切り出す。窓を境界にして解決すると、候補を 1 つも含まない窓で
2099
+ // getSortedAllowedDates が送出してしまう。窓が動いた先の候補もこの一覧から絞る
2100
+ const sortedMicroDomainDates = useMemo(() => {
1811
2101
  if (!isVernierMode) return []
1812
- const domainDates = getSortedAllowedDates(microAllowedDates, microUnit, minDate, maxDate)
1813
- return domainDates.filter((d) => {
2102
+ return getSortedAllowedDates(microAllowedDates, microUnit, minDate, maxDate)
2103
+ }, [isVernierMode, microAllowedDates, microUnit, minTime, maxTime])
2104
+
2105
+ /**
2106
+ * Narrows the domain-resolved micro candidates to those a given micro window contains.
2107
+ * 定義域で解決済みのミクロ候補を、指定のミクロ窓が含むものだけへ絞り込む関数。
2108
+ *
2109
+ * @param windowMinEnc - Encoded window start / エンコード済み窓開始値
2110
+ * @param windowMaxEnc - Encoded window end / エンコード済み窓終了値
2111
+ * @returns Candidates inside the window, ascending / 窓の内側の候補 (昇順)
2112
+ */
2113
+ const narrowMicroCandidatesToWindow = (windowMinEnc: number, windowMaxEnc: number): Date[] =>
2114
+ sortedMicroDomainDates.filter((d) => {
1814
2115
  const enc = encode(microUnit, d)
1815
- return enc >= vernierMicroMinEnc && enc <= vernierMicroMaxEnc
2116
+ return enc >= windowMinEnc && enc <= windowMaxEnc
1816
2117
  })
1817
- }, [isVernierMode, microAllowedDates, microUnit, minTime, maxTime, vernierMicroMinEnc, vernierMicroMaxEnc])
2118
+
2119
+ // 窓内に候補が 1 つも無い場合は空配列となり、各操作は離散分岐へ入らず窓内の連続値として扱われる
2120
+ const sortedMicroAllowedDates = useMemo(() => narrowMicroCandidatesToWindow(vernierMicroMinEnc, vernierMicroMaxEnc), [sortedMicroDomainDates, microUnit, vernierMicroMinEnc, vernierMicroMaxEnc])
1818
2121
 
1819
2122
  // 離散指定は窓内に候補が 1 つでも残っているときだけ成立する。空配列のままでは窓内の連続値として扱う
1820
2123
  const macroIsDiscreteScale = macroIsDiscrete && sortedMacroAllowedDates.length > 0
1821
2124
  const microIsDiscreteScale = microIsDiscrete && sortedMicroAllowedDates.length > 0
1822
2125
 
2126
+ /**
2127
+ * Resolves the encoded value a micro date takes on the rail as it is currently drawn.
2128
+ * 現在描かれているレール上で、ミクロ日付が取る符号化値を解決する関数。
2129
+ *
2130
+ * A discrete rail draws nothing but its candidate set, so a date that is not a candidate has no
2131
+ * position of its own there and resolves to the nearest one; a continuous rail only clamps into the
2132
+ * window. Position, ARIA, label and every committed value read this one rule, so the rail can never
2133
+ * draw a handle somewhere the published value does not name.
2134
+ * 離散レールは候補集合しか描かないため、候補でない日付はそこに固有の位置を持たず最近傍候補へ解決される。
2135
+ * 連続レールは窓へ収めるだけ。位置・ARIA・ラベル・確定値の全てがこの 1 規則を読むため、
2136
+ * つまみを描く場所と公表する値が食い違わない。
2137
+ *
2138
+ * @param date - Micro date to place / 位置を求めるミクロ日付
2139
+ * @param candidates - Candidates the window contains, ascending (empty for a continuous rail) / 窓が含む候補 (昇順、連続レールでは空)
2140
+ * @param windowMinEnc - Encoded window start / エンコード済み窓開始値
2141
+ * @param windowMaxEnc - Encoded window end / エンコード済み窓終了値
2142
+ * @returns Encoded value on the rail / レール上の符号化値
2143
+ */
2144
+ const resolveMicroRailEnc = (date: Date, candidates: Date[], windowMinEnc: number, windowMaxEnc: number): number =>
2145
+ candidates.length > 0 ? encode(microUnit, candidates[findNearestDateIndex(candidates, date, microUnit)]) : Math.max(windowMinEnc, Math.min(windowMaxEnc, encode(microUnit, date)))
2146
+
2147
+ /** Candidates the current window contains, empty while the micro rail is continuous / 現在の窓が含む候補 (ミクロレールが連続の間は空) */
2148
+ const railMicroCandidates = microIsDiscreteScale ? sortedMicroAllowedDates : []
2149
+
2150
+ // 定義域の内側でもマクロ窓の外側であり得る (制御下の選択は窓が動いた次のレンダーまで遅れる)。
2151
+ // レールへ載せた値を配ることで、aria-valuenow が自分の aria-valuemin/max を外れる状態も、
2152
+ // 離散レールが候補でない日付を読み上げる状態も構造的に消える
1823
2153
  const vernierMicroLowEnc = useMemo(() => {
1824
2154
  if (vernierMicroSelection === null) return vernierMicroMinEnc
1825
- return encode(microUnit, vernierMicroSelection[0])
1826
- }, [microLowMs, vernierMicroMinEnc, microUnit, vernierMicroSelection])
2155
+ return resolveMicroRailEnc(vernierMicroSelection[0], railMicroCandidates, vernierMicroMinEnc, vernierMicroMaxEnc)
2156
+ }, [microLowMs, vernierMicroMinEnc, vernierMicroMaxEnc, microUnit, vernierMicroSelection, railMicroCandidates])
1827
2157
 
1828
2158
  const vernierMicroHighEnc = useMemo(() => {
1829
2159
  if (vernierMicroSelection === null) return vernierMicroMaxEnc
1830
- return encode(microUnit, vernierMicroSelection[1])
1831
- }, [microHighMs, vernierMicroMaxEnc, microUnit, vernierMicroSelection])
2160
+ return resolveMicroRailEnc(vernierMicroSelection[1], railMicroCandidates, vernierMicroMinEnc, vernierMicroMaxEnc)
2161
+ }, [microHighMs, vernierMicroMinEnc, vernierMicroMaxEnc, microUnit, vernierMicroSelection, railMicroCandidates])
1832
2162
 
1833
2163
  // つまみ位置と同じ enc から復元することで、ラベルと描画位置が食い違う余地をなくす
1834
2164
  const vernierMicroLowDate = useMemo(() => decode(microUnit, vernierMicroLowEnc), [microUnit, vernierMicroLowEnc])
@@ -1921,7 +2251,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1921
2251
  const lowDate = valueToDate(nextLow)
1922
2252
  const highDate = valueToDate(nextHigh)
1923
2253
 
1924
- // ノギスモードは値空間 (rangeMin/rangeMax) が別系統のため、この経路ではなく notifyMicroRange / notifyMacroRange を使う
2254
+ // ノギスモードは値空間 (rangeMin/rangeMax) が別系統のため、この経路ではなく notifyMicroSelection / notifyMacroRange を使う
1925
2255
  const doEmit = () => {
1926
2256
  // 予約から発火までの間に利用側が別のハンドラへ差し替えることがある。
1927
2257
  // 予約時点のスナップショットを閉じ込めると、既に捨てられたクロージャだけが呼ばれる
@@ -1967,15 +2297,19 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1967
2297
  )
1968
2298
 
1969
2299
  /**
1970
- * Commits the micro range to the uncontrolled state when needed and emits the canonical callback.
2300
+ * Commits the micro selection to the uncontrolled state when needed and emits the canonical callback.
1971
2301
  * 非制御時はミクロ選択ステートを更新したうえで、正準コールバックを発火する関数。
1972
2302
  *
1973
- * @param lower - New micro range start date / 新しいミクロ範囲の開始日付
1974
- * @param upper - New micro range end date / 新しいミクロ範囲の終了日付
2303
+ * Both micro shapes share this one commit path and the shape decides which callback is canonical, so a
2304
+ * point consumer never receives a period notification and a period consumer never receives a point one.
2305
+ * ミクロ 2 形態はこの唯一の確定経路を共有し、形態が正準コールバックを決めるため、時点の利用側へ期間の通知が届くことはない (逆も同様)。
2306
+ *
2307
+ * @param lower - New micro selection start date / 新しいミクロ選択の開始日付
2308
+ * @param upper - New micro selection end date, equal to lower in point shape / 新しいミクロ選択の終了日付 (時点形態では lower と同値)
1975
2309
  * @param immediate - Bypasses debounceMs and emits at once / debounceMs を迂回して即時発火するか
1976
2310
  * @returns Nothing / 戻り値なし
1977
2311
  */
1978
- const notifyMicroRange = useCallback(
2312
+ const notifyMicroSelection = useCallback(
1979
2313
  (lower: Date, upper: Date, immediate = false) => {
1980
2314
  const p = propsRef.current
1981
2315
  if (p.mode !== "vernier") return
@@ -1983,20 +2317,46 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
1983
2317
  const clampedUpper = clampToDomain(upper)
1984
2318
  // 非制御時はここが唯一の自律更新点。書かなければコールバックだけが鳴り、つまみは初期位置で固まる。
1985
2319
  // デバウンス対象は利用側への通知のみで、つまみ追従までは遅らせない
1986
- if (p.microRange === undefined) {
2320
+ if (isMicroPointShape ? p.microValue === undefined : p.microRange === undefined) {
1987
2321
  setUncontrolledMicroRange([clampedLower, clampedUpper])
1988
2322
  }
1989
2323
  scheduleEmit(
1990
2324
  microEmitRef.current,
1991
2325
  () => {
2326
+ // 予約から発火までの間に利用側がハンドラを差し替えることがあるため、ハンドラは現在の Props から読む。
2327
+ // 形態だけは予約時点のものを使う。報告する値はその形態が生んだ値であり、
2328
+ // 発火直前の差し替えで読み替えると幅ゼロの期間が鳴ってしまう
1992
2329
  const current = propsRef.current
1993
2330
  if (current.mode !== "vernier") return
2331
+ if (isMicroPointShape) {
2332
+ current.onChangeMicroPoint?.(clampedLower)
2333
+ return
2334
+ }
1994
2335
  current.onChangeMicroRange?.(clampedLower, clampedUpper)
1995
2336
  },
1996
2337
  immediate,
1997
2338
  )
1998
2339
  },
1999
- [clampToDomain, scheduleEmit],
2340
+ [clampToDomain, scheduleEmit, isMicroPointShape],
2341
+ )
2342
+
2343
+ /**
2344
+ * Commits a micro point as the zero-width selection every rail computation reads.
2345
+ * ミクロ時点を、全レール計算が読む幅ゼロの選択として確定する関数。
2346
+ *
2347
+ * Point-only paths go through here instead of calling the selection commit directly, so no such path
2348
+ * can open a width by handing it two different dates.
2349
+ * 時点専用の経路は選択確定関数を直接呼ばず本関数を通すため、異なる 2 日付を渡して幅を開くことが構造的に起こらない。
2350
+ *
2351
+ * @param value - New micro point date / 新しいミクロ選択時点
2352
+ * @param immediate - Bypasses debounceMs and emits at once / debounceMs を迂回して即時発火するか
2353
+ * @returns Nothing / 戻り値なし
2354
+ */
2355
+ const notifyMicroPoint = useCallback(
2356
+ (value: Date, immediate = false) => {
2357
+ notifyMicroSelection(value, value, immediate)
2358
+ },
2359
+ [notifyMicroSelection],
2000
2360
  )
2001
2361
 
2002
2362
  // ------------------------------------------------------------------
@@ -2131,12 +2491,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2131
2491
  startMacroHighRatio: number
2132
2492
  startMicroLowRatio: number
2133
2493
  startMicroHighRatio: number
2134
- startMacroLowEnc: number
2135
- startMacroHighEnc: number
2136
- startMicroLowEnc: number
2137
- startMicroHighEnc: number
2138
2494
  startMacroLowDate: Date
2139
- startMacroHighDate: Date
2140
2495
  initialMicroLowDate: Date
2141
2496
  initialMicroHighDate: Date
2142
2497
  } | null>(null)
@@ -2184,13 +2539,19 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2184
2539
  notifyMacroRange(nextMacroLowDate, nextMacroHighDate)
2185
2540
  }
2186
2541
 
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
+
2187
2548
  // 異単位スケール間(例: 月×日)でのパン操作時の日数ズレを防ぐため、マクロ単位の暦月・暦年差分に基づいて平行移動
2188
2549
  let nextMicroLowDate: Date
2189
2550
  let nextMicroHighDate: Date
2190
2551
 
2191
2552
  if (vCtx.handle === "macro-connect") {
2192
- const curMacroLowDate = normalizeDateByUnit(microUnit, nextMacroLowDate)
2193
- const curMacroHighDate = getMacroWindowEndDate(macroUnit, microUnit, nextMacroHighDate)
2553
+ const curMacroLowDate = nextWindowStart
2554
+ const curMacroHighDate = nextWindowEnd
2194
2555
 
2195
2556
  let shiftedLowDate: Date
2196
2557
  let shiftedHighDate: Date
@@ -2228,8 +2589,8 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2228
2589
  } else {
2229
2590
  // マクロ窓境界変更時の弾性復元 (Elastic Range Restoration & Push Clamp)
2230
2591
  // 記憶した初期境界を毎 move 生きた窓へ当て直すことで、窓を再拡張した際に選択が元位置へ戻る (クランプ後の値を確定させると戻らない)
2231
- const minMs = nextMacroLowDate.getTime()
2232
- const maxMs = getMacroWindowEndDate(macroUnit, microUnit, nextMacroHighDate).getTime()
2592
+ const minMs = nextWindowStart.getTime()
2593
+ const maxMs = nextWindowEnd.getTime()
2233
2594
  const targetLowMs = vCtx.initialMicroLowDate.getTime()
2234
2595
  const targetHighMs = vCtx.initialMicroHighDate.getTime()
2235
2596
 
@@ -2240,12 +2601,19 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2240
2601
  nextMicroHighDate = normalizeDateByUnit(microUnit, new Date(clampedHighMs))
2241
2602
  }
2242
2603
 
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
+
2243
2611
  const microKey = `${nextMicroLowDate.getTime()}_${nextMicroHighDate.getTime()}`
2244
2612
  if (microKey !== lastEmittedMicroRangeRef.current) {
2245
2613
  lastEmittedMicroRangeRef.current = microKey
2246
- notifyMicroRange(nextMicroLowDate, nextMicroHighDate)
2614
+ notifyMicroSelection(nextMicroLowDate, nextMicroHighDate)
2247
2615
  }
2248
- } else if (vCtx.handle === "micro-low" || vCtx.handle === "micro-high" || vCtx.handle === "micro-connect") {
2616
+ } else if (vCtx.handle === "micro-low" || vCtx.handle === "micro-high" || vCtx.handle === "micro-connect" || vCtx.handle === "micro-point") {
2249
2617
  const [nextMicroLowRatio, nextMicroHighRatio, activeMicroHandle] = calculateVernierMicroDrag(vCtx.handle, pointerRatio, vCtx.startPointerRatio, vCtx.startMicroLowRatio, vCtx.startMicroHighRatio)
2250
2618
  if (activeMicroHandle !== activeVernierHandleRef.current) {
2251
2619
  activeVernierHandleRef.current = activeMicroHandle
@@ -2261,16 +2629,18 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2261
2629
  nextMicroLowDate = sortedMicroAllowedDates[lowIdx]
2262
2630
  nextMicroHighDate = sortedMicroAllowedDates[highIdx]
2263
2631
  } else {
2264
- const nextMicroLowEnc = Math.round(vernierMicroMinEnc + nextMicroLowRatio * microSpan)
2265
- const nextMicroHighEnc = Math.round(vernierMicroMinEnc + nextMicroHighRatio * microSpan)
2266
- nextMicroLowDate = decode(microUnit, nextMicroLowEnc)
2267
- nextMicroHighDate = decode(microUnit, nextMicroHighEnc)
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)
2268
2638
  }
2269
2639
 
2270
2640
  const microKey = `${nextMicroLowDate.getTime()}_${nextMicroHighDate.getTime()}`
2271
2641
  if (microKey !== lastEmittedMicroRangeRef.current) {
2272
2642
  lastEmittedMicroRangeRef.current = microKey
2273
- notifyMicroRange(nextMicroLowDate, nextMicroHighDate)
2643
+ notifyMicroSelection(nextMicroLowDate, nextMicroHighDate)
2274
2644
  }
2275
2645
  }
2276
2646
  return
@@ -2337,8 +2707,12 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2337
2707
  microUnit,
2338
2708
  macroIsDiscreteScale,
2339
2709
  microIsDiscreteScale,
2710
+ microIsDiscrete,
2711
+ minTime,
2712
+ maxTime,
2340
2713
  sortedMacroAllowedDates,
2341
2714
  sortedMicroAllowedDates,
2715
+ sortedMicroDomainDates,
2342
2716
  vernierMacroMinEnc,
2343
2717
  macroSpan,
2344
2718
  vernierMicroMinEnc,
@@ -2353,7 +2727,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2353
2727
  pctToValue,
2354
2728
  notifyChange,
2355
2729
  notifyMacroRange,
2356
- notifyMicroRange,
2730
+ notifyMicroSelection,
2357
2731
  isPointMode,
2358
2732
  ],
2359
2733
  )
@@ -2445,12 +2819,10 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2445
2819
  startMacroHighRatio: macroHighRatio,
2446
2820
  startMicroLowRatio: microLowRatio,
2447
2821
  startMicroHighRatio: microHighRatio,
2448
- startMacroLowEnc: vernierMacroLowEnc,
2449
- startMacroHighEnc: vernierMacroHighEnc,
2450
- startMicroLowEnc: vernierMicroLowEnc,
2451
- startMicroHighEnc: vernierMicroHighEnc,
2452
- startMacroLowDate: p.macroRange[0],
2453
- startMacroHighDate: p.macroRange[1],
2822
+ // 平行移動量は暦差分で求めるため、基準は表示しているマクロ値 (期間先頭・定義域内) でなければならない。
2823
+ // 生の Props を基準にすると、期間の途中や定義域の外を指す開始日で日差分が半端になり、
2824
+ // 動いていない押下でも丸めで 1 単位ずれる
2825
+ startMacroLowDate: vernierMacroLowDate,
2454
2826
  initialMicroLowDate: vernierMicroLowDate,
2455
2827
  initialMicroHighDate: vernierMicroHighDate,
2456
2828
  }
@@ -2458,7 +2830,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2458
2830
  setActiveVernierHandle(handle)
2459
2831
  setFrontVernierHandle(handle)
2460
2832
  },
2461
- [macroLowRatio, macroHighRatio, microLowRatio, microHighRatio, vernierMacroLowEnc, vernierMacroHighEnc, vernierMicroLowEnc, vernierMicroHighEnc, vernierMicroLowDate, vernierMicroHighDate],
2833
+ [macroLowRatio, macroHighRatio, microLowRatio, microHighRatio, vernierMacroLowDate, vernierMicroLowDate, vernierMicroHighDate],
2462
2834
  )
2463
2835
 
2464
2836
  const handleKnobPointerDown = (handle: "low" | "high") => (e: React.PointerEvent<HTMLDivElement>) => {
@@ -2529,7 +2901,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2529
2901
  if (pointerRatio === null) return
2530
2902
  const pointerCrossAxisOffset = isVertical ? e.clientX - (rect.left + rect.width / 2) : e.clientY - (rect.top + rect.height / 2)
2531
2903
  // 帯を隠したまま帯ドラッグだけ残ると、描かれていない当たり判定が生き続ける
2532
- const targetHandle = resolveVernierTargetHandle(pointerRatio, pointerCrossAxisOffset, macroLowRatio, macroHighRatio, microLowRatio, microHighRatio, vernierOrientation, undefined, !hideConnectBar)
2904
+ const targetHandle = resolveVernierTargetHandle(pointerRatio, pointerCrossAxisOffset, macroLowRatio, macroHighRatio, microLowRatio, microHighRatio, vernierOrientation, undefined, !hideConnectBar, isMicroPointShape ? "point" : "range")
2533
2905
  startVernierDrag(e.pointerId, targetHandle, pointerRatio)
2534
2906
  return
2535
2907
  }
@@ -2595,18 +2967,35 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2595
2967
  * Re-contains the micro selection into a newly resolved macro window and emits it only when it moved.
2596
2968
  * 新しく確定したマクロ窓へミクロ選択を収め直し、実際に動いた場合のみ発火する関数。
2597
2969
  *
2970
+ * Containment is applied to the two tuple slots with the upper one floored at the lower, so a zero-width
2971
+ * point selection stays a point: the shape needs no branch of its own here.
2972
+ * 収め直しは上限を下限で床止めしてタプル 2 枠へ適用するため、幅ゼロの時点選択は時点のまま保たれ、形態別の分岐を持たない。
2973
+ *
2974
+ * A discrete micro rail only draws its candidate set, so the selection is carried to the nearest
2975
+ * candidate of the next window rather than to the window edge; a window holding no candidate at all
2976
+ * is continuous by specification and keeps the plain encoded clamp.
2977
+ * 離散ミクロレールは候補集合しか描かないため、選択は窓端ではなく次の窓の最近傍候補へ運ぶ。
2978
+ * 候補を 1 つも含まない窓は仕様上連続レールとなるため、素のエンコード値クランプのまま。
2979
+ *
2598
2980
  * @param nextMacroLow - Start date of the macro window just resolved / 確定直後のマクロ窓開始日付
2599
2981
  * @param nextMacroHigh - End date of the macro window just resolved / 確定直後のマクロ窓終了日付
2600
2982
  * @returns Nothing / 戻り値なし
2601
2983
  */
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)
2984
+ const containMicroSelectionIntoMacroWindow = (nextMacroLow: Date, nextMacroHigh: Date): void => {
2985
+ if (vernierMicroSelection === null) return
2986
+ // 次のレンダーでミクロレール端はこの窓へ置き換わる。同じ解決器で収め直さないと aria-valuenow が aria-valuemax の外を指し続ける
2987
+ const [nextWindowStart, nextWindowEnd] = resolveMacroWindow(macroUnit, microUnit, [nextMacroLow, nextMacroHigh], minDate, maxDate)
2988
+ const nextMicroMinEnc = encode(microUnit, nextWindowStart)
2989
+ const nextMicroMaxEnc = encode(microUnit, nextWindowEnd)
2990
+ const nextCandidates = microIsDiscrete ? narrowMicroCandidatesToWindow(nextMicroMinEnc, nextMicroMaxEnc) : []
2991
+ // 出発点は利用側が保持している選択そのもの。レールへ載せた表示値から出発すると、新しい窓が選択を
2992
+ // 完全に含む場合でも古い窓の端へ引き戻し、比較の両辺が同じ端になって訂正自体が発火しなくなる
2993
+ const currentLowEnc = encode(microUnit, vernierMicroSelection[0])
2994
+ const currentHighEnc = encode(microUnit, vernierMicroSelection[1])
2995
+ const nextLowEnc = resolveMicroRailEnc(vernierMicroSelection[0], nextCandidates, nextMicroMinEnc, nextMicroMaxEnc)
2996
+ const nextHighEnc = Math.max(nextLowEnc, resolveMicroRailEnc(vernierMicroSelection[1], nextCandidates, nextMicroMinEnc, nextMicroMaxEnc))
2997
+ if (nextLowEnc === currentLowEnc && nextHighEnc === currentHighEnc) return
2998
+ notifyMicroSelection(decode(microUnit, nextLowEnc), decode(microUnit, nextHighEnc), true)
2610
2999
  }
2611
3000
 
2612
3001
  /**
@@ -2620,7 +3009,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2620
3009
  * @param handle - The Vernier handle being manipulated / 操作対象のノギスハンドル
2621
3010
  * @returns Keyboard event handler for the given handle / 指定ハンドル用のキーボードイベントハンドラ
2622
3011
  */
2623
- const handleVernierKeyDown = (handle: "macro-low" | "macro-high" | "micro-low" | "micro-high") => (e: React.KeyboardEvent<HTMLDivElement>) => {
3012
+ const handleVernierKeyDown = (handle: "macro-low" | "macro-high" | "micro-low" | "micro-high" | "micro-point") => (e: React.KeyboardEvent<HTMLDivElement>) => {
2624
3013
  if (disabled || !isVernierMode || props.mode !== "vernier") return
2625
3014
  setFrontVernierHandle(handle)
2626
3015
  let delta = 0
@@ -2662,7 +3051,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2662
3051
  if (nextIdx === findNearestDateIndex(sortedMacroAllowedDates, currentLow, macroUnit)) return
2663
3052
  const nextLow = sortedMacroAllowedDates[nextIdx]
2664
3053
  notifyMacroRange(nextLow, currentHigh, true)
2665
- containMicroRangeIntoMacroWindow(nextLow, currentHigh)
3054
+ containMicroSelectionIntoMacroWindow(nextLow, currentHigh)
2666
3055
  return
2667
3056
  }
2668
3057
  let next: number
@@ -2672,7 +3061,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2672
3061
  if (next === vernierMacroLowEnc) return
2673
3062
  const nextLow = decode(macroUnit, next)
2674
3063
  notifyMacroRange(nextLow, currentHigh, true)
2675
- containMicroRangeIntoMacroWindow(nextLow, currentHigh)
3064
+ containMicroSelectionIntoMacroWindow(nextLow, currentHigh)
2676
3065
  } else if (handle === "macro-high") {
2677
3066
  const currentLow = decode(macroUnit, vernierMacroLowEnc)
2678
3067
  const currentHigh = decode(macroUnit, vernierMacroHighEnc)
@@ -2681,7 +3070,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2681
3070
  if (nextIdx === findNearestDateIndex(sortedMacroAllowedDates, currentHigh, macroUnit)) return
2682
3071
  const nextHigh = sortedMacroAllowedDates[nextIdx]
2683
3072
  notifyMacroRange(currentLow, nextHigh, true)
2684
- containMicroRangeIntoMacroWindow(currentLow, nextHigh)
3073
+ containMicroSelectionIntoMacroWindow(currentLow, nextHigh)
2685
3074
  return
2686
3075
  }
2687
3076
  let next: number
@@ -2691,14 +3080,14 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2691
3080
  if (next === vernierMacroHighEnc) return
2692
3081
  const nextHigh = decode(macroUnit, next)
2693
3082
  notifyMacroRange(currentLow, nextHigh, true)
2694
- containMicroRangeIntoMacroWindow(currentLow, nextHigh)
3083
+ containMicroSelectionIntoMacroWindow(currentLow, nextHigh)
2695
3084
  } else if (handle === "micro-low") {
2696
3085
  const currentLow = decode(microUnit, vernierMicroLowEnc)
2697
3086
  const currentHigh = decode(microUnit, vernierMicroHighEnc)
2698
3087
  if (microIsDiscreteScale) {
2699
3088
  const nextIdx = stepDiscreteIndex(sortedMicroAllowedDates, microUnit, currentLow, sortedMicroAllowedDates[0], currentHigh, delta, isHome, isEnd)
2700
3089
  if (nextIdx === findNearestDateIndex(sortedMicroAllowedDates, currentLow, microUnit)) return
2701
- notifyMicroRange(sortedMicroAllowedDates[nextIdx], currentHigh, true)
3090
+ notifyMicroSelection(sortedMicroAllowedDates[nextIdx], currentHigh, true)
2702
3091
  return
2703
3092
  }
2704
3093
  let next: number
@@ -2706,14 +3095,14 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2706
3095
  else if (isEnd) next = vernierMicroHighEnc
2707
3096
  else next = Math.max(vernierMicroMinEnc, Math.min(vernierMicroHighEnc, vernierMicroLowEnc + delta))
2708
3097
  if (next === vernierMicroLowEnc) return
2709
- notifyMicroRange(decode(microUnit, next), currentHigh, true)
3098
+ notifyMicroSelection(decode(microUnit, next), currentHigh, true)
2710
3099
  } else if (handle === "micro-high") {
2711
3100
  const currentLow = decode(microUnit, vernierMicroLowEnc)
2712
3101
  const currentHigh = decode(microUnit, vernierMicroHighEnc)
2713
3102
  if (microIsDiscreteScale) {
2714
3103
  const nextIdx = stepDiscreteIndex(sortedMicroAllowedDates, microUnit, currentHigh, currentLow, sortedMicroAllowedDates[sortedMicroAllowedDates.length - 1], delta, isHome, isEnd)
2715
3104
  if (nextIdx === findNearestDateIndex(sortedMicroAllowedDates, currentHigh, microUnit)) return
2716
- notifyMicroRange(currentLow, sortedMicroAllowedDates[nextIdx], true)
3105
+ notifyMicroSelection(currentLow, sortedMicroAllowedDates[nextIdx], true)
2717
3106
  return
2718
3107
  }
2719
3108
  let next: number
@@ -2721,10 +3110,79 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2721
3110
  else if (isEnd) next = vernierMicroMaxEnc
2722
3111
  else next = Math.max(vernierMicroLowEnc, Math.min(vernierMicroMaxEnc, vernierMicroHighEnc + delta))
2723
3112
  if (next === vernierMicroHighEnc) return
2724
- notifyMicroRange(currentLow, decode(microUnit, next), true)
3113
+ notifyMicroSelection(currentLow, decode(microUnit, next), true)
3114
+ } else if (handle === "micro-point") {
3115
+ // 時点は対になるつまみに塞がれない。可動域はミクロレールの両端そのもので、Home / End もその両端を指す
3116
+ const current = decode(microUnit, vernierMicroLowEnc)
3117
+ if (microIsDiscreteScale) {
3118
+ const nextIdx = stepDiscreteIndex(sortedMicroAllowedDates, microUnit, current, sortedMicroAllowedDates[0], sortedMicroAllowedDates[sortedMicroAllowedDates.length - 1], delta, isHome, isEnd)
3119
+ if (nextIdx === findNearestDateIndex(sortedMicroAllowedDates, current, microUnit)) return
3120
+ notifyMicroPoint(sortedMicroAllowedDates[nextIdx], true)
3121
+ return
3122
+ }
3123
+ let next: number
3124
+ if (isHome) next = vernierMicroMinEnc
3125
+ else if (isEnd) next = vernierMicroMaxEnc
3126
+ else next = Math.max(vernierMicroMinEnc, Math.min(vernierMicroMaxEnc, vernierMicroLowEnc + delta))
3127
+ if (next === vernierMicroLowEnc) return
3128
+ notifyMicroPoint(decode(microUnit, next), true)
2725
3129
  }
2726
3130
  }
2727
3131
 
3132
+ /**
3133
+ * Shifts the macro window by delta macro units, preserving its width and clamping it to the domain.
3134
+ * マクロ窓を delta マクロ単位だけ幅を保ったまま平行移動し、定義域へクランプする関数。
3135
+ *
3136
+ * The rule is the one the stepper already applies to the micro selection: keep the span, re-anchor at
3137
+ * whichever end the shift would have crossed, and re-contain the micro selection into the new window.
3138
+ * 規則はステッパーがミクロ選択へ既に適用しているものと同一 (幅を保ち、越えた側の端へ寄せ直し、
3139
+ * ミクロ選択を新しい窓へ収め直す)。
3140
+ *
3141
+ * @param delta - Signed number of macro units to move by / 移動するマクロ単位数 (符号付き)
3142
+ * @returns Nothing / 戻り値なし
3143
+ */
3144
+ const shiftMacroWindow = (delta: number): void => {
3145
+ if (props.mode !== "vernier") return
3146
+
3147
+ if (macroIsDiscreteScale) {
3148
+ const maxIdx = sortedMacroAllowedDates.length - 1
3149
+ const curLowIdx = findNearestDateIndex(sortedMacroAllowedDates, vernierMacroLowDate, macroUnit)
3150
+ const curHighIdx = findNearestDateIndex(sortedMacroAllowedDates, vernierMacroHighDate, macroUnit)
3151
+ const idxSpan = curHighIdx - curLowIdx
3152
+ let nextLowIdx = curLowIdx + delta
3153
+ let nextHighIdx = curHighIdx + delta
3154
+ if (delta < 0 && nextLowIdx < 0) {
3155
+ nextLowIdx = 0
3156
+ nextHighIdx = Math.min(maxIdx, idxSpan)
3157
+ } else if (delta > 0 && nextHighIdx > maxIdx) {
3158
+ nextHighIdx = maxIdx
3159
+ nextLowIdx = Math.max(0, maxIdx - idxSpan)
3160
+ }
3161
+ if (nextLowIdx === curLowIdx && nextHighIdx === curHighIdx) return
3162
+ const nextLowDate = sortedMacroAllowedDates[nextLowIdx]
3163
+ const nextHighDate = sortedMacroAllowedDates[nextHighIdx]
3164
+ notifyMacroRange(nextLowDate, nextHighDate, true)
3165
+ containMicroSelectionIntoMacroWindow(nextLowDate, nextHighDate)
3166
+ return
3167
+ }
3168
+
3169
+ const span = vernierMacroHighEnc - vernierMacroLowEnc
3170
+ let nextLow = vernierMacroLowEnc + delta
3171
+ let nextHigh = vernierMacroHighEnc + delta
3172
+ if (delta < 0 && nextLow < vernierMacroMinEnc) {
3173
+ nextLow = vernierMacroMinEnc
3174
+ nextHigh = Math.min(vernierMacroMaxEnc, nextLow + span)
3175
+ } else if (delta > 0 && nextHigh > vernierMacroMaxEnc) {
3176
+ nextHigh = vernierMacroMaxEnc
3177
+ nextLow = Math.max(vernierMacroMinEnc, nextHigh - span)
3178
+ }
3179
+ if (nextLow === vernierMacroLowEnc && nextHigh === vernierMacroHighEnc) return
3180
+ const nextLowDate = decode(macroUnit, nextLow)
3181
+ const nextHighDate = decode(macroUnit, nextHigh)
3182
+ notifyMacroRange(nextLowDate, nextHighDate, true)
3183
+ containMicroSelectionIntoMacroWindow(nextLowDate, nextHighDate)
3184
+ }
3185
+
2728
3186
  const shift = useCallback(
2729
3187
  (delta: number) => {
2730
3188
  const p = propsRef.current
@@ -2753,7 +3211,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2753
3211
  nextLowIdx = Math.max(0, maxIdx - idxSpan)
2754
3212
  }
2755
3213
  if (nextLowIdx !== curLowIdx || nextHighIdx !== curHighIdx) {
2756
- notifyMicroRange(sortedMicroAllowedDates[nextLowIdx], sortedMicroAllowedDates[nextHighIdx], true)
3214
+ notifyMicroSelection(sortedMicroAllowedDates[nextLowIdx], sortedMicroAllowedDates[nextHighIdx], true)
2757
3215
  }
2758
3216
  return
2759
3217
  }
@@ -2772,7 +3230,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2772
3230
  nextLow = Math.max(minEnc, nextHigh - span)
2773
3231
  }
2774
3232
  if (nextLow !== curLowEnc || nextHigh !== curHighEnc) {
2775
- notifyMicroRange(decode(microUnit, nextLow), decode(microUnit, nextHigh), true)
3233
+ notifyMicroSelection(decode(microUnit, nextLow), decode(microUnit, nextHigh), true)
2776
3234
  }
2777
3235
  } else {
2778
3236
  const span = currentHighVal - currentLowVal
@@ -2800,7 +3258,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2800
3258
  rangeMax,
2801
3259
  isControlled,
2802
3260
  notifyChange,
2803
- notifyMicroRange,
3261
+ notifyMicroSelection,
2804
3262
  vernierMicroLowEnc,
2805
3263
  vernierMicroHighEnc,
2806
3264
  vernierMicroMinEnc,
@@ -2813,6 +3271,63 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2813
3271
  ],
2814
3272
  )
2815
3273
 
3274
+ /**
3275
+ * Shifts the scale the pointer is over by one unit when the wheel is turned with Shift held.
3276
+ * Shift 押下中のホイール操作で、ポインターが載っているスケールを 1 単位だけ平行移動するハンドラ。
3277
+ *
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
+ * ページのスクロールを奪うのはレールへ向けられた操作のときだけ。
3282
+ *
3283
+ * In vernier mode the track carries two rails, so the wheel moves the scale under the pointer: the
3284
+ * macro window on the macro rail, the micro selection on the micro rail. Moving the micro selection
3285
+ * while the pointer sits on the macro rail would misreport what the pointer is on.
3286
+ * ノギスではトラックが 2 本のレールを載せるため、ポインターの下のスケールを動かす
3287
+ * (マクロレールならマクロ窓、ミクロレールならミクロ選択)。マクロレール上でミクロ選択が動くのは、
3288
+ * ポインターが何の上に居るかについての嘘になる。
3289
+ *
3290
+ * @param event - Wheel event delivered by the non-passive track listener / 非パッシブなトラックリスナーが受け取るホイールイベント
3291
+ * @returns Nothing / 戻り値なし
3292
+ */
3293
+ const handleTrackWheel = (event: WheelEvent): void => {
3294
+ if (disabled || !event.shiftKey) return
3295
+ const step = resolveWheelStep(event.deltaX, event.deltaY, isVertical)
3296
+ if (step === 0) return
3297
+ event.preventDefault()
3298
+
3299
+ if (!isVernierMode) {
3300
+ shift(step)
3301
+ return
3302
+ }
3303
+
3304
+ const el = trackRef.current
3305
+ if (!el) return
3306
+ const rect = el.getBoundingClientRect()
3307
+ const pointerCrossAxisOffset = isVertical ? event.clientX - (rect.left + rect.width / 2) : event.clientY - (rect.top + rect.height / 2)
3308
+ if (resolveVernierRailZone(pointerCrossAxisOffset, vernierOrientation) === "macro") {
3309
+ shiftMacroWindow(step)
3310
+ return
3311
+ }
3312
+ shift(step)
3313
+ }
3314
+
3315
+ // ハンドラは毎レンダー作り直されるが、リスナーは 1 度だけ張る。ref 経由で最新を呼ぶことで、
3316
+ // 登録し直しによる取りこぼしも、閉じ込めた古い値も起こらない (ポインター移動と同じ手)
3317
+ const handleTrackWheelRef = useRef(handleTrackWheel)
3318
+ handleTrackWheelRef.current = handleTrackWheel
3319
+
3320
+ useEffect(() => {
3321
+ const el = trackRef.current
3322
+ if (!el) return
3323
+
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)
3329
+ }, [])
3330
+
2816
3331
  // ------------------------------------------------------------------
2817
3332
  // I. 表示位置とスタイル計算
2818
3333
  // ------------------------------------------------------------------
@@ -2854,7 +3369,9 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2854
3369
  // 符号化値が一致すればラベルは文字列まで一致する。しかもノギスには押し退けが無く 2 枚が同一矩形へ
2855
3370
  // 完全に重なるため、畳まないと同じ値が二重に読み上げられるだけで視覚的な情報も増えない
2856
3371
  const isVernierMacroLabelMerged = vernierMacroLowEnc === vernierMacroHighEnc
2857
- const isVernierMicroLabelMerged = vernierMicroLowEnc === vernierMicroHighEnc
3372
+ // 時点形態のミクロラベルは 1 枚しか無い。畳み込み判定は恒真になるため、Point モードの !isPointMode と
3373
+ // 同じ理由で形態ごと外す (外さないと唯一のラベルが重複として隠れる)
3374
+ const isVernierMicroLabelMerged = !isMicroPointShape && vernierMicroLowEnc === vernierMicroHighEnc
2858
3375
 
2859
3376
  // 生存者は対の内側だけで決める。frontVernierHandle は 4 つのつまみで 1 本しか無く、相手の対や
2860
3377
  // 連結バーを操作している間は対の両方が非 front になるため、「front でない方を隠す」では両方消える。
@@ -2881,9 +3398,13 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2881
3398
  [macroLowRatio, macroHighRatio, trackLength, macroRailLabelPosition, macroLabelSlantConfig, isVernierMacroLabelMerged, isVernierSlantable],
2882
3399
  )
2883
3400
 
3401
+ // 傾斜は接近した対を離すための機構であり、時点形態には離す相手が居ない。Point モードが
3402
+ // buildHorizontalSlantResult へ落ちるのと同じく、直立のまま置く
3403
+ const isMicroPairSlantable = isVernierSlantable && !isMicroPointShape
3404
+
2884
3405
  const microPairPlacement = useMemo(
2885
- () => solveVernierPairPlacement(microLowRatio, microHighRatio, trackLength, microRailLabelPosition, microLabelSlantConfig, isVernierMicroLabelMerged, isVernierSlantable),
2886
- [microLowRatio, microHighRatio, trackLength, microRailLabelPosition, microLabelSlantConfig, isVernierMicroLabelMerged, isVernierSlantable],
3406
+ () => solveVernierPairPlacement(microLowRatio, microHighRatio, trackLength, microRailLabelPosition, microLabelSlantConfig, isVernierMicroLabelMerged, isMicroPairSlantable),
3407
+ [microLowRatio, microHighRatio, trackLength, microRailLabelPosition, microLabelSlantConfig, isVernierMicroLabelMerged, isMicroPairSlantable],
2887
3408
  )
2888
3409
 
2889
3410
  const lowTooltipStyle: CSSProperties = useMemo(() => {
@@ -2964,6 +3485,9 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2964
3485
  const stepperDecreaseDisabled = disabled || (isVernierMode ? vernierMicroLowEnc <= microStepFloorEnc : isPointMode ? currentLowVal <= rangeMin : currentLowVal <= rangeMin && currentHighVal <= rangeMin)
2965
3486
  const stepperIncreaseDisabled = disabled || (isVernierMode ? vernierMicroHighEnc >= microStepCeilEnc : isPointMode ? currentHighVal >= rangeMax : currentLowVal >= rangeMax && currentHighVal >= rangeMax)
2966
3487
 
3488
+ // ミクロレールの主つまみ。期間形態では下限つまみ、時点形態では唯一の時点つまみが同じ枠に立つ
3489
+ const microPrimaryHandle: "micro-low" | "micro-point" = isMicroPointShape ? "micro-point" : "micro-low"
3490
+
2967
3491
  const cursorClass = disabled ? "cursor-not-allowed opacity-50" : "cursor-pointer"
2968
3492
 
2969
3493
  // ------------------------------------------------------------------
@@ -3061,22 +3585,25 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3061
3585
  }
3062
3586
  onPointerDown={handleVernierKnobPointerDown("macro-connect")}
3063
3587
  />
3064
- <div
3065
- data-testid="period-slider-connect-micro"
3066
- className="period-slider-connect-micro"
3067
- style={
3068
- isVertical
3069
- ? {
3070
- bottom: `calc(${microLowRatio * 100}% - 8px)`,
3071
- height: `calc(${Math.max(0, (microHighRatio - microLowRatio) * 100)}% + 16px)`,
3072
- }
3073
- : {
3074
- left: `calc(${microLowRatio * 100}% - 8px)`,
3075
- width: `calc(${Math.max(0, (microHighRatio - microLowRatio) * 100)}% + 16px)`,
3076
- }
3077
- }
3078
- onPointerDown={handleVernierKnobPointerDown("micro-connect")}
3079
- />
3588
+ {/* 時点形態のミクロ選択には幅が無い。帯を描くと「満タンの期間」に見え、掴める帯まで生えてしまう */}
3589
+ {!isMicroPointShape && (
3590
+ <div
3591
+ data-testid="period-slider-connect-micro"
3592
+ className="period-slider-connect-micro"
3593
+ style={
3594
+ isVertical
3595
+ ? {
3596
+ bottom: `calc(${microLowRatio * 100}% - 8px)`,
3597
+ height: `calc(${Math.max(0, (microHighRatio - microLowRatio) * 100)}% + 16px)`,
3598
+ }
3599
+ : {
3600
+ left: `calc(${microLowRatio * 100}% - 8px)`,
3601
+ width: `calc(${Math.max(0, (microHighRatio - microLowRatio) * 100)}% + 16px)`,
3602
+ }
3603
+ }
3604
+ onPointerDown={handleVernierKnobPointerDown("micro-connect")}
3605
+ />
3606
+ )}
3080
3607
  </>
3081
3608
  )}
3082
3609
 
@@ -3210,14 +3737,14 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3210
3737
  )}
3211
3738
  </div>
3212
3739
 
3213
- {/* ミクロ下限ハンドル (下半円爪 / 右半円爪) */}
3740
+ {/* ミクロ主ハンドル: 期間形態は下限つまみ、時点形態は唯一の時点つまみ (下半円爪 / 右半円爪) */}
3214
3741
  <div
3215
3742
  tabIndex={disabled ? -1 : 0}
3216
3743
  role="slider"
3217
- aria-label={props.lowerAriaLabel ?? "Micro range start"}
3744
+ aria-label={isMicroPointShape ? (props.pointAriaLabel ?? "Micro selected date") : (props.lowerAriaLabel ?? "Micro range start")}
3218
3745
  aria-disabled={disabled ? "true" : undefined}
3219
3746
  aria-valuemin={vernierMicroMinEnc}
3220
- aria-valuemax={vernierMicroHighEnc}
3747
+ aria-valuemax={isMicroPointShape ? vernierMicroMaxEnc : vernierMicroHighEnc}
3221
3748
  aria-valuenow={vernierMicroLowEnc}
3222
3749
  aria-valuetext={props.formatAriaValueText ? props.formatAriaValueText(vernierMicroLowDate, microUnit) : formatScreenReaderLabel(microUnit, vernierMicroLowDate, formatMicroLabel, locale)}
3223
3750
  aria-orientation={isVertical ? "vertical" : "horizontal"}
@@ -3237,23 +3764,23 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3237
3764
  left: isMacroFirstRail ? "auto" : 0,
3238
3765
  right: isMacroFirstRail ? 0 : "auto",
3239
3766
  transform: isMacroFirstRail ? "translate(100%, 50%)" : "translate(-100%, 50%)",
3240
- zIndex: activeVernierHandle === "micro-low" || frontVernierHandle === "micro-low" ? 30 : 20,
3767
+ zIndex: activeVernierHandle === microPrimaryHandle || frontVernierHandle === microPrimaryHandle ? 30 : 20,
3241
3768
  }
3242
3769
  : {
3243
3770
  left: `${microLowRatio * 100}%`,
3244
3771
  top: isMacroFirstRail ? "auto" : 0,
3245
3772
  bottom: isMacroFirstRail ? 0 : "auto",
3246
3773
  transform: isMacroFirstRail ? "translate(-50%, 100%)" : "translate(-50%, -100%)",
3247
- zIndex: activeVernierHandle === "micro-low" || frontVernierHandle === "micro-low" ? 30 : 20,
3774
+ zIndex: activeVernierHandle === microPrimaryHandle || frontVernierHandle === microPrimaryHandle ? 30 : 20,
3248
3775
  }
3249
3776
  }
3250
- onPointerDown={handleVernierKnobPointerDown("micro-low")}
3251
- onKeyDown={handleVernierKeyDown("micro-low")}
3252
- onFocus={handleVernierKnobFocus("micro-low")}
3253
- data-active={activeVernierHandle === "micro-low" ? "true" : undefined}
3254
- data-front={frontVernierHandle === "micro-low" ? "true" : undefined}
3777
+ onPointerDown={handleVernierKnobPointerDown(microPrimaryHandle)}
3778
+ onKeyDown={handleVernierKeyDown(microPrimaryHandle)}
3779
+ onFocus={handleVernierKnobFocus(microPrimaryHandle)}
3780
+ data-active={activeVernierHandle === microPrimaryHandle ? "true" : undefined}
3781
+ data-front={frontVernierHandle === microPrimaryHandle ? "true" : undefined}
3255
3782
  data-vernier-pos={isVertical ? (isMacroFirstRail ? "right" : "left") : isMacroFirstRail ? "bottom" : "top"}
3256
- data-handle-type="micro-low">
3783
+ data-handle-type={microPrimaryHandle}>
3257
3784
  <VernierKnobSvg type="micro" isTop={!isMacroFirstRail} isVertical={isVertical} isLeft={!isMacroFirstRail} />
3258
3785
  {showHairline && <div className="period-slider-hairline" />}
3259
3786
  {tooltipStyle !== "hover" && (
@@ -3269,64 +3796,66 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3269
3796
  )}
3270
3797
  </div>
3271
3798
 
3272
- {/* ミクロ上限ハンドル (下半円爪 / 右半円爪) */}
3273
- <div
3274
- tabIndex={disabled ? -1 : 0}
3275
- role="slider"
3276
- aria-label={props.upperAriaLabel ?? "Micro range end"}
3277
- aria-disabled={disabled ? "true" : undefined}
3278
- aria-valuemin={vernierMicroLowEnc}
3279
- aria-valuemax={vernierMicroMaxEnc}
3280
- aria-valuenow={vernierMicroHighEnc}
3281
- aria-valuetext={props.formatAriaValueText ? props.formatAriaValueText(vernierMicroHighDate, microUnit) : formatScreenReaderLabel(microUnit, vernierMicroHighDate, formatMicroLabel, locale)}
3282
- aria-orientation={isVertical ? "vertical" : "horizontal"}
3283
- className={`period-slider-handle period-slider-handle-vernier ${isVertical ? "is-vertical" : ""} group absolute touch-none ${
3284
- isVertical
3285
- ? isMacroFirstRail
3286
- ? "after:absolute after:-inset-y-3 after:-right-4 after:left-0"
3287
- : "after:absolute after:-inset-y-3 after:right-0 after:-left-4"
3288
- : isMacroFirstRail
3289
- ? "after:absolute after:-inset-x-3 after:top-0 after:-bottom-4"
3290
- : "after:absolute after:-inset-x-3 after:-top-4 after:bottom-0"
3291
- } after:content-[''] focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-offset-2 ${cursorClass}`}
3292
- style={
3293
- isVertical
3294
- ? {
3295
- bottom: `${microHighRatio * 100}%`,
3296
- left: isMacroFirstRail ? "auto" : 0,
3297
- right: isMacroFirstRail ? 0 : "auto",
3298
- transform: isMacroFirstRail ? "translate(100%, 50%)" : "translate(-100%, 50%)",
3299
- zIndex: activeVernierHandle === "micro-high" || frontVernierHandle === "micro-high" ? 30 : 20,
3300
- }
3301
- : {
3302
- left: `${microHighRatio * 100}%`,
3303
- top: isMacroFirstRail ? "auto" : 0,
3304
- bottom: isMacroFirstRail ? 0 : "auto",
3305
- transform: isMacroFirstRail ? "translate(-50%, 100%)" : "translate(-50%, -100%)",
3306
- zIndex: activeVernierHandle === "micro-high" || frontVernierHandle === "micro-high" ? 30 : 20,
3307
- }
3308
- }
3309
- onPointerDown={handleVernierKnobPointerDown("micro-high")}
3310
- onKeyDown={handleVernierKeyDown("micro-high")}
3311
- onFocus={handleVernierKnobFocus("micro-high")}
3312
- data-active={activeVernierHandle === "micro-high" ? "true" : undefined}
3313
- data-front={frontVernierHandle === "micro-high" ? "true" : undefined}
3314
- data-vernier-pos={isVertical ? (isMacroFirstRail ? "right" : "left") : isMacroFirstRail ? "bottom" : "top"}
3315
- data-handle-type="micro-high">
3316
- <VernierKnobSvg type="micro" isTop={!isMacroFirstRail} isVertical={isVertical} isLeft={!isMacroFirstRail} />
3317
- {showHairline && <div className="period-slider-hairline" />}
3318
- {tooltipStyle !== "hover" && (
3319
- <div
3320
- className={`period-slider-tooltip absolute whitespace-nowrap font-medium shadow-md ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
3321
- data-tooltip-style={tooltipStyle}
3322
- data-duplicate={isVernierMicroHighLabelDuplicate ? "true" : undefined}
3323
- data-slanted={microPairPlacement.slant.isSlanted ? "true" : undefined}
3324
- ref={microHighLabelRef}
3325
- style={microPairPlacement.highStyle}>
3326
- {formatLabel(microUnit, vernierMicroHighDate, formatMicroLabel, locale)}
3327
- </div>
3328
- )}
3329
- </div>
3799
+ {/* ミクロ上限ハンドル (下半円爪 / 右半円爪)。時点形態には相方が居ないため描かない */}
3800
+ {!isMicroPointShape && (
3801
+ <div
3802
+ tabIndex={disabled ? -1 : 0}
3803
+ role="slider"
3804
+ aria-label={props.upperAriaLabel ?? "Micro range end"}
3805
+ aria-disabled={disabled ? "true" : undefined}
3806
+ aria-valuemin={vernierMicroLowEnc}
3807
+ aria-valuemax={vernierMicroMaxEnc}
3808
+ aria-valuenow={vernierMicroHighEnc}
3809
+ aria-valuetext={props.formatAriaValueText ? props.formatAriaValueText(vernierMicroHighDate, microUnit) : formatScreenReaderLabel(microUnit, vernierMicroHighDate, formatMicroLabel, locale)}
3810
+ aria-orientation={isVertical ? "vertical" : "horizontal"}
3811
+ className={`period-slider-handle period-slider-handle-vernier ${isVertical ? "is-vertical" : ""} group absolute touch-none ${
3812
+ isVertical
3813
+ ? 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"
3816
+ : 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}`}
3820
+ style={
3821
+ isVertical
3822
+ ? {
3823
+ bottom: `${microHighRatio * 100}%`,
3824
+ left: isMacroFirstRail ? "auto" : 0,
3825
+ right: isMacroFirstRail ? 0 : "auto",
3826
+ transform: isMacroFirstRail ? "translate(100%, 50%)" : "translate(-100%, 50%)",
3827
+ zIndex: activeVernierHandle === "micro-high" || frontVernierHandle === "micro-high" ? 30 : 20,
3828
+ }
3829
+ : {
3830
+ left: `${microHighRatio * 100}%`,
3831
+ top: isMacroFirstRail ? "auto" : 0,
3832
+ bottom: isMacroFirstRail ? 0 : "auto",
3833
+ transform: isMacroFirstRail ? "translate(-50%, 100%)" : "translate(-50%, -100%)",
3834
+ zIndex: activeVernierHandle === "micro-high" || frontVernierHandle === "micro-high" ? 30 : 20,
3835
+ }
3836
+ }
3837
+ onPointerDown={handleVernierKnobPointerDown("micro-high")}
3838
+ onKeyDown={handleVernierKeyDown("micro-high")}
3839
+ onFocus={handleVernierKnobFocus("micro-high")}
3840
+ data-active={activeVernierHandle === "micro-high" ? "true" : undefined}
3841
+ data-front={frontVernierHandle === "micro-high" ? "true" : undefined}
3842
+ data-vernier-pos={isVertical ? (isMacroFirstRail ? "right" : "left") : isMacroFirstRail ? "bottom" : "top"}
3843
+ data-handle-type="micro-high">
3844
+ <VernierKnobSvg type="micro" isTop={!isMacroFirstRail} isVertical={isVertical} isLeft={!isMacroFirstRail} />
3845
+ {showHairline && <div className="period-slider-hairline" />}
3846
+ {tooltipStyle !== "hover" && (
3847
+ <div
3848
+ className={`period-slider-tooltip absolute whitespace-nowrap font-medium shadow-md ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
3849
+ data-tooltip-style={tooltipStyle}
3850
+ data-duplicate={isVernierMicroHighLabelDuplicate ? "true" : undefined}
3851
+ data-slanted={microPairPlacement.slant.isSlanted ? "true" : undefined}
3852
+ ref={microHighLabelRef}
3853
+ style={microPairPlacement.highStyle}>
3854
+ {formatLabel(microUnit, vernierMicroHighDate, formatMicroLabel, locale)}
3855
+ </div>
3856
+ )}
3857
+ </div>
3858
+ )}
3330
3859
  </>
3331
3860
  ) : (
3332
3861
  <>
@@ -3548,6 +4077,9 @@ export const arePeriodSliderPropsEqual = (prev: PeriodSliderProps, next: PeriodS
3548
4077
  if ((prev.microRange?.[1]?.getTime() ?? null) !== (next.microRange?.[1]?.getTime() ?? null)) return false
3549
4078
  if ((prev.defaultMicroRange?.[0]?.getTime() ?? null) !== (next.defaultMicroRange?.[0]?.getTime() ?? null)) return false
3550
4079
  if ((prev.defaultMicroRange?.[1]?.getTime() ?? null) !== (next.defaultMicroRange?.[1]?.getTime() ?? null)) return false
4080
+ // 時点形態の選択も同じ判定を要する。ここを抜くと microValue を動かしても描画が据え置かれる
4081
+ if ((prev.microValue?.getTime() ?? null) !== (next.microValue?.getTime() ?? null)) return false
4082
+ if ((prev.defaultMicroValue?.getTime() ?? null) !== (next.defaultMicroValue?.getTime() ?? null)) return false
3551
4083
  if (prev.macroRange[0].getTime() !== next.macroRange[0].getTime()) return false
3552
4084
  if (prev.macroRange[1].getTime() !== next.macroRange[1].getTime()) return false
3553
4085
 
@@ -3563,6 +4095,7 @@ export const arePeriodSliderPropsEqual = (prev: PeriodSliderProps, next: PeriodS
3563
4095
  prev.formatMacroLabel !== next.formatMacroLabel ||
3564
4096
  prev.formatMicroLabel !== next.formatMicroLabel ||
3565
4097
  prev.onChangeMicroRange !== next.onChangeMicroRange ||
4098
+ prev.onChangeMicroPoint !== next.onChangeMicroPoint ||
3566
4099
  prev.onChangeMacroRange !== next.onChangeMacroRange
3567
4100
  ) {
3568
4101
  return false