@aiquants/period-slider 0.23.0 → 0.24.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/CHANGELOG.md +44 -0
- package/README.md +31 -7
- package/dist/DateSelector.d.ts.map +1 -1
- package/dist/MonthSelector.d.ts.map +1 -1
- package/dist/PeriodSlider.d.ts +0 -7
- package/dist/PeriodSlider.d.ts.map +1 -1
- package/dist/YearSelector.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +991 -992
- package/dist/selectorField.d.ts +20 -0
- package/dist/selectorField.d.ts.map +1 -0
- package/dist/styles/period-slider.css +1 -1
- package/dist/styles/period-slider.standalone.css +1 -1
- package/package.json +2 -2
- package/src/DateSelector.tsx +6 -6
- package/src/MonthSelector.tsx +3 -2
- package/src/PeriodSlider.tsx +24 -17
- package/src/YearSelector.tsx +2 -1
- package/src/selectorField.ts +22 -0
- package/src/styles/period-slider.css +34 -13
package/src/PeriodSlider.tsx
CHANGED
|
@@ -1749,14 +1749,6 @@ const DEFAULT_LABEL_PADDING_PX = 12
|
|
|
1749
1749
|
/** Angle the labels reach when the two handles coincide, in degrees / 2 つのつまみが完全一致した時に到達する角度 (度) */
|
|
1750
1750
|
const DEFAULT_MAX_SLANT_ANGLE_DEG = 90
|
|
1751
1751
|
|
|
1752
|
-
/**
|
|
1753
|
-
* Scale the stylesheet draws the label of a grabbed knob at (`--ps-tooltip-scale` under `[data-active="true"]`); the room
|
|
1754
|
-
* check reads it so the pair still fits once one of its labels is grabbed, and a unit test pins it to the stylesheet.
|
|
1755
|
-
* 掴んだつまみのラベルをスタイルシートが描く倍率 (`[data-active="true"]` の `--ps-tooltip-scale`)。
|
|
1756
|
-
* 余白の判定がこれを読むため、対のどちらかを掴んでも収まったままになる。単体テストがスタイルシートとの一致を固定する。
|
|
1757
|
-
*/
|
|
1758
|
-
export const LABEL_EMPHASIS_SCALE = 1.15
|
|
1759
|
-
|
|
1760
1752
|
/**
|
|
1761
1753
|
* Half extents of the bounding box of a rectangle rotated by an angle, along its unrotated width and across it.
|
|
1762
1754
|
* 角度だけ回転した矩形の外接矩形の半寸法 (回転前の幅方向と、その直交方向)。
|
|
@@ -3289,7 +3281,6 @@ const resolveVernierRoomFit = (input: VernierPairPlacementInput): { config: Labe
|
|
|
3289
3281
|
anchorGapY: input.anchor.anchorPx - KNOB_RADIUS_PX,
|
|
3290
3282
|
flipClearancePx: input.opposite.anchorPx + input.opposite.reachPx + DEFAULT_LABEL_ANCHOR_GAP_Y_PX,
|
|
3291
3283
|
room: input.room,
|
|
3292
|
-
drawnScale: LABEL_EMPHASIS_SCALE,
|
|
3293
3284
|
},
|
|
3294
3285
|
oppositeAnchorPx: input.opposite.anchorPx,
|
|
3295
3286
|
}
|
|
@@ -3319,17 +3310,16 @@ interface VernierPairPlacementInput extends PairSlantInput {
|
|
|
3319
3310
|
interface VernierOppositeLabels {
|
|
3320
3311
|
/** Distance from the rail centre line to the anchor line the other rail's labels stand on, in pixels / レール中心線から、もう一方のレールのラベルが立つ基準線までの距離 (ピクセル) */
|
|
3321
3312
|
anchorPx: number
|
|
3322
|
-
/** How far the other rail's labels reach beyond that line
|
|
3313
|
+
/** How far the other rail's labels reach beyond that line, in pixels / もう一方のレールのラベルが、その線から先へ届く距離 (ピクセル) */
|
|
3323
3314
|
reachPx: number
|
|
3324
3315
|
}
|
|
3325
3316
|
|
|
3326
3317
|
/**
|
|
3327
3318
|
* Resolves the other vernier rail's labels as a pair that may stand across them sees them: where they start and how far
|
|
3328
3319
|
* they reach, standing on their own side, rotated as far as their anti-collision ramp asks (upright when they are a merged
|
|
3329
|
-
* pair the host keeps upright)
|
|
3320
|
+
* pair the host keeps upright) - that is, before the room is read.
|
|
3330
3321
|
* 反対側へ立ちうる対から見た、もう一方のノギスのレールのラベル (どこから始まり、どこまで届くか) を解決する関数。
|
|
3331
|
-
* ラベルは余白を読む前の姿 (
|
|
3332
|
-
* 強調の倍率で描かれる) で取る。
|
|
3322
|
+
* ラベルは余白を読む前の姿 (自分の側に立ち、衝突回避のランプが求める角度まで回る。ホストが直立を求めた畳んだ対は直立) で取る。
|
|
3333
3323
|
*
|
|
3334
3324
|
* That is where they are whenever the pair may stand across them: the pair moves over only when it fits beyond those
|
|
3335
3325
|
* labels, and the other rail's labels, needing less of the same room, then fit on their own side unmoved and at the full
|
|
@@ -3346,8 +3336,7 @@ interface VernierOppositeLabels {
|
|
|
3346
3336
|
const resolveVernierOppositeLabels = (lowRatio: number, highRatio: number, other: Omit<VernierPairPlacementInput, "opposite">, box: MeasuredBoxPx | null): VernierOppositeLabels | null => {
|
|
3347
3337
|
if (other.anchor === null || box === null) return null
|
|
3348
3338
|
const angleDeg = other.isSlantable ? solvePairSlant(lowRatio * 100, highRatio * 100, other, other.config).lowAngleDeg : 0
|
|
3349
|
-
|
|
3350
|
-
return { anchorPx: other.anchor.anchorPx, reachPx: (1 + LABEL_EMPHASIS_SCALE) * resolveRotatedHalfExtents(box.widthPx, box.heightPx, angleDeg).acrossPx }
|
|
3339
|
+
return { anchorPx: other.anchor.anchorPx, reachPx: 2 * resolveRotatedHalfExtents(box.widthPx, box.heightPx, angleDeg).acrossPx }
|
|
3351
3340
|
}
|
|
3352
3341
|
|
|
3353
3342
|
/**
|
|
@@ -3416,8 +3405,7 @@ const solveFlatPairPlacement = (lowPct: number, highPct: number, input: FlatPair
|
|
|
3416
3405
|
const isSolvable = input.autoSlantLabels && !input.isPointMode
|
|
3417
3406
|
let slant = baseline
|
|
3418
3407
|
if (isSolvable) {
|
|
3419
|
-
|
|
3420
|
-
const config = input.config === undefined || input.room === undefined ? input.config : { ...input.config, room: input.room, drawnScale: LABEL_EMPHASIS_SCALE }
|
|
3408
|
+
const config = input.config === undefined || input.room === undefined ? input.config : { ...input.config, room: input.room }
|
|
3421
3409
|
slant = solvePairSlant(lowPct, highPct, input, config)
|
|
3422
3410
|
}
|
|
3423
3411
|
|
|
@@ -4849,10 +4837,29 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
4849
4837
|
}
|
|
4850
4838
|
}, [isDragging])
|
|
4851
4839
|
|
|
4840
|
+
/**
|
|
4841
|
+
* Starts a flat-rail drag of a knob or of the range body: captures the pointer, records where the drag starts and
|
|
4842
|
+
* makes the grabbed handle the active one. The hover guide's value is cleared, because the guide shows the value
|
|
4843
|
+
* under the pointer and the drag moves the pointer away from it: kept, it would come back at the position the drag
|
|
4844
|
+
* started from as soon as the drag ends (on pointerup, pointercancel, a lost capture or a mode switch alike), and it
|
|
4845
|
+
* returns at the pointer's position with the next move over the track.
|
|
4846
|
+
* 平レールのつまみか範囲の帯のドラッグを始める関数。ポインターを捕まえ、ドラッグの始まりを記録し、掴んだつまみを操作中にする。
|
|
4847
|
+
* ホバーガイドの値は消す。ガイドはポインターの下の値を示すもので、ドラッグはポインターをそこから離すため、残すとドラッグが
|
|
4848
|
+
* 終わった瞬間 (pointerup・pointercancel・捕捉の喪失・mode の切り替えのどれでも) にドラッグを始めた位置へ戻ってしまう。
|
|
4849
|
+
* ガイドはトラックの上の次のポインターの移動で、その位置に戻る。
|
|
4850
|
+
*
|
|
4851
|
+
* @param grabbed - Element that received the pointerdown / pointerdown を受けた要素
|
|
4852
|
+
* @param pointerId - Pointer that starts the drag / ドラッグを始めるポインター
|
|
4853
|
+
* @param handle - What is dragged: a knob or the range body / ドラッグするもの (つまみか範囲の帯)
|
|
4854
|
+
* @param startPointerPos - Pointer's client coordinate along the rail at the start (`clientX`, or `clientY` when vertical), in px / 始まりのレール方向のポインターのクライアント座標 (`clientX`。縦向きは `clientY`。px)
|
|
4855
|
+
* @returns Nothing / 戻り値なし
|
|
4856
|
+
*/
|
|
4852
4857
|
const startDrag = useCallback(
|
|
4853
4858
|
(grabbed: Element, pointerId: number, handle: "low" | "high" | "connect", startPointerPos: number) => {
|
|
4854
4859
|
cancelSnapBack()
|
|
4855
4860
|
captureGesturePointer(grabbed, pointerId)
|
|
4861
|
+
setHoverValue(null)
|
|
4862
|
+
setHoverPct(null)
|
|
4856
4863
|
// 掴んでいない間はスクロールを見張っていない。表示層が対を傾け始める前に、今の画面に対して余白を測り直す
|
|
4857
4864
|
remeasureLabelSurroundings()
|
|
4858
4865
|
dragContextRef.current = {
|
package/src/YearSelector.tsx
CHANGED
|
@@ -24,6 +24,7 @@ import { assertCandidateListInput, describeValue, isValidDate } from "./inputVal
|
|
|
24
24
|
import { areLabelOverridesEqual, type PeriodSliderLabelOverrides, type PeriodSliderLocale } from "./labels"
|
|
25
25
|
import { assertLocaleTag, encodeInsideDateRange, formatLabel, isYearStartMonth, type PeriodOptionFormatter, resolveYearStartMonth, sentinelBoundRemedy, yearKeyOfCivil } from "./PeriodSlider"
|
|
26
26
|
import { resolveStepGlyph, STEPPER_ROW_GAP_CLASS, type StepGlyph, StepperButton } from "./StepperButton"
|
|
27
|
+
import { YEAR_SELECTOR_FIELD_CLASSES } from "./selectorField"
|
|
27
28
|
import { areSelectorDatePropsEqual, selectorUnitKey } from "./selectorMemo"
|
|
28
29
|
import { assertSelectorStepper, type SelectorStepper } from "./selectorStep"
|
|
29
30
|
import { useResolvedLabels } from "./useResolvedLabels"
|
|
@@ -442,7 +443,7 @@ const YearSelectorComponent = (props: YearSelectorProps): React.JSX.Element => {
|
|
|
442
443
|
<select
|
|
443
444
|
aria-label={resolvedLabels.yearSelect}
|
|
444
445
|
disabled={disabled}
|
|
445
|
-
className=
|
|
446
|
+
className={`${YEAR_SELECTOR_FIELD_CLASSES} appearance-none rounded-md border border-gray-300 bg-gray-100 px-1 py-0.5 text-center font-mono text-gray-900 tabular-nums [text-align-last:center] [text-align:center] focus:border-blue-500 focus:ring-blue-500 disabled:opacity-50 dark:border-slate-600 dark:bg-slate-700 dark:text-slate-100 dark:focus:border-blue-500 dark:focus:ring-blue-500`}
|
|
446
447
|
value={currentYear}
|
|
447
448
|
onChange={(e) => {
|
|
448
449
|
// 空値の change は選択解除であり、年として解釈しない
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Size contract every selector field shares (internal; nothing here is exported from the package entry).
|
|
3
|
+
* Every field of the three selectors, in every variant - the year `select`, the month `select` and native month
|
|
4
|
+
* input, the date combobox, the year / month / day `select`s and the native date input - carries
|
|
5
|
+
* `SELECTOR_FIELD_CLASS`, so the shipped stylesheet's one rule sizes all of them from the two published variables
|
|
6
|
+
* `--aqps-field-height` and `--aqps-field-font-size`. The fixed widths are multiples of that font size, so a larger font
|
|
7
|
+
* widens the field with it and the value keeps fitting; at the default font they are the widths the fields always had.
|
|
8
|
+
* 3 セレクタの全ての欄が共有する大きさの契約 (内部モジュール。パッケージの入口からは公開しない)。
|
|
9
|
+
* どの変種のどの欄 (年の `select`、年月の `select` とネイティブの年月の入力、日付のコンボボックス、年・月・日の `select`、
|
|
10
|
+
* ネイティブの日付の入力) も `SELECTOR_FIELD_CLASS` を持ち、配布スタイルシートの 1 つの規則が、公開の 2 変数
|
|
11
|
+
* `--aqps-field-height`・`--aqps-field-font-size` から全ての欄の大きさを決める。固定の幅は字の大きさの倍数のため、字を大きくすると
|
|
12
|
+
* 欄も一緒に広がって値が収まり続け、既定の字ではこれまでの幅と同じ。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** Class hooking a field to the stylesheet's size rule (`.period-slider-selector-field`); a field carrying only this one keeps the width its content gives it / 欄を配布スタイルシートの大きさの規則へ繋ぐクラス (これだけを持つ欄は中身の幅のまま) */
|
|
16
|
+
export const SELECTOR_FIELD_CLASS = "period-slider-selector-field"
|
|
17
|
+
|
|
18
|
+
/** Classes of the year field: the size rule and a width of 6 times the font size, 72px at the default 12px font / 年の欄のクラス (大きさの規則と、字の大きさの 6 倍の幅。既定の字 12px で 72px) */
|
|
19
|
+
export const YEAR_SELECTOR_FIELD_CLASSES = `${SELECTOR_FIELD_CLASS} period-slider-selector-field-year`
|
|
20
|
+
|
|
21
|
+
/** Classes of the month and date fields: the size rule and a width of 28 / 3 times the font size, 112px at the default 12px font / 年月と日付の欄のクラス (大きさの規則と、字の大きさの 28 / 3 倍の幅。既定の字 12px で 112px) */
|
|
22
|
+
export const DATE_SELECTOR_FIELD_CLASSES = `${SELECTOR_FIELD_CLASS} period-slider-selector-field-date`
|
|
@@ -415,7 +415,6 @@
|
|
|
415
415
|
--ps-tooltip-tx: -50%;
|
|
416
416
|
--ps-tooltip-ty: -50%;
|
|
417
417
|
--ps-tooltip-rot: 0deg;
|
|
418
|
-
--ps-tooltip-scale: 1;
|
|
419
418
|
|
|
420
419
|
position: absolute !important;
|
|
421
420
|
top: 50% !important;
|
|
@@ -423,7 +422,7 @@
|
|
|
423
422
|
bottom: auto !important;
|
|
424
423
|
right: auto !important;
|
|
425
424
|
transform-origin: var(--ps-tooltip-origin) !important;
|
|
426
|
-
transform: translate(var(--ps-tooltip-tx), var(--ps-tooltip-ty)) rotate(var(--ps-tooltip-rot))
|
|
425
|
+
transform: translate(var(--ps-tooltip-tx), var(--ps-tooltip-ty)) rotate(var(--ps-tooltip-rot)) !important;
|
|
427
426
|
white-space: nowrap !important;
|
|
428
427
|
pointer-events: none !important;
|
|
429
428
|
z-index: var(--aqps-z-label, 31) !important;
|
|
@@ -436,9 +435,9 @@
|
|
|
436
435
|
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
|
|
437
436
|
}
|
|
438
437
|
|
|
439
|
-
/* 掴んだ時 (data-active="true"):
|
|
438
|
+
/* 掴んだ時 (data-active="true"): ラベルは拡大せず、光の影で示す。
|
|
439
|
+
拡大した箱は描かれた内容として祖先と文書のスクロールの範囲に数えられ、文書の端に接したラベルを掴むと文書が送れてしまう */
|
|
440
440
|
.period-slider-handle[data-active="true"] .period-slider-tooltip {
|
|
441
|
-
--ps-tooltip-scale: 1.15;
|
|
442
441
|
box-shadow:
|
|
443
442
|
0 0 12px #38bdf8,
|
|
444
443
|
0 0 22px rgba(56, 189, 248, 0.75);
|
|
@@ -469,11 +468,6 @@
|
|
|
469
468
|
bottom: auto !important;
|
|
470
469
|
}
|
|
471
470
|
|
|
472
|
-
.period-slider-track[data-orientation="vertical"] .period-slider-handle[data-active="true"] .period-slider-tooltip,
|
|
473
|
-
.period-slider[data-orientation="vertical"] .period-slider-handle[data-active="true"] .period-slider-tooltip {
|
|
474
|
-
--ps-tooltip-scale: 1.15;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
471
|
.period-slider-handle[data-active="true"] .period-slider-tooltip::after {
|
|
478
472
|
animation: period-slider-kirat 0.3s ease-out 0s forwards;
|
|
479
473
|
}
|
|
@@ -996,7 +990,7 @@
|
|
|
996
990
|
--ps-tooltip-tx: -50%;
|
|
997
991
|
--ps-tooltip-ty: 0px;
|
|
998
992
|
--ps-tooltip-rot: 0deg;
|
|
999
|
-
transform: translate(var(--ps-tooltip-tx), var(--ps-tooltip-ty)) rotate(var(--ps-tooltip-rot))
|
|
993
|
+
transform: translate(var(--ps-tooltip-tx), var(--ps-tooltip-ty)) rotate(var(--ps-tooltip-rot)) !important;
|
|
1000
994
|
}
|
|
1001
995
|
|
|
1002
996
|
.period-slider-handle-vernier[data-vernier-pos="bottom"] .period-slider-tooltip {
|
|
@@ -1008,7 +1002,7 @@
|
|
|
1008
1002
|
--ps-tooltip-tx: -50%;
|
|
1009
1003
|
--ps-tooltip-ty: 0px;
|
|
1010
1004
|
--ps-tooltip-rot: 0deg;
|
|
1011
|
-
transform: translate(var(--ps-tooltip-tx), var(--ps-tooltip-ty)) rotate(var(--ps-tooltip-rot))
|
|
1005
|
+
transform: translate(var(--ps-tooltip-tx), var(--ps-tooltip-ty)) rotate(var(--ps-tooltip-rot)) !important;
|
|
1012
1006
|
}
|
|
1013
1007
|
|
|
1014
1008
|
/* 垂直ノギスにおけるツールチップ (左側 / 右側に既定 8px の数学的クリアランス、垂直中央揃えで相互衝突完全ゼロ) */
|
|
@@ -1021,7 +1015,7 @@
|
|
|
1021
1015
|
--ps-tooltip-tx: 0px;
|
|
1022
1016
|
--ps-tooltip-ty: -50%;
|
|
1023
1017
|
--ps-tooltip-rot: 0deg;
|
|
1024
|
-
transform: translate(var(--ps-tooltip-tx), var(--ps-tooltip-ty)) rotate(var(--ps-tooltip-rot))
|
|
1018
|
+
transform: translate(var(--ps-tooltip-tx), var(--ps-tooltip-ty)) rotate(var(--ps-tooltip-rot)) !important;
|
|
1025
1019
|
}
|
|
1026
1020
|
|
|
1027
1021
|
.period-slider-handle-vernier.is-vertical[data-vernier-pos="right"] .period-slider-tooltip {
|
|
@@ -1033,7 +1027,7 @@
|
|
|
1033
1027
|
--ps-tooltip-tx: 0px;
|
|
1034
1028
|
--ps-tooltip-ty: -50%;
|
|
1035
1029
|
--ps-tooltip-rot: 0deg;
|
|
1036
|
-
transform: translate(var(--ps-tooltip-tx), var(--ps-tooltip-ty)) rotate(var(--ps-tooltip-rot))
|
|
1030
|
+
transform: translate(var(--ps-tooltip-tx), var(--ps-tooltip-ty)) rotate(var(--ps-tooltip-rot)) !important;
|
|
1037
1031
|
}
|
|
1038
1032
|
|
|
1039
1033
|
/* Vernier ツールチップのカラーセマンティクス連動 (マクロ=青系、ミクロ=赤系) */
|
|
@@ -1077,6 +1071,33 @@
|
|
|
1077
1071
|
will-change: transform;
|
|
1078
1072
|
}
|
|
1079
1073
|
|
|
1074
|
+
/* ============================================================= */
|
|
1075
|
+
/* セレクタの欄の大きさ: 3 セレクタのどの変種の欄 (年・年月の select、日付のコンボボックス、 */
|
|
1076
|
+
/* 年・月・日の select、ネイティブの年月・日付の入力) も .period-slider-selector-field を持ち、 */
|
|
1077
|
+
/* この 1 つの規則が公開の --aqps-field-height と --aqps-field-font-size から大きさを決める。 */
|
|
1078
|
+
/* 既定は変数化する前の描画そのもの (高さは字と余白と枠で決まる auto、字は 0.75rem)。 */
|
|
1079
|
+
/* ============================================================= */
|
|
1080
|
+
.period-slider-selector-field {
|
|
1081
|
+
/* 高さを渡されたとき、枠と余白を含めた箱がその高さになるように (preflight の無いホストでも) */
|
|
1082
|
+
box-sizing: border-box;
|
|
1083
|
+
/* 変数から供給する 2 項目は、ホストのユーティリティ層に変数ごと奪われないよう !important (ラベルの見た目と同じ理由) */
|
|
1084
|
+
height: var(--aqps-field-height, auto) !important;
|
|
1085
|
+
font-size: var(--aqps-field-font-size, 0.75rem) !important;
|
|
1086
|
+
/* 行送りは字の大きさの 4/3 倍。字の大きさに整数を掛けてから割るため、既定の 0.75rem でちょうど 16px になる
|
|
1087
|
+
(calc(1 / 0.75) は掛ける前に割り切れない小数へ畳まれ、1/64px 低い 15.984px になる) */
|
|
1088
|
+
line-height: calc(var(--aqps-field-font-size, 0.75rem) * 4 / 3);
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
/* 固定の幅も字の大きさの倍数で持ち、字を大きくしても値が収まり続ける。年は 6 倍 (既定で 72px)、
|
|
1092
|
+
年月と日付は 28/3 倍 (既定で 112px)。em で書くと 28/3 が掛ける前に小数へ畳まれ、既定の幅が 1/64px 狭くなる */
|
|
1093
|
+
.period-slider-selector-field-year {
|
|
1094
|
+
width: calc(var(--aqps-field-font-size, 0.75rem) * 6);
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
.period-slider-selector-field-date {
|
|
1098
|
+
width: calc(var(--aqps-field-font-size, 0.75rem) * 28 / 3);
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1080
1101
|
/* ============================================================= */
|
|
1081
1102
|
/* ネイティブ日付入力 (type="date" / type="month") の字送り */
|
|
1082
1103
|
/* 隣り合うドロップダウン形態と同じ位置に数字が来るようにする。 */
|