@aiquants/period-slider 0.10.0 → 0.10.2

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 +1 @@
1
- {"version":3,"file":"rangeAreaWheel.d.ts","sourceRoot":"","sources":["../src/rangeAreaWheel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,GAAI,WAAW,OAAO,GAAG,IAAI,EAAE,QAAQ,WAAW,GAAG,IAAI,KAAG,OAA8G,CAAA;AAqE1M;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,WAAW,EAAE,QAAQ,WAAW,EAAE,aAAa,MAAM,EAAE,YAAY,OAAO,EAAE,SAAS,MAAM,EAAE,SAAS,MAAM,KAAG,OAgCvJ,CAAA;AAED;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACtC,iGAAiG;IACjG,OAAO,EAAE,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,KAAK,OAAO,CAAA;IAChD,oKAAoK;IACpK,gBAAgB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;IACrE,wHAAwH;IACxH,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;CACpC;AAwDD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iCAAiC,GAAI,MAAM,MAAM,EAAE,aAAa,yBAAyB,KAAG,CAAC,MAAM,IAAI,CAkBnH,CAAA"}
1
+ {"version":3,"file":"rangeAreaWheel.d.ts","sourceRoot":"","sources":["../src/rangeAreaWheel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,GAAI,WAAW,OAAO,GAAG,IAAI,EAAE,QAAQ,WAAW,GAAG,IAAI,KAAG,OAA8G,CAAA;AAyG1M;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,WAAW,EAAE,QAAQ,WAAW,EAAE,aAAa,MAAM,EAAE,YAAY,OAAO,EAAE,SAAS,MAAM,EAAE,SAAS,MAAM,KAAG,OAkCvJ,CAAA;AAED;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACtC,iGAAiG;IACjG,OAAO,EAAE,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,KAAK,OAAO,CAAA;IAChD,oKAAoK;IACpK,gBAAgB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;IACrE,wHAAwH;IACxH,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;CACpC;AA+DD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iCAAiC,GAAI,MAAM,MAAM,EAAE,aAAa,yBAAyB,KAAG,CAAC,MAAM,IAAI,CAkBnH,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiquants/period-slider",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "description": "Customizable period slider and year/month/date selectors for React",
5
5
  "sideEffects": [
6
6
  "**/*.css"
@@ -1693,6 +1693,55 @@ const cancelPendingEmit = (slot: PendingEmitSlot): void => {
1693
1693
  slot.emit = null
1694
1694
  }
1695
1695
 
1696
+ /**
1697
+ * Value one rail displays while a pointer gesture owns it, and the two ways a gesture hands it over.
1698
+ * ポインター操作が持ち主である間、1 本のレールが表示する値と、操作がそれを引き渡す 2 つの口。
1699
+ */
1700
+ interface DragDisplaySlot {
1701
+ /** Selection the live gesture has drawn for this rail, null while the rail displays its owner's selection / 生きている操作がこのレールへ描いた選択 (レールが持ち主の選択を表示している間は null) */
1702
+ shown: [Date, Date] | null
1703
+ /** Draws the selection the gesture resolved for the position it is drawing / 操作が、描いている位置に対して解決した選択を描くメソッド */
1704
+ show: (low: Date, high: Date) => void
1705
+ /** Returns the rail to its owner / レールを持ち主へ返すメソッド */
1706
+ release: () => void
1707
+ }
1708
+
1709
+ /**
1710
+ * Holds one rail's drag-time displayed selection, mirrored in a ref the pointer handler reads at event time.
1711
+ * ドラッグ中に 1 本のレールが表示する選択を保持し、ポインターのハンドラが事象の時点で読む ref へ写すフック。
1712
+ *
1713
+ * The value is rendered, so it has to be state; the mirror is what makes the write decision correct. Two moves can
1714
+ * reach the handler before a commit, and comparing against the render on screen would skip the write exactly when the
1715
+ * pointer walks back onto the value that render still shows - leaving the text on the value the finger just left.
1716
+ * 表示される値であるためステートでなければならないが、書き込みの判定はこの写しが無いと成立しない。
1717
+ * 1 回のコミットの前に移動が 2 件届くことがあり、画面に出ているレンダーと比べると、ポインターが
1718
+ * そのレンダーの値へ戻る移動のときだけ書き込みを飛ばしてしまう (文字が指の去った値に取り残される)。
1719
+ *
1720
+ * @returns Selection currently drawn for the rail, together with the two transfers a gesture performs / レールへいま描かれている選択と、操作が行う 2 つの引き渡し
1721
+ */
1722
+ const useDragDisplaySlot = (): DragDisplaySlot => {
1723
+ const [shown, setShown] = useState<[Date, Date] | null>(null)
1724
+ const shownRef = useRef<[Date, Date] | null>(null)
1725
+
1726
+ const show = useCallback((low: Date, high: Date): void => {
1727
+ const drawn = shownRef.current
1728
+ // 表示値は離散であり、1 目盛りを跨がない移動では動かない。動いていない値を書くと 1 回の移動ごとに再描画が走る
1729
+ if (drawn !== null && drawn[0].getTime() === low.getTime() && drawn[1].getTime() === high.getTime()) return
1730
+ const next: [Date, Date] = [low, high]
1731
+ shownRef.current = next
1732
+ setShown(next)
1733
+ }, [])
1734
+
1735
+ const release = useCallback((): void => {
1736
+ // 一度も描かなかった操作 (動かさなかった押下) は返すものを持たない
1737
+ if (shownRef.current === null) return
1738
+ shownRef.current = null
1739
+ setShown(null)
1740
+ }, [])
1741
+
1742
+ return { shown, show, release }
1743
+ }
1744
+
1696
1745
  /**
1697
1746
  * Validates a BCP 47 language tag prop and fails fast on a tag Intl cannot use.
1698
1747
  * BCP 47 言語タグ Props を検証し、Intl が解釈できないタグで即座に失敗させる関数。
@@ -2313,9 +2362,20 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2313
2362
  return [props.microValue, props.microValue]
2314
2363
  }, [props.mode, controlledMicroPointMs])
2315
2364
 
2316
- // null はノギス以外を意味する。ノギスでは resolveVernierMicroSelection が値の存在を保証済み。
2365
+ // ノギス 2 本のレールが、ポインター操作の生きている間に表示する値。平レールの draggingValues と同じ役割を
2366
+ // 「対になる値を 2 本のレールが持つ」ノギスへ与えたもの。掴んでいないレールは持ち主の値を表示し続ける
2367
+ const macroDragDisplay = useDragDisplaySlot()
2368
+ const microDragDisplay = useDragDisplaySlot()
2369
+
2370
+ // ノギスのミクロ選択のうち、利用側が保持しているもの。null はノギス以外を意味する
2371
+ // (ノギスでは resolveVernierMicroSelection が値の存在を保証済み)。
2317
2372
  // 時点形態も同じ幅ゼロタプルで表すため、以降の全計算は形態を意識しない
2318
- const vernierMicroSelection: [Date, Date] | null = props.mode !== "vernier" ? null : isMicroPointShape ? (controlledMicroPoint ?? uncontrolledMicroRange) : props.microRange !== undefined ? props.microRange : uncontrolledMicroRange
2373
+ const ownedMicroSelection: [Date, Date] | null = props.mode !== "vernier" ? null : isMicroPointShape ? (controlledMicroPoint ?? uncontrolledMicroRange) : props.microRange !== undefined ? props.microRange : uncontrolledMicroRange
2374
+
2375
+ // 表示されるミクロ選択。ポインター操作が生きている間は、その操作が描いている位置が名指す値が持ち主であり、
2376
+ // 指を離した瞬間に利用側の値へ返る。制御下で debounceMs を渡した利用側では、通知が届くまで利用側の値が動かないため、
2377
+ // この 1 段が無いと文字と ARIA だけが操作の間ずっと古い値に留まる
2378
+ const vernierMicroSelection: [Date, Date] | null = ownedMicroSelection === null ? null : (microDragDisplay.shown ?? ownedMicroSelection)
2319
2379
 
2320
2380
  const effectiveLowerDate: Date | undefined = props.mode === "range" ? (props.range?.[0] ?? props.defaultRange?.[0]) : props.mode === "vernier" ? vernierMicroSelection?.[0] : undefined
2321
2381
 
@@ -2378,8 +2438,6 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2378
2438
  const formatMacroLabel = isVernierMode ? ((props as PeriodSliderVernierProps).formatMacroLabel ?? props.formatLabel) : props.formatLabel
2379
2439
  const formatMicroLabel = isVernierMode ? ((props as PeriodSliderVernierProps).formatMicroLabel ?? props.formatLabel) : props.formatLabel
2380
2440
 
2381
- const macroRangeStartMs = props.mode === "vernier" ? props.macroRange[0].getTime() : undefined
2382
- const macroRangeEndMs = props.mode === "vernier" ? props.macroRange[1].getTime() : undefined
2383
2441
  const microLowMs = effectiveLowerDate?.getTime()
2384
2442
  const microHighMs = effectiveUpperDate?.getTime()
2385
2443
 
@@ -2416,23 +2474,31 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2416
2474
  return maxEnc
2417
2475
  }, [isVernierMode, minTime, maxTime, vernierMacroMinEnc, macroUnit])
2418
2476
 
2477
+ // 離散スナップのフラグが降りている間は候補配列そのものを読まない。読むと、離散を求めていない構成が
2478
+ // getSortedAllowedDates の定義域表明 (全要素が定義域の外) で落ち、フラグで正しく塞いでいるフックと
2479
+ // 本体とで、同じ Props に対する挙動が食い違う
2419
2480
  const sortedMacroAllowedDates = useMemo(() => {
2420
- if (!isVernierMode) return []
2481
+ if (!(isVernierMode && macroIsDiscrete)) return []
2421
2482
  return getSortedAllowedDates(macroAllowedDates, macroUnit, minDate, maxDate)
2422
- }, [isVernierMode, macroAllowedDates, macroUnit, minTime, maxTime])
2483
+ }, [isVernierMode, macroIsDiscrete, macroAllowedDates, macroUnit, minTime, maxTime])
2423
2484
 
2424
2485
  // macroRange は定義域をはみ出してよい窓なので、レールに載る対はここで一度だけ定義域へ畳む。
2425
2486
  // 生の値のまま使うと aria-valuenow が自分の aria-valuemin/max の外を指し、
2426
2487
  // 平行移動はみ出した分を戻そうとして操作と逆向きに動く
2427
- const vernierMacroLowEnc = useMemo(() => {
2428
- if (props.mode !== "vernier") return vernierMacroMinEnc
2429
- return Math.max(vernierMacroMinEnc, Math.min(vernierMacroMaxEnc, encode(macroUnit, props.macroRange[0])))
2430
- }, [props.mode, macroRangeStartMs, vernierMacroMinEnc, vernierMacroMaxEnc, macroUnit])
2488
+ /**
2489
+ * Folds one macro window pair into the declared domain and returns it encoded.
2490
+ * マクロ窓の対 1 組を宣言済み定義域へ畳み、符号化して返す関数。
2491
+ *
2492
+ * @param range - Macro window pair to fold / 畳む対象のマクロ窓の対
2493
+ * @returns Encoded [start, end] pair inside the domain / 定義域の内側にある符号化済みの [開始, 終了] の対
2494
+ */
2495
+ const encodeMacroRangeIntoDomain = (range: [Date, Date]): [number, number] => [Math.max(vernierMacroMinEnc, Math.min(vernierMacroMaxEnc, encode(macroUnit, range[0]))), Math.max(vernierMacroMinEnc, Math.min(vernierMacroMaxEnc, encode(macroUnit, range[1])))]
2431
2496
 
2432
- const vernierMacroHighEnc = useMemo(() => {
2433
- if (props.mode !== "vernier") return vernierMacroMaxEnc
2434
- return Math.max(vernierMacroMinEnc, Math.min(vernierMacroMaxEnc, encode(macroUnit, props.macroRange[1])))
2435
- }, [props.mode, macroRangeEndMs, vernierMacroMinEnc, vernierMacroMaxEnc, macroUnit])
2497
+ // 利用側が保持しているマクロ窓 (ノギスでは必須 Props であり常に制御されている)。発火の重複判定はこれを基準にする
2498
+ const [ownedMacroLowEnc, ownedMacroHighEnc] = props.mode !== "vernier" ? [vernierMacroMinEnc, vernierMacroMaxEnc] : encodeMacroRangeIntoDomain(props.macroRange)
2499
+
2500
+ // 表示されるマクロ窓。ミクロ側と同じ規則で、ポインター操作が生きている間はその操作が持ち主
2501
+ const [vernierMacroLowEnc, vernierMacroHighEnc] = macroDragDisplay.shown === null ? [ownedMacroLowEnc, ownedMacroHighEnc] : encodeMacroRangeIntoDomain(macroDragDisplay.shown)
2436
2502
 
2437
2503
  // 位置と ARIA は正規化済みエンコード値、表示だけ生 prop という二重の真実を解消する。
2438
2504
  // 同じ値なら表示も一致することが構造的に保証される
@@ -2456,9 +2522,9 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2456
2522
  // 候補は定義域で解決してからマクロ窓で切り出す。窓を境界にして解決すると、候補を 1 つも含まない窓で
2457
2523
  // getSortedAllowedDates が送出してしまう。窓が動いた先の候補もこの一覧から絞る
2458
2524
  const sortedMicroDomainDates = useMemo(() => {
2459
- if (!isVernierMode) return []
2525
+ if (!(isVernierMode && microIsDiscrete)) return []
2460
2526
  return getSortedAllowedDates(microAllowedDates, microUnit, minDate, maxDate)
2461
- }, [isVernierMode, microAllowedDates, microUnit, minTime, maxTime])
2527
+ }, [isVernierMode, microIsDiscrete, microAllowedDates, microUnit, minTime, maxTime])
2462
2528
 
2463
2529
  /**
2464
2530
  * Narrows the domain-resolved micro candidates to those a given micro window contains.
@@ -2522,10 +2588,10 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
2522
2588
  const vernierMicroLowDate = useMemo(() => decode(microUnit, vernierMicroLowEnc), [microUnit, vernierMicroLowEnc])
2523
2589
  const vernierMicroHighDate = useMemo(() => decode(microUnit, vernierMicroHighEnc), [microUnit, vernierMicroHighEnc])
2524
2590
 
2525
- // 重複発火の判定基準。ミクロ側は利用側が保持している選択そのものを符号化する (レールへ載せた表示値を基準にすると、
2526
- // 窓の外へ出た選択を窓の中へ収め直す訂正が、比較の両辺が同値になって発火しなくなる)
2591
+ // 重複発火の判定基準。両レールとも利用側が保持している選択そのものを符号化する (ドラッグが描いている表示値や
2592
+ // レールへ載せた表示値を基準にすると、窓の外へ出た選択を窓の中へ収め直す訂正が、比較の両辺が同値になって発火しなくなる)
2527
2593
  const committedVernierScales: CommittedVernierScales | null =
2528
- !isVernierMode || vernierMicroSelection === null ? null : { macroUnit, macroLowEnc: vernierMacroLowEnc, macroHighEnc: vernierMacroHighEnc, microUnit, microLowEnc: encode(microUnit, vernierMicroSelection[0]), microHighEnc: encode(microUnit, vernierMicroSelection[1]) }
2594
+ !isVernierMode || ownedMicroSelection === null ? null : { macroUnit, macroLowEnc: ownedMacroLowEnc, macroHighEnc: ownedMacroHighEnc, microUnit, microLowEnc: encode(microUnit, ownedMicroSelection[0]), microHighEnc: encode(microUnit, ownedMicroSelection[1]) }
2529
2595
  const committedVernierRef = useRef(committedVernierScales)
2530
2596
 
2531
2597
  // 比率 (0.0 〜 1.0)。離散レールは当たり判定と同じ候補空間で描かないと、つまみがポインターから離れて飛ぶ
@@ -3125,6 +3191,9 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3125
3191
  nextMacroHighDate = decode(macroUnit, nextHighEnc)
3126
3192
  }
3127
3193
 
3194
+ // 描かれているマクロ窓が名指す値。ラベル・ARIA・ミクロレールの座標系 (窓そのもの) はここから描かれる
3195
+ macroDragDisplay.show(nextMacroLowDate, nextMacroHighDate)
3196
+
3128
3197
  const macroKey = `${nextMacroLowDate.getTime()}_${nextMacroHighDate.getTime()}`
3129
3198
  if (macroKey !== lastEmittedMacroRangeRef.current) {
3130
3199
  lastEmittedMacroRangeRef.current = macroKey
@@ -3200,6 +3269,9 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3200
3269
  nextMicroLowDate = decode(microUnit, emitLowEnc)
3201
3270
  nextMicroHighDate = decode(microUnit, emitHighEnc)
3202
3271
 
3272
+ // 窓が切り出し直したミクロ選択も同じ操作が描いている。発火の重複判定とは別の問いなので、同じ門を通さない
3273
+ microDragDisplay.show(nextMicroLowDate, nextMicroHighDate)
3274
+
3203
3275
  const microKey = `${nextMicroLowDate.getTime()}_${nextMicroHighDate.getTime()}`
3204
3276
  if (microKey !== lastEmittedMicroRangeRef.current) {
3205
3277
  lastEmittedMicroRangeRef.current = microKey
@@ -3230,6 +3302,9 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3230
3302
  nextMicroHighDate = decode(microUnit, highEnc)
3231
3303
  }
3232
3304
 
3305
+ // 描かれているミクロ選択が名指す値
3306
+ microDragDisplay.show(nextMicroLowDate, nextMicroHighDate)
3307
+
3233
3308
  const microKey = `${nextMicroLowDate.getTime()}_${nextMicroHighDate.getTime()}`
3234
3309
  if (microKey !== lastEmittedMicroRangeRef.current) {
3235
3310
  lastEmittedMicroRangeRef.current = microKey
@@ -3303,6 +3378,50 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3303
3378
  }
3304
3379
  }
3305
3380
 
3381
+ /**
3382
+ * Ends the live vernier gesture, committing the position it was interrupted at.
3383
+ * 生きているノギスの操作を終え、中断された位置を確定させる関数。
3384
+ *
3385
+ * @returns Nothing / 戻り値なし
3386
+ */
3387
+ const endVernierGesture = (): void => {
3388
+ endDragPresentation()
3389
+ lastEmittedMacroRangeRef.current = null
3390
+ lastEmittedMicroRangeRef.current = null
3391
+ vernierDragContextRef.current = null
3392
+ activeVernierHandleRef.current = null
3393
+ setActiveVernierHandle(null)
3394
+ // 表示の持ち主を利用側へ返す。発火の掃き出しと同じ React の一括処理へ入るため、値をそのまま返す利用側では
3395
+ // 描画は 1 回で済み、値を畳む・拒む利用側では利用側の値が勝つ
3396
+ macroDragDisplay.release()
3397
+ microDragDisplay.release()
3398
+ // 予約したままドラッグを終えると、指を離した位置の値が発火されずに消える
3399
+ flushPendingEmit(macroEmitRef.current)
3400
+ flushPendingEmit(microEmitRef.current)
3401
+ }
3402
+
3403
+ /**
3404
+ * Ends the live flat-rail gesture, committing the position it was interrupted at.
3405
+ * 生きている平レールの操作を終え、中断された位置を確定させる関数。
3406
+ *
3407
+ * @returns Nothing / 戻り値なし
3408
+ */
3409
+ const endFlatGesture = (): void => {
3410
+ endDragPresentation()
3411
+
3412
+ const finalVals = latestDraggingValuesRef.current ?? draggingValues
3413
+ if (finalVals) {
3414
+ notifyChange(finalVals[0], finalVals[1], true)
3415
+ setUncontrolledValues(finalVals)
3416
+ }
3417
+
3418
+ latestDraggingValuesRef.current = null
3419
+ setDraggingValues(null)
3420
+ dragContextRef.current = null
3421
+ activeHandleRef.current = null
3422
+ setActiveHandle(null)
3423
+ }
3424
+
3306
3425
  /**
3307
3426
  * Ends the gesture that owns the drag, commits its final value and opens the settling window.
3308
3427
  * ドラッグの持ち主である操作を終え、確定値を発火して収め戻しの窓を開くハンドラ。
@@ -3323,45 +3442,46 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3323
3442
  // 別のポインターが離れただけでドラッグを畳むと、指を置いたままのユーザーの手の下で掴みが解け、
3324
3443
  // さらに収め戻しが走って部品が確定位置へ戻る。持ち主の判定は平レールと同じ規則で行う
3325
3444
  if (!vCtx || e.pointerId !== vCtx.pointerId) return
3326
-
3327
- endDragPresentation()
3328
- lastEmittedMacroRangeRef.current = null
3329
- lastEmittedMicroRangeRef.current = null
3330
- vernierDragContextRef.current = null
3331
- activeVernierHandleRef.current = null
3332
- setActiveVernierHandle(null)
3333
- // 予約したままドラッグを終えると、指を離した位置の値が発火されずに消える
3334
- flushPendingEmit(macroEmitRef.current)
3335
- flushPendingEmit(microEmitRef.current)
3445
+ endVernierGesture()
3336
3446
  return
3337
3447
  }
3338
3448
 
3339
3449
  const ctx = dragContextRef.current
3340
3450
  if (!ctx || e.pointerId !== ctx.pointerId) return
3451
+ endFlatGesture()
3452
+ }
3341
3453
 
3342
- endDragPresentation()
3343
-
3344
- const finalVals = latestDraggingValuesRef.current ?? draggingValues
3345
- if (finalVals) {
3346
- notifyChange(finalVals[0], finalVals[1], true)
3347
- setUncontrolledValues(finalVals)
3348
- }
3349
-
3350
- latestDraggingValuesRef.current = null
3351
- setDraggingValues(null)
3352
- dragContextRef.current = null
3353
- activeHandleRef.current = null
3354
- setActiveHandle(null)
3454
+ /**
3455
+ * Ends whichever gesture is live, whether or not the current mode is the one that started it.
3456
+ * いま生きている操作を、それを始めた mode が現在の mode かどうかに関わらず終える関数。
3457
+ *
3458
+ * @returns Nothing / 戻り値なし
3459
+ */
3460
+ const endLiveGesture = (): void => {
3461
+ if (vernierDragContextRef.current !== null) endVernierGesture()
3462
+ if (dragContextRef.current !== null) endFlatGesture()
3355
3463
  }
3356
3464
 
3357
3465
  const handlePointerMoveRef = useRef(handleGlobalPointerMove)
3358
3466
  const handlePointerUpRef = useRef(handleGlobalPointerUp)
3467
+ const endLiveGestureRef = useRef(endLiveGesture)
3359
3468
 
3360
3469
  useLayoutEffect(() => {
3361
3470
  handlePointerMoveRef.current = handleGlobalPointerMove
3362
3471
  handlePointerUpRef.current = handleGlobalPointerUp
3472
+ endLiveGestureRef.current = endLiveGesture
3363
3473
  })
3364
3474
 
3475
+ // 掴んだレールは mode が変わると画面から消える。解放は「いまの mode」の分岐へ入るため、反対側の文脈は
3476
+ // 誰にも消されずに残り、isGestureLive が永久に真になって値を動かせる経路 (2 本目のポインター・ホイール・
3477
+ // 矢印キー・ステッパー) すべてを締め出す。終え方は pointerup / pointercancel と同じ (中断した位置が確定値)
3478
+ const wasVernierModeRef = useRef(isVernierMode)
3479
+ useEffect(() => {
3480
+ if (wasVernierModeRef.current === isVernierMode) return
3481
+ wasVernierModeRef.current = isVernierMode
3482
+ endLiveGestureRef.current()
3483
+ }, [isVernierMode])
3484
+
3365
3485
  const isDragging = activeHandle !== null || activeVernierHandle !== null
3366
3486
 
3367
3487
  useEffect(() => {
@@ -3605,7 +3725,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3605
3725
  * @returns Nothing / 戻り値なし
3606
3726
  */
3607
3727
  const containMicroSelectionIntoMacroWindow = (nextMacroLow: Date, nextMacroHigh: Date): void => {
3608
- if (vernierMicroSelection === null) return
3728
+ if (ownedMicroSelection === null) return
3609
3729
  // 次のレンダーでミクロレール端はこの窓へ置き換わる。同じ解決器で収め直さないと aria-valuenow が aria-valuemax の外を指し続ける
3610
3730
  const [nextWindowStart, nextWindowEnd] = resolveMacroWindow(macroUnit, microUnit, [nextMacroLow, nextMacroHigh], minDate, maxDate)
3611
3731
  const nextMicroMinEnc = encode(microUnit, nextWindowStart)
@@ -3614,8 +3734,8 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3614
3734
  // 出発点は利用側が保持している選択そのもの。レールへ載せた表示値から出発すると、新しい窓が選択を
3615
3735
  // 完全に含む場合でも古い窓の端へ引き戻し、比較の両辺が同じ端になって訂正自体が発火しなくなる。
3616
3736
  // 動いていない選択を鳴らさない判定は notifyMicroSelection が全経路分まとめて持つ
3617
- const nextLowEnc = resolveMicroRailEnc(vernierMicroSelection[0], nextCandidates, nextMicroMinEnc, nextMicroMaxEnc)
3618
- const nextHighEnc = Math.max(nextLowEnc, resolveMicroRailEnc(vernierMicroSelection[1], nextCandidates, nextMicroMinEnc, nextMicroMaxEnc))
3737
+ const nextLowEnc = resolveMicroRailEnc(ownedMicroSelection[0], nextCandidates, nextMicroMinEnc, nextMicroMaxEnc)
3738
+ const nextHighEnc = Math.max(nextLowEnc, resolveMicroRailEnc(ownedMicroSelection[1], nextCandidates, nextMicroMinEnc, nextMicroMaxEnc))
3619
3739
  notifyMicroSelection(decode(microUnit, nextLowEnc), decode(microUnit, nextHighEnc), true)
3620
3740
  }
3621
3741
 
@@ -3986,6 +4106,9 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
3986
4106
  return
3987
4107
  }
3988
4108
 
4109
+ // この番人へ到達し得る操作は無い。持ち主判定の 2 段はどちらもトラックとルートの ref を要求し、
4110
+ // React は削除時にルートの ref を先に外すため、トラックだけが null の瞬間には操作が配送されない。
4111
+ // 取り消しをこの後ろへ動かしても観測できる差は無く、番人は型の絞り込みのためだけに残る
3989
4112
  const el = trackRef.current
3990
4113
  if (!el) return
3991
4114
  const rect = el.getBoundingClientRect()
@@ -4005,17 +4128,36 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
4005
4128
  rangeAreaWheelRef.current = { ownsWheelHit, distanceToRailPx, stepFromRangeAreaWheel }
4006
4129
  })
4007
4130
 
4131
+ const wheelRegistrationRef = useRef<{ view: Window; unregister: () => void } | null>(null)
4132
+
4133
+ // 事象を配送するのは、このスライダーが「いま」描かれている文書の window。モジュールの window へ登録すると
4134
+ // 操作は 1 度も届かず、マウント時の window へ 1 度だけ登録すると、後から別文書へ移されたスライダーは
4135
+ // 去った window へ残り続ける (新しい文書では操作を受け取らず、去った文書では新しい文書の座標で
4136
+ // 持ち主争いに加わり、そこに見えているものからホイールを奪う)。宛先の変化はコミットのたびに読み直す
4008
4137
  useEffect(() => {
4009
- // 事象を配送するのは、このスライダーが描かれている文書の window。別文書へポータルされたスライダーが
4010
- // モジュールの window へ登録すると、操作は 1 度も届かない
4011
- const view = rootRef.current?.ownerDocument.defaultView
4012
- if (!view) return
4013
- return registerRangeAreaWheelParticipant(view, {
4138
+ const view = rootRef.current?.ownerDocument.defaultView ?? null
4139
+ const registration = wheelRegistrationRef.current
4140
+ if (registration !== null && registration.view === view) return
4141
+ registration?.unregister()
4142
+ if (view === null) {
4143
+ wheelRegistrationRef.current = null
4144
+ return
4145
+ }
4146
+ const unregister = registerRangeAreaWheelParticipant(view, {
4014
4147
  ownsHit: (target) => rangeAreaWheelRef.current.ownsWheelHit(target),
4015
4148
  distanceToRailPx: (clientX, clientY) => rangeAreaWheelRef.current.distanceToRailPx(clientX, clientY),
4016
4149
  step: (event) => rangeAreaWheelRef.current.stepFromRangeAreaWheel(event),
4017
4150
  })
4018
- }, [])
4151
+ wheelRegistrationRef.current = { view, unregister }
4152
+ })
4153
+
4154
+ useEffect(
4155
+ () => () => {
4156
+ wheelRegistrationRef.current?.unregister()
4157
+ wheelRegistrationRef.current = null
4158
+ },
4159
+ [],
4160
+ )
4019
4161
 
4020
4162
  // ------------------------------------------------------------------
4021
4163
  // I. 表示位置とスタイル計算
@@ -76,6 +76,41 @@ const CONTAINING_BLOCK_WILL_CHANGE_VALUES = ["transform", "perspective", "filter
76
76
  */
77
77
  const isDeclared = (value: string | undefined): boolean => value !== undefined && value !== "" && value !== "none"
78
78
 
79
+ /**
80
+ * Tells whether an element declares a query container, which carries layout containment.
81
+ * 要素がクエリコンテナを宣言しているか (レイアウトの封じ込めを伴う) を返す関数。
82
+ *
83
+ * `container-type` is the one containing-block creator whose absent state is a named value rather than `none`: the
84
+ * initial computed value is `normal`, so `isDeclared` would answer true for every element that never opted in. Any
85
+ * other value applies layout containment, and layout containment makes the element the containing block of its
86
+ * absolutely and fixed positioned descendants.
87
+ * `container-type` は、不在の状態が `none` ではなく名前付きの値になる唯一の包含ブロック生成子
88
+ * (算出の初期値が `normal` であるため、`isDeclared` では一度も宣言していない要素すべてに真を返してしまう)。
89
+ * それ以外の値はレイアウトの封じ込めを適用し、封じ込めは絶対・固定配置の子孫にとっての包含ブロックを作る。
90
+ *
91
+ * @param value - Computed `container-type` of the element / 要素の算出 `container-type`
92
+ * @returns Whether the element is a query container / その要素がクエリコンテナか
93
+ */
94
+ const isQueryContainer = (value: string | undefined): boolean => value !== undefined && value !== "" && value !== "normal"
95
+
96
+ /**
97
+ * Resolves one border width in pixels from its computed value.
98
+ * 算出値からボーダー幅 1 辺をピクセルで解決する関数。
99
+ *
100
+ * `overflow` and paint containment clip at the padding box, so the border of a clipping ancestor is not a place its
101
+ * descendants are painted. A computed style that carries only declared properties reports an unset border as the
102
+ * empty string, which is a border of zero width rather than an unknown one.
103
+ * `overflow` と描画の封じ込めはパディングボックスで切り取るため、切り取る祖先のボーダーの上は子孫が描かれる場所ではない。
104
+ * 宣言済みプロパティしか持たない算出スタイルは、設定していないボーダーを空文字列で返す (幅 0 のボーダーであって、不明ではない)。
105
+ *
106
+ * @param value - Computed border width of one edge / 1 辺の算出ボーダー幅
107
+ * @returns Width in pixels / 幅 (ピクセル)
108
+ */
109
+ const borderWidthPx = (value: string | undefined): number => {
110
+ const px = Number.parseFloat(value ?? "")
111
+ return Number.isFinite(px) ? px : 0
112
+ }
113
+
79
114
  /**
80
115
  * How a box escapes the normal flow, which decides which ancestors can clip it.
81
116
  * 箱が通常フローから外れている度合い (どの祖先がそれを切り取れるかを決める)。
@@ -111,6 +146,7 @@ const outOfFlowKindOf = (style: CSSStyleDeclaration): OutOfFlowKind => (style.po
111
146
  const establishesContainingBlock = (style: CSSStyleDeclaration, kind: Exclude<OutOfFlowKind, null>): boolean => {
112
147
  if (kind === "absolute" && isDeclared(style.position) && style.position !== "static") return true
113
148
  if (isDeclared(style.transform) || isDeclared(style.perspective) || isDeclared(style.filter) || isDeclared(style.backdropFilter)) return true
149
+ if (isQueryContainer(style.containerType)) return true
114
150
  if (CONTAINING_BLOCK_CONTAIN_VALUES.some((value) => style.contain.includes(value))) return true
115
151
  return CONTAINING_BLOCK_WILL_CHANGE_VALUES.some((value) => style.willChange.includes(value))
116
152
  }
@@ -171,10 +207,12 @@ export const ownsPaintedPoint = (areaEl: HTMLElement, rootEl: HTMLElement, mainR
171
207
  const clipsY = CLIPPING_OVERFLOWS.has(style.overflowY) || PAINT_CONTAINING_VALUES.some((value) => style.contain.includes(value))
172
208
  if (clipsX || clipsY) {
173
209
  // 切り取る祖先の中では、はみ出した部分は描かれない。矩形は残るため、切り取りを見ないと畳まれたスライダーが
174
- // その場所に見えているホストの要素からホイールを奪う
210
+ // その場所に見えているホストの要素からホイールを奪う。
211
+ // 切り取り線はボーダーボックスではなくパディングボックス。縁を持つ祖先でボーダーボックスを使うと、
212
+ // ボーダーが描かれている帯 (子孫は 1 画素も出られない) までスライダーが自分の点として主張する
175
213
  const clip = ancestor.getBoundingClientRect()
176
- if (clipsX && (clientX < clip.left || clientX >= clip.right)) return false
177
- if (clipsY && (clientY < clip.top || clientY >= clip.bottom)) return false
214
+ if (clipsX && (clientX < clip.left + borderWidthPx(style.borderLeftWidth) || clientX >= clip.right - borderWidthPx(style.borderRightWidth))) return false
215
+ if (clipsY && (clientY < clip.top + borderWidthPx(style.borderTopWidth) || clientY >= clip.bottom - borderWidthPx(style.borderBottomWidth))) return false
178
216
  }
179
217
  escaping = outOfFlowKindOf(style)
180
218
  }
@@ -195,11 +233,18 @@ export interface RangeAreaWheelParticipant {
195
233
  }
196
234
 
197
235
  /**
198
- * Sliders of one window, in mount order, together with the listener installed for them.
199
- * 1 つの window に属するスライダー (マウント順) と、そのために張ったリスナー。
236
+ * Sliders of one window, in registration order, together with the listener installed for them.
237
+ * 1 つの window に属するスライダー (登録順) と、そのために張ったリスナー。
238
+ *
239
+ * Registration order is the mount order of the sliders that stayed in the document they were mounted in; a slider
240
+ * moved into another document unregisters from the window it left and joins the end of the new one. The set is never
241
+ * reordered, so the tie-break the listener applies is stable for as long as nobody moves a slider between documents.
242
+ * 登録順は、マウントした文書に留まったスライダーについてはマウント順そのもの。別文書へ移されたスライダーは
243
+ * 去った window から登録を外し、新しい window の末尾へ加わる。集合を並べ替えることはないため、
244
+ * リスナーが使う同着処理は、文書をまたいでスライダーを移さない限り安定している。
200
245
  */
201
246
  interface RangeAreaWheelRegistry {
202
- /** Sliders the listener asks, in mount order / リスナーが順に問うスライダー (マウント順) */
247
+ /** Sliders the listener asks, in registration order / リスナーが順に問うスライダー (登録順) */
203
248
  participants: Set<RangeAreaWheelParticipant>
204
249
  /** Listener installed on that window / その window へ張ったリスナー */
205
250
  listener: (event: WheelEvent) => void