@aiquants/period-slider 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -7
- package/dist/PeriodSlider.d.ts +1 -1
- package/dist/PeriodSlider.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1065 -1018
- package/dist/styles/period-slider.css +1 -1
- package/dist/styles/period-slider.standalone.css +1 -1
- package/package.json +1 -1
- package/src/PeriodSlider.tsx +236 -20
- package/src/styles/period-slider.css +31 -19
package/src/PeriodSlider.tsx
CHANGED
|
@@ -210,7 +210,7 @@ export interface BasePeriodSliderProps extends AccessibleSliderLabels {
|
|
|
210
210
|
tooltipStyle?: "always" | "hover" | "balloon"
|
|
211
211
|
/** Label position: "top" (default) or "bottom" / ラベル表示位置("top": 上側 [既定], "bottom": 下側) */
|
|
212
212
|
labelPosition?: PeriodSliderLabelPosition
|
|
213
|
-
/** Whether to automatically slant labels when close in range mode (default: true) / Range
|
|
213
|
+
/** Whether to automatically slant labels when a pair comes close, in range mode and on both vernier rails (default: true) / Range モードとノギスの両レールで、対が接近した時に自動斜め表示するか (既定: true) */
|
|
214
214
|
autoSlantLabels?: boolean
|
|
215
215
|
/** Renders the slider along the vertical axis (default: false) / 垂直方向レイアウト (既定: false) */
|
|
216
216
|
isVertical?: boolean
|
|
@@ -1029,6 +1029,21 @@ export const calculateLabelSlant = (lowPct: number, highPct: number, trackWidthP
|
|
|
1029
1029
|
}
|
|
1030
1030
|
}
|
|
1031
1031
|
|
|
1032
|
+
/**
|
|
1033
|
+
* Drops the push-apart of a label pair that shows only one label, keeping rotation and clearance.
|
|
1034
|
+
* ラベルが 1 枚しか見えていない対から押し退けだけを取り除き、回転とクリアランスは保持する関数。
|
|
1035
|
+
*
|
|
1036
|
+
* `calculateLabelSlant` is right to separate two labels that sit at distance 0, because both of them
|
|
1037
|
+
* are normally shown. A merged pair is the one case where they are not, and the caller — never the
|
|
1038
|
+
* pure function — knows it.
|
|
1039
|
+
* 距離 0 の 2 ラベルを押し退ける `calculateLabelSlant` の挙動は、2 枚とも表示される通常時には正しい。
|
|
1040
|
+
* 畳んだ対だけが例外であり、それを知るのは純粋関数ではなく呼び出し側。
|
|
1041
|
+
*
|
|
1042
|
+
* @param geometry - Slant geometry solved for the pair / 対に対して解決した傾斜幾何
|
|
1043
|
+
* @returns Same geometry with both horizontal offsets zeroed / 水平オフセットのみ 0 にした同一幾何
|
|
1044
|
+
*/
|
|
1045
|
+
const withoutHorizontalPush = (geometry: LabelSlantResult): LabelSlantResult => ({ ...geometry, lowOffsetX: 0, highOffsetX: 0 })
|
|
1046
|
+
|
|
1032
1047
|
/**
|
|
1033
1048
|
* Grabbable part of a vernier slider, naming both the rail and the element on it.
|
|
1034
1049
|
* ノギススライダーで掴める部位 (レールと要素の組)。
|
|
@@ -1463,6 +1478,97 @@ const useMeasuredBorderBox = (): [(element: HTMLElement | null) => void, Measure
|
|
|
1463
1478
|
return [measureRef, box]
|
|
1464
1479
|
}
|
|
1465
1480
|
|
|
1481
|
+
/**
|
|
1482
|
+
* Builds the slant geometry config of one label pair out of the two measured boxes.
|
|
1483
|
+
* 実測済みの 2 ボックスから 1 対分の傾斜幾何設定を構築する関数。
|
|
1484
|
+
*
|
|
1485
|
+
* Collision avoidance is decided by the real size of both labels: with only one of them measured the
|
|
1486
|
+
* wider one is unknown, so the push-apart would be wrong and the slanted label would cut into the
|
|
1487
|
+
* track. An unmeasured pair therefore means "no size", never an invented default.
|
|
1488
|
+
* 衝突回避は 2 枚の実寸で決まる。片方だけでは広い方が分からず押し出し量を誤ってトラックへ食い込ませる
|
|
1489
|
+
* ため、片方でも未実測なら既定値を捏造せず「寸法なし」として扱う。
|
|
1490
|
+
*
|
|
1491
|
+
* @param lowBox - Measured box of the low label, or null while unmeasured / 下限ラベルの実測ボックス (未実測時は null)
|
|
1492
|
+
* @param highBox - Measured box of the high label, or null while unmeasured / 上限ラベルの実測ボックス (未実測時は null)
|
|
1493
|
+
* @returns Config built from the larger of the pair, or undefined while either box is missing / 対の大きい方から構築した設定 (片方でも欠ければ undefined)
|
|
1494
|
+
*/
|
|
1495
|
+
const buildPairSlantConfig = (lowBox: MeasuredBoxPx | null, highBox: MeasuredBoxPx | null): LabelSlantConfig | undefined => {
|
|
1496
|
+
if (lowBox === null || highBox === null) return undefined
|
|
1497
|
+
return { estimatedWidthPx: Math.max(lowBox.widthPx, highBox.widthPx), estimatedHeightPx: Math.max(lowBox.heightPx, highBox.heightPx) }
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
/**
|
|
1501
|
+
* Placement one vernier label pair resolved, as geometry plus the inline style of each label.
|
|
1502
|
+
* ノギスの 1 対が解決した配置 (幾何と各ラベルのインラインスタイル)。
|
|
1503
|
+
*/
|
|
1504
|
+
interface VernierPairPlacement {
|
|
1505
|
+
/** Geometry solved for the pair / 対に対して解決した傾斜幾何 */
|
|
1506
|
+
slant: LabelSlantResult
|
|
1507
|
+
/** Inline placement of the low label, or undefined to keep the rail baseline / 下限ラベルのインライン配置 (undefined はレール基準配置のまま) */
|
|
1508
|
+
lowStyle: CSSProperties | undefined
|
|
1509
|
+
/** Inline placement of the high label, or undefined to keep the rail baseline / 上限ラベルのインライン配置 (undefined はレール基準配置のまま) */
|
|
1510
|
+
highStyle: CSSProperties | undefined
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
/**
|
|
1514
|
+
* Expresses one vernier label placement as a delta from the upright baseline of its own rail.
|
|
1515
|
+
* ノギスのラベル 1 枚の配置を、自レールの直立基準からの差分として表現する関数。
|
|
1516
|
+
*
|
|
1517
|
+
* @param offsetX - Horizontal push in pixels / 水平押し出し量 (ピクセル)
|
|
1518
|
+
* @param offsetYDelta - Extra vertical push the rotation adds, in pixels / 回転により増える垂直押し出し量 (ピクセル)
|
|
1519
|
+
* @param angleDeg - Rotation in degrees / 回転角 (度)
|
|
1520
|
+
* @returns Custom properties the stylesheet substitutes into the tooltip transform / スタイルシートがツールチップの transform へ代入するカスタムプロパティ
|
|
1521
|
+
*/
|
|
1522
|
+
const buildVernierTooltipStyle = (offsetX: number, offsetYDelta: number, angleDeg: number): CSSProperties =>
|
|
1523
|
+
({
|
|
1524
|
+
"--ps-tooltip-tx": `calc(-50% + ${offsetX}px)`,
|
|
1525
|
+
"--ps-tooltip-ty": `${offsetYDelta}px`,
|
|
1526
|
+
"--ps-tooltip-rot": `${angleDeg}deg`,
|
|
1527
|
+
}) as CSSProperties
|
|
1528
|
+
|
|
1529
|
+
/**
|
|
1530
|
+
* Solves the anti-collision placement of one vernier label pair.
|
|
1531
|
+
* ノギスの 1 対分について、ラベル衝突回避の配置を解決する関数。
|
|
1532
|
+
*
|
|
1533
|
+
* The rail stylesheet already stands an upright label off its own knob (`top` / `bottom: calc(100% + 8px)`
|
|
1534
|
+
* with `--ps-tooltip-ty: 0px`), so only the extra push the rotation adds belongs inline. Taking that
|
|
1535
|
+
* extra as the difference against the upright baseline of the same label size cancels the clearance
|
|
1536
|
+
* constant, which is why this never has to know the rail gap.
|
|
1537
|
+
* レール側 CSS は直立ラベルを既につまみから離して置いているため、インラインで与えるべきは回転で増える
|
|
1538
|
+
* 分だけ。同寸法の直立基準との差を取ると離隔定数が相殺されるので、この関数はレールの隙間量を知らなくてよい。
|
|
1539
|
+
*
|
|
1540
|
+
* The vertical rails ("macro-left" / "macro-right") are excluded for the same reason vertical range is:
|
|
1541
|
+
* the geometry is X-axis only (`lowOffsetX` / `highOffsetX`, distance derived from `ratio * trackLength`),
|
|
1542
|
+
* and their CSS baseline is a different placement (`--ps-tooltip-tx: 0px` / `--ps-tooltip-ty: -50%`),
|
|
1543
|
+
* so writing this result there would displace the label instead of separating the pair.
|
|
1544
|
+
* 縦向きレール ("macro-left" / "macro-right") は縦向き Range と同じ理由で除外する。幾何が X 軸専用であり、
|
|
1545
|
+
* かつ縦レールの CSS 基準配置が別物 (tx: 0px / ty: -50%) のため、ここの結果を書くと対を離すのではなく
|
|
1546
|
+
* ラベルを移動させてしまう。
|
|
1547
|
+
*
|
|
1548
|
+
* @param lowRatio - Low handle position along the track as a 0-1 ratio / トラック上の下限つまみ位置比率 (0-1)
|
|
1549
|
+
* @param highRatio - High handle position along the track as a 0-1 ratio / トラック上の上限つまみ位置比率 (0-1)
|
|
1550
|
+
* @param trackLengthPx - Measured track length in pixels / 実測トラック長 (ピクセル)
|
|
1551
|
+
* @param labelPosition - Side of the track this rail draws its labels on / このレールがラベルを描くトラックの側
|
|
1552
|
+
* @param config - Measured geometry of this pair, or undefined while unmeasured / この対の実測幾何 (未実測時は undefined)
|
|
1553
|
+
* @param isMerged - Whether the pair holds one value and therefore shows one label / 対が同一値で 1 枚だけ見えている状態か
|
|
1554
|
+
* @param isSlantable - Whether this rail may slant at all / このレールが傾斜してよいか
|
|
1555
|
+
* @returns Geometry of the pair and the inline placement of each of its two labels / 対の幾何と 2 枚それぞれのインライン配置
|
|
1556
|
+
*/
|
|
1557
|
+
const solveVernierPairPlacement = (lowRatio: number, highRatio: number, trackLengthPx: number, labelPosition: PeriodSliderLabelPosition, config: LabelSlantConfig | undefined, isMerged: boolean, isSlantable: boolean): VernierPairPlacement => {
|
|
1558
|
+
const baseline = buildHorizontalSlantResult(labelPosition, config)
|
|
1559
|
+
|
|
1560
|
+
if (!isSlantable) return { slant: baseline, lowStyle: undefined, highStyle: undefined }
|
|
1561
|
+
|
|
1562
|
+
const solved = calculateLabelSlant(lowRatio * 100, highRatio * 100, trackLengthPx, labelPosition, config)
|
|
1563
|
+
const slant = isMerged ? withoutHorizontalPush(solved) : solved
|
|
1564
|
+
|
|
1565
|
+
return {
|
|
1566
|
+
slant,
|
|
1567
|
+
lowStyle: buildVernierTooltipStyle(slant.lowOffsetX, slant.lowOffsetY - baseline.lowOffsetY, slant.lowAngleDeg),
|
|
1568
|
+
highStyle: buildVernierTooltipStyle(slant.highOffsetX, slant.highOffsetY - baseline.highOffsetY, slant.highAngleDeg),
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1466
1572
|
/**
|
|
1467
1573
|
* What a stepper button does to the selected value.
|
|
1468
1574
|
* ステッパーボタンが選択値へ与える作用。
|
|
@@ -1680,6 +1786,11 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
1680
1786
|
return encode(macroUnit, props.macroRange[1])
|
|
1681
1787
|
}, [props.mode, macroRangeEndMs, vernierMacroMaxEnc, macroUnit])
|
|
1682
1788
|
|
|
1789
|
+
// 位置と ARIA は正規化済みエンコード値、表示だけ生 prop という二重の真実を解消する。
|
|
1790
|
+
// 同じ値なら表示も一致することが構造的に保証される
|
|
1791
|
+
const vernierMacroLowDate = useMemo(() => decode(macroUnit, vernierMacroLowEnc), [macroUnit, vernierMacroLowEnc])
|
|
1792
|
+
const vernierMacroHighDate = useMemo(() => decode(macroUnit, vernierMacroHighEnc), [macroUnit, vernierMacroHighEnc])
|
|
1793
|
+
|
|
1683
1794
|
// ミクロ境界 (マクロ窓がミクロのスケール範囲)。
|
|
1684
1795
|
// マクロ窓は macroUnit 単位へ丸められるうえ末尾期間全体まで広げられるため、そのままでは定義域の外側まで伸びる。
|
|
1685
1796
|
// レール自体を [minDate, maxDate] で切り落とさないと、aria-valuemin/max もドラッグ端も定義域外の日付を指す
|
|
@@ -1725,8 +1836,8 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
1725
1836
|
|
|
1726
1837
|
// 比率 (0.0 〜 1.0)。離散レールは当たり判定と同じ候補空間で描かないと、つまみがポインターから離れて飛ぶ
|
|
1727
1838
|
const macroSpan = Math.max(1, vernierMacroMaxEnc - vernierMacroMinEnc)
|
|
1728
|
-
const macroLowRatio = macroIsDiscreteScale ? discreteDateToRailRatio(sortedMacroAllowedDates, macroUnit, snapMode,
|
|
1729
|
-
const macroHighRatio = Math.max(macroLowRatio, macroIsDiscreteScale ? discreteDateToRailRatio(sortedMacroAllowedDates, macroUnit, snapMode,
|
|
1839
|
+
const macroLowRatio = macroIsDiscreteScale ? discreteDateToRailRatio(sortedMacroAllowedDates, macroUnit, snapMode, vernierMacroLowDate) : Math.max(0, Math.min(1, (vernierMacroLowEnc - vernierMacroMinEnc) / macroSpan))
|
|
1840
|
+
const macroHighRatio = Math.max(macroLowRatio, macroIsDiscreteScale ? discreteDateToRailRatio(sortedMacroAllowedDates, macroUnit, snapMode, vernierMacroHighDate) : Math.min(1, (vernierMacroHighEnc - vernierMacroMinEnc) / macroSpan))
|
|
1730
1841
|
|
|
1731
1842
|
const microSpan = Math.max(1, vernierMicroMaxEnc - vernierMicroMinEnc)
|
|
1732
1843
|
const microLowRatio = microIsDiscreteScale ? discreteDateToRailRatio(sortedMicroAllowedDates, microUnit, snapMode, vernierMicroLowDate) : Math.max(0, Math.min(1, (vernierMicroLowEnc - vernierMicroMinEnc) / microSpan))
|
|
@@ -1942,6 +2053,13 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
1942
2053
|
const [lowLabelRef, lowLabelBox] = useMeasuredBorderBox()
|
|
1943
2054
|
const [highLabelRef, highLabelBox] = useMeasuredBorderBox()
|
|
1944
2055
|
|
|
2056
|
+
// ノギスの 4 枚も同じ経路で測る。マクロとミクロは書式も単位も違うため実寸も違い、片方の幅で
|
|
2057
|
+
// 他方の押し出しを決めると必ずどちらかが外れる。測っていない対は「寸法なし」= 直立のまま
|
|
2058
|
+
const [macroLowLabelRef, macroLowLabelBox] = useMeasuredBorderBox()
|
|
2059
|
+
const [macroHighLabelRef, macroHighLabelBox] = useMeasuredBorderBox()
|
|
2060
|
+
const [microLowLabelRef, microLowLabelBox] = useMeasuredBorderBox()
|
|
2061
|
+
const [microHighLabelRef, microHighLabelBox] = useMeasuredBorderBox()
|
|
2062
|
+
|
|
1945
2063
|
useEffect(() => {
|
|
1946
2064
|
const el = trackRef.current
|
|
1947
2065
|
if (!el) return
|
|
@@ -2352,6 +2470,35 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2352
2470
|
startDrag(e.pointerId, handle, pos)
|
|
2353
2471
|
}
|
|
2354
2472
|
|
|
2473
|
+
/**
|
|
2474
|
+
* Brings the focused range handle to the front so the surviving label follows the keyboard.
|
|
2475
|
+
* 焦点の当たった Range つまみを前面へ出し、生存ラベルをキーボード操作へ追従させるハンドラ生成関数。
|
|
2476
|
+
*
|
|
2477
|
+
* @param handle - Handle that received focus / 焦点を受け取ったつまみ
|
|
2478
|
+
* @returns Focus event handler for the given handle / 指定つまみ用の focus イベントハンドラ
|
|
2479
|
+
*/
|
|
2480
|
+
const handleKnobFocus = (handle: "low" | "high") => () => {
|
|
2481
|
+
// 値が重なるとラベルは前面側の 1 枚しか見えない。焦点の当たったつまみを前面へ出さないと、
|
|
2482
|
+
// Tab で到達したつまみだけが値を表示しないまま操作されることになる。
|
|
2483
|
+
// ドラッグ中に限り前面はポインターが掴んだつまみの専権事項で、focus に譲ると交差時に掴んでいない側が前面へ出る
|
|
2484
|
+
if (disabled || activeHandleRef.current !== null) return
|
|
2485
|
+
setFrontHandle(handle)
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
/**
|
|
2489
|
+
* Brings the focused Vernier handle to the front, mirroring the range-mode focus contract.
|
|
2490
|
+
* 焦点の当たったノギスつまみを前面へ出す、Range モードと同契約の focus ハンドラ生成関数。
|
|
2491
|
+
*
|
|
2492
|
+
* @param handle - Knob handle that received focus / 焦点を受け取ったつまみ
|
|
2493
|
+
* @returns Focus event handler for the given handle / 指定つまみ用の focus イベントハンドラ
|
|
2494
|
+
*/
|
|
2495
|
+
const handleVernierKnobFocus = (handle: VernierHandle) => () => {
|
|
2496
|
+
// 同値で畳んだ対は前面側の 1 枚しか見えない。Tab で到達した側を前面へ出さないと、
|
|
2497
|
+
// これから操作するつまみだけが値を表示しない状態で残る
|
|
2498
|
+
if (disabled || activeVernierHandleRef.current !== null) return
|
|
2499
|
+
setFrontVernierHandle(handle)
|
|
2500
|
+
}
|
|
2501
|
+
|
|
2355
2502
|
const handleVernierKnobPointerDown = (handle: VernierHandle) => (e: React.PointerEvent<HTMLDivElement>) => {
|
|
2356
2503
|
if (disabled) return
|
|
2357
2504
|
e.stopPropagation()
|
|
@@ -2675,25 +2822,70 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2675
2822
|
const lowDate = valueToDate(currentLowVal)
|
|
2676
2823
|
const highDate = valueToDate(currentHighVal)
|
|
2677
2824
|
|
|
2678
|
-
//
|
|
2679
|
-
//
|
|
2825
|
+
// Point モードはラベルが 1 枚で、その 1 枚の実寸がそのまま直立基準の高さになる。
|
|
2826
|
+
// 対になる 2 枚の規則 (片方でも未実測なら寸法なし) は buildPairSlantConfig が一手に持つ
|
|
2680
2827
|
const labelSlantConfig: LabelSlantConfig | undefined = useMemo(() => {
|
|
2681
2828
|
if (isPointMode) return lowLabelBox === null ? undefined : { estimatedWidthPx: lowLabelBox.widthPx, estimatedHeightPx: lowLabelBox.heightPx }
|
|
2682
|
-
|
|
2683
|
-
return {
|
|
2684
|
-
estimatedWidthPx: Math.max(lowLabelBox.widthPx, highLabelBox.widthPx),
|
|
2685
|
-
estimatedHeightPx: Math.max(lowLabelBox.heightPx, highLabelBox.heightPx),
|
|
2686
|
-
}
|
|
2829
|
+
return buildPairSlantConfig(lowLabelBox, highLabelBox)
|
|
2687
2830
|
}, [isPointMode, lowLabelBox, highLabelBox])
|
|
2688
2831
|
|
|
2832
|
+
// 値が一致するとき 2 枚のラベルは文字列まで同一になる (valueToDate が純粋なので構造的に保証される)。
|
|
2833
|
+
// ピクセル距離では別日と区別できないため判定は必ず値で行う。
|
|
2834
|
+
// point モードは上限値を下限値へ寄せるため素の一致判定が恒真になり、!isPointMode で外さないと成立しない
|
|
2835
|
+
const isLabelMerged = !isPointMode && currentLowVal === currentHighVal
|
|
2836
|
+
|
|
2689
2837
|
const slantResult: LabelSlantResult = useMemo(() => {
|
|
2838
|
+
// 縦向きは X 軸オフセットしか返さない幾何を適用できない。Point モードは避ける相手そのものが居ない
|
|
2690
2839
|
if (isPointMode || !autoSlantLabels || isVertical) return buildHorizontalSlantResult(labelPosition, labelSlantConfig)
|
|
2691
|
-
|
|
2692
|
-
|
|
2840
|
+
|
|
2841
|
+
const solved = calculateLabelSlant(lowPct, highPct, trackLength, labelPosition, labelSlantConfig)
|
|
2842
|
+
if (!isLabelMerged) return solved
|
|
2843
|
+
|
|
2844
|
+
// 併合時に残る 1 枚は前面側であり、front は焦点・押下・交差のたび入れ替わる。押し退けを残すと
|
|
2845
|
+
// 唯一のラベルが ±shiftX の間を飛び、離す相手も居ない。角度と垂直オフセットは 90deg のラベルを
|
|
2846
|
+
// つまみから逃がすために必要なので保持し、接近から一致まで角度も位置も連続させる
|
|
2847
|
+
return withoutHorizontalPush(solved)
|
|
2848
|
+
}, [isPointMode, isLabelMerged, autoSlantLabels, isVertical, lowPct, highPct, trackLength, labelPosition, labelSlantConfig])
|
|
2693
2849
|
|
|
2694
2850
|
const isLowFront = activeHandle === "low" || (activeHandle !== "high" && frontHandle === "low")
|
|
2695
2851
|
const isHighFront = !isPointMode && (activeHandle === "high" || (activeHandle !== "low" && frontHandle === "high"))
|
|
2696
2852
|
|
|
2853
|
+
// ノギスの 2 対も Range と同じ根拠で畳む。マクロ・ミクロとも符号化値から復元した日付を整形するため、
|
|
2854
|
+
// 符号化値が一致すればラベルは文字列まで一致する。しかもノギスには押し退けが無く 2 枚が同一矩形へ
|
|
2855
|
+
// 完全に重なるため、畳まないと同じ値が二重に読み上げられるだけで視覚的な情報も増えない
|
|
2856
|
+
const isVernierMacroLabelMerged = vernierMacroLowEnc === vernierMacroHighEnc
|
|
2857
|
+
const isVernierMicroLabelMerged = vernierMicroLowEnc === vernierMicroHighEnc
|
|
2858
|
+
|
|
2859
|
+
// 生存者は対の内側だけで決める。frontVernierHandle は 4 つのつまみで 1 本しか無く、相手の対や
|
|
2860
|
+
// 連結バーを操作している間は対の両方が非 front になるため、「front でない方を隠す」では両方消える。
|
|
2861
|
+
// 下限が front のときだけ下限を残し、それ以外は上限を残す (Range の初期前面と同じ上限優先) 全域規則
|
|
2862
|
+
const isVernierMacroLowLabelDuplicate = isVernierMacroLabelMerged && frontVernierHandle !== "macro-low"
|
|
2863
|
+
const isVernierMacroHighLabelDuplicate = isVernierMacroLabelMerged && frontVernierHandle === "macro-low"
|
|
2864
|
+
const isVernierMicroLowLabelDuplicate = isVernierMicroLabelMerged && frontVernierHandle !== "micro-low"
|
|
2865
|
+
const isVernierMicroHighLabelDuplicate = isVernierMicroLabelMerged && frontVernierHandle === "micro-low"
|
|
2866
|
+
|
|
2867
|
+
// ラベルが載る面はつまみと同じ側であり、JSX の data-vernier-pos が示す面と必ず一致する
|
|
2868
|
+
const macroRailLabelPosition: PeriodSliderLabelPosition = isMacroFirstRail ? "top" : "bottom"
|
|
2869
|
+
const microRailLabelPosition: PeriodSliderLabelPosition = isMacroFirstRail ? "bottom" : "top"
|
|
2870
|
+
|
|
2871
|
+
// マクロとミクロは同じトラックの上で比率も単位空間もラベル幅も異なる。1 つの計算を共有すると
|
|
2872
|
+
// 一方の押し退け量が他方の実寸で決まってしまうため、対ごとに独立して解く
|
|
2873
|
+
const macroLabelSlantConfig = useMemo(() => buildPairSlantConfig(macroLowLabelBox, macroHighLabelBox), [macroLowLabelBox, macroHighLabelBox])
|
|
2874
|
+
const microLabelSlantConfig = useMemo(() => buildPairSlantConfig(microLowLabelBox, microHighLabelBox), [microLowLabelBox, microHighLabelBox])
|
|
2875
|
+
|
|
2876
|
+
// 傾斜可否はレール単位で決まる。縦向きノギスは縦向き Range と同じ理由で外す (solveVernierPairPlacement 参照)
|
|
2877
|
+
const isVernierSlantable = autoSlantLabels && !isVertical
|
|
2878
|
+
|
|
2879
|
+
const macroPairPlacement = useMemo(
|
|
2880
|
+
() => solveVernierPairPlacement(macroLowRatio, macroHighRatio, trackLength, macroRailLabelPosition, macroLabelSlantConfig, isVernierMacroLabelMerged, isVernierSlantable),
|
|
2881
|
+
[macroLowRatio, macroHighRatio, trackLength, macroRailLabelPosition, macroLabelSlantConfig, isVernierMacroLabelMerged, isVernierSlantable],
|
|
2882
|
+
)
|
|
2883
|
+
|
|
2884
|
+
const microPairPlacement = useMemo(
|
|
2885
|
+
() => solveVernierPairPlacement(microLowRatio, microHighRatio, trackLength, microRailLabelPosition, microLabelSlantConfig, isVernierMicroLabelMerged, isVernierSlantable),
|
|
2886
|
+
[microLowRatio, microHighRatio, trackLength, microRailLabelPosition, microLabelSlantConfig, isVernierMicroLabelMerged, isVernierSlantable],
|
|
2887
|
+
)
|
|
2888
|
+
|
|
2697
2889
|
const lowTooltipStyle: CSSProperties = useMemo(() => {
|
|
2698
2890
|
if (isVertical) {
|
|
2699
2891
|
return {
|
|
@@ -2903,7 +3095,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2903
3095
|
aria-valuemin={vernierMacroMinEnc}
|
|
2904
3096
|
aria-valuemax={vernierMacroHighEnc}
|
|
2905
3097
|
aria-valuenow={vernierMacroLowEnc}
|
|
2906
|
-
aria-valuetext={props.formatAriaValueText ? props.formatAriaValueText(
|
|
3098
|
+
aria-valuetext={props.formatAriaValueText ? props.formatAriaValueText(vernierMacroLowDate, macroUnit) : formatScreenReaderLabel(macroUnit, vernierMacroLowDate, formatMacroLabel, locale)}
|
|
2907
3099
|
aria-orientation={isVertical ? "vertical" : "horizontal"}
|
|
2908
3100
|
className={`period-slider-handle period-slider-handle-vernier ${isVertical ? "is-vertical" : ""} group absolute touch-none ${
|
|
2909
3101
|
isVertical
|
|
@@ -2933,6 +3125,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2933
3125
|
}
|
|
2934
3126
|
onPointerDown={handleVernierKnobPointerDown("macro-low")}
|
|
2935
3127
|
onKeyDown={handleVernierKeyDown("macro-low")}
|
|
3128
|
+
onFocus={handleVernierKnobFocus("macro-low")}
|
|
2936
3129
|
data-active={activeVernierHandle === "macro-low" ? "true" : undefined}
|
|
2937
3130
|
data-front={frontVernierHandle === "macro-low" ? "true" : undefined}
|
|
2938
3131
|
data-vernier-pos={isVertical ? (isMacroFirstRail ? "left" : "right") : isMacroFirstRail ? "top" : "bottom"}
|
|
@@ -2942,8 +3135,12 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2942
3135
|
{tooltipStyle !== "hover" && (
|
|
2943
3136
|
<div
|
|
2944
3137
|
className={`period-slider-tooltip absolute whitespace-nowrap rounded bg-slate-900 px-2 py-0.5 font-medium text-white text-xs shadow-md dark:bg-slate-800 ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
|
|
2945
|
-
data-tooltip-style={tooltipStyle}
|
|
2946
|
-
{
|
|
3138
|
+
data-tooltip-style={tooltipStyle}
|
|
3139
|
+
data-duplicate={isVernierMacroLowLabelDuplicate ? "true" : undefined}
|
|
3140
|
+
data-slanted={macroPairPlacement.slant.isSlanted ? "true" : undefined}
|
|
3141
|
+
ref={macroLowLabelRef}
|
|
3142
|
+
style={macroPairPlacement.lowStyle}>
|
|
3143
|
+
{formatLabel(macroUnit, vernierMacroLowDate, formatMacroLabel, locale)}
|
|
2947
3144
|
</div>
|
|
2948
3145
|
)}
|
|
2949
3146
|
</div>
|
|
@@ -2957,7 +3154,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2957
3154
|
aria-valuemin={vernierMacroLowEnc}
|
|
2958
3155
|
aria-valuemax={vernierMacroMaxEnc}
|
|
2959
3156
|
aria-valuenow={vernierMacroHighEnc}
|
|
2960
|
-
aria-valuetext={props.formatAriaValueText ? props.formatAriaValueText(
|
|
3157
|
+
aria-valuetext={props.formatAriaValueText ? props.formatAriaValueText(vernierMacroHighDate, macroUnit) : formatScreenReaderLabel(macroUnit, vernierMacroHighDate, formatMacroLabel, locale)}
|
|
2961
3158
|
aria-orientation={isVertical ? "vertical" : "horizontal"}
|
|
2962
3159
|
className={`period-slider-handle period-slider-handle-vernier ${isVertical ? "is-vertical" : ""} group absolute touch-none ${
|
|
2963
3160
|
isVertical
|
|
@@ -2987,6 +3184,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2987
3184
|
}
|
|
2988
3185
|
onPointerDown={handleVernierKnobPointerDown("macro-high")}
|
|
2989
3186
|
onKeyDown={handleVernierKeyDown("macro-high")}
|
|
3187
|
+
onFocus={handleVernierKnobFocus("macro-high")}
|
|
2990
3188
|
data-active={activeVernierHandle === "macro-high" ? "true" : undefined}
|
|
2991
3189
|
data-front={frontVernierHandle === "macro-high" ? "true" : undefined}
|
|
2992
3190
|
data-vernier-pos={isVertical ? (isMacroFirstRail ? "left" : "right") : isMacroFirstRail ? "top" : "bottom"}
|
|
@@ -2996,8 +3194,12 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2996
3194
|
{tooltipStyle !== "hover" && (
|
|
2997
3195
|
<div
|
|
2998
3196
|
className={`period-slider-tooltip absolute whitespace-nowrap rounded bg-slate-900 px-2 py-0.5 font-medium text-white text-xs shadow-md dark:bg-slate-800 ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
|
|
2999
|
-
data-tooltip-style={tooltipStyle}
|
|
3000
|
-
{
|
|
3197
|
+
data-tooltip-style={tooltipStyle}
|
|
3198
|
+
data-duplicate={isVernierMacroHighLabelDuplicate ? "true" : undefined}
|
|
3199
|
+
data-slanted={macroPairPlacement.slant.isSlanted ? "true" : undefined}
|
|
3200
|
+
ref={macroHighLabelRef}
|
|
3201
|
+
style={macroPairPlacement.highStyle}>
|
|
3202
|
+
{formatLabel(macroUnit, vernierMacroHighDate, formatMacroLabel, locale)}
|
|
3001
3203
|
</div>
|
|
3002
3204
|
)}
|
|
3003
3205
|
</div>
|
|
@@ -3041,6 +3243,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3041
3243
|
}
|
|
3042
3244
|
onPointerDown={handleVernierKnobPointerDown("micro-low")}
|
|
3043
3245
|
onKeyDown={handleVernierKeyDown("micro-low")}
|
|
3246
|
+
onFocus={handleVernierKnobFocus("micro-low")}
|
|
3044
3247
|
data-active={activeVernierHandle === "micro-low" ? "true" : undefined}
|
|
3045
3248
|
data-front={frontVernierHandle === "micro-low" ? "true" : undefined}
|
|
3046
3249
|
data-vernier-pos={isVertical ? (isMacroFirstRail ? "right" : "left") : isMacroFirstRail ? "bottom" : "top"}
|
|
@@ -3050,7 +3253,11 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3050
3253
|
{tooltipStyle !== "hover" && (
|
|
3051
3254
|
<div
|
|
3052
3255
|
className={`period-slider-tooltip absolute whitespace-nowrap rounded bg-slate-900 px-2 py-0.5 font-medium text-white text-xs shadow-md dark:bg-slate-800 ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
|
|
3053
|
-
data-tooltip-style={tooltipStyle}
|
|
3256
|
+
data-tooltip-style={tooltipStyle}
|
|
3257
|
+
data-duplicate={isVernierMicroLowLabelDuplicate ? "true" : undefined}
|
|
3258
|
+
data-slanted={microPairPlacement.slant.isSlanted ? "true" : undefined}
|
|
3259
|
+
ref={microLowLabelRef}
|
|
3260
|
+
style={microPairPlacement.lowStyle}>
|
|
3054
3261
|
{formatLabel(microUnit, vernierMicroLowDate, formatMicroLabel, locale)}
|
|
3055
3262
|
</div>
|
|
3056
3263
|
)}
|
|
@@ -3095,6 +3302,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3095
3302
|
}
|
|
3096
3303
|
onPointerDown={handleVernierKnobPointerDown("micro-high")}
|
|
3097
3304
|
onKeyDown={handleVernierKeyDown("micro-high")}
|
|
3305
|
+
onFocus={handleVernierKnobFocus("micro-high")}
|
|
3098
3306
|
data-active={activeVernierHandle === "micro-high" ? "true" : undefined}
|
|
3099
3307
|
data-front={frontVernierHandle === "micro-high" ? "true" : undefined}
|
|
3100
3308
|
data-vernier-pos={isVertical ? (isMacroFirstRail ? "right" : "left") : isMacroFirstRail ? "bottom" : "top"}
|
|
@@ -3104,7 +3312,11 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3104
3312
|
{tooltipStyle !== "hover" && (
|
|
3105
3313
|
<div
|
|
3106
3314
|
className={`period-slider-tooltip absolute whitespace-nowrap rounded bg-slate-900 px-2 py-0.5 font-medium text-white text-xs shadow-md dark:bg-slate-800 ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
|
|
3107
|
-
data-tooltip-style={tooltipStyle}
|
|
3315
|
+
data-tooltip-style={tooltipStyle}
|
|
3316
|
+
data-duplicate={isVernierMicroHighLabelDuplicate ? "true" : undefined}
|
|
3317
|
+
data-slanted={microPairPlacement.slant.isSlanted ? "true" : undefined}
|
|
3318
|
+
ref={microHighLabelRef}
|
|
3319
|
+
style={microPairPlacement.highStyle}>
|
|
3108
3320
|
{formatLabel(microUnit, vernierMicroHighDate, formatMicroLabel, locale)}
|
|
3109
3321
|
</div>
|
|
3110
3322
|
)}
|
|
@@ -3153,6 +3365,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3153
3365
|
style={lowHandleStyle}
|
|
3154
3366
|
onPointerDown={handleKnobPointerDown("low")}
|
|
3155
3367
|
onKeyDown={handleKeyDown("low")}
|
|
3368
|
+
onFocus={handleKnobFocus("low")}
|
|
3156
3369
|
data-active={activeHandle === "low" ? "true" : undefined}
|
|
3157
3370
|
data-front={isLowFront ? "true" : undefined}>
|
|
3158
3371
|
<div
|
|
@@ -3166,6 +3379,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3166
3379
|
data-label-position={labelPosition}
|
|
3167
3380
|
data-slanted={slantResult.isSlanted ? "true" : undefined}
|
|
3168
3381
|
data-front={isLowFront ? "true" : undefined}
|
|
3382
|
+
data-duplicate={isLabelMerged && !isLowFront ? "true" : undefined}
|
|
3169
3383
|
ref={lowLabelRef}
|
|
3170
3384
|
style={lowTooltipStyle}>
|
|
3171
3385
|
{formatLabel(unit, lowDate, props.formatLabel, locale)}
|
|
@@ -3189,6 +3403,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3189
3403
|
style={highHandleStyle}
|
|
3190
3404
|
onPointerDown={handleKnobPointerDown("high")}
|
|
3191
3405
|
onKeyDown={handleKeyDown("high")}
|
|
3406
|
+
onFocus={handleKnobFocus("high")}
|
|
3192
3407
|
data-active={activeHandle === "high" ? "true" : undefined}
|
|
3193
3408
|
data-front={isHighFront ? "true" : undefined}>
|
|
3194
3409
|
<div
|
|
@@ -3202,6 +3417,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3202
3417
|
data-label-position={labelPosition}
|
|
3203
3418
|
data-slanted={slantResult.isSlanted ? "true" : undefined}
|
|
3204
3419
|
data-front={isHighFront ? "true" : undefined}
|
|
3420
|
+
data-duplicate={isLabelMerged && !isHighFront ? "true" : undefined}
|
|
3205
3421
|
ref={highLabelRef}
|
|
3206
3422
|
style={highTooltipStyle}>
|
|
3207
3423
|
{formatLabel(unit, highDate, props.formatLabel, locale)}
|
|
@@ -351,6 +351,15 @@
|
|
|
351
351
|
0 0 22px rgba(56, 189, 248, 0.75);
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
+
/* 2 つのつまみが同じ値を持つとき、背面側のラベルは前面側と一字一句同じ文字列になるため隠す。
|
|
355
|
+
display:none やアンマウントでは ResizeObserver が実寸を報告しなくなり (0px または通知停止)、
|
|
356
|
+
つまみが離れた瞬間に未実測の値で傾斜計算が走って配置が跳ねる。
|
|
357
|
+
visibility:hidden ならボーダーボックスは残り実測が続く一方、描画とアクセシビリティツリーの
|
|
358
|
+
双方からは外れる。!important は隣接宣言と同じく Tailwind ユーティリティ層へ勝つため */
|
|
359
|
+
.period-slider-tooltip[data-duplicate="true"] {
|
|
360
|
+
visibility: hidden !important;
|
|
361
|
+
}
|
|
362
|
+
|
|
354
363
|
/* 垂直モード (isVertical) 時のインジケーターラベル配置: つまみの左側 8px に垂直中央揃えで配置 */
|
|
355
364
|
.period-slider-track[data-orientation="vertical"] .period-slider-tooltip,
|
|
356
365
|
.period-slider[data-orientation="vertical"] .period-slider-tooltip {
|
|
@@ -497,25 +506,28 @@
|
|
|
497
506
|
/* ------------------------------------------------------------- */
|
|
498
507
|
/* ツールチップ: Balloon スタイル (旧水滴バルーン風) */
|
|
499
508
|
/* ------------------------------------------------------------- */
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
509
|
+
/* data-tooltip-style はツールチップ要素自身に付くため、子孫結合子では一致しない (要素自身で選ぶ)。
|
|
510
|
+
回転は基底ルールの transform (!important) が握っており、ここで transform を書いても効かない。
|
|
511
|
+
仮に勝たせると衝突回避の平行移動ごと消えてラベルがつまみから外れるため、形は border-radius だけで作る。
|
|
512
|
+
!important は隣接する .period-slider-tooltip や [data-duplicate="true"] と同じ理由による。利用側が
|
|
513
|
+
Tailwind の場合、本 CSS はユーティリティ層より下のカスケードレイヤーへ取り込まれるため、詳細度が
|
|
514
|
+
高くても !important 無しでは要素に付く bg-slate-900 / rounded / px-2 py-0.5 / text-xs が勝つ。
|
|
515
|
+
ユーティリティの無い height と border だけが適用される半端な見た目 (pill でも balloon でもない) を避ける */
|
|
516
|
+
.period-slider-tooltip[data-tooltip-style="balloon"] {
|
|
517
|
+
height: 28px !important;
|
|
518
|
+
/* 角丸の内側へ文字が潜らないよう、pill 既定 (5px) より広い左右余白を取る */
|
|
519
|
+
padding: 0 10px 1.5px 10px !important;
|
|
520
|
+
border: none !important;
|
|
521
|
+
background-color: #5fc0f4 !important;
|
|
522
|
+
color: #ffffff !important;
|
|
523
|
+
font-size: 10px !important;
|
|
524
|
+
/* 左下だけ角を残した吹き出しの尾。ラベル幅は文字列とロケールで変わるため、水平半径に % を使うと
|
|
525
|
+
箱全体が楕円になって文字が欠ける。高さ 28px の半分を実寸で指定し、端は常に半円に保つ */
|
|
526
|
+
border-radius: 14px 14px 14px 0 !important;
|
|
527
|
+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2) !important;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
.period-slider-tooltip[data-tooltip-style="balloon"].is-active {
|
|
519
531
|
background-color: #0284c7;
|
|
520
532
|
box-shadow:
|
|
521
533
|
0 0 0 2px #ffffff,
|