@aiquants/period-slider 0.22.0 → 0.23.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 +14 -0
- package/README.md +6 -4
- package/dist/PeriodSlider.d.ts +2 -0
- package/dist/PeriodSlider.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +2274 -2267
- package/package.json +2 -2
- package/src/PeriodSlider.tsx +58 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiquants/period-slider",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Customizable period slider and year/month/date selectors for React",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"**/*.css"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"date-fns": "^4.1.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@aiquants/virtualscroll": "^3.23.
|
|
43
|
+
"@aiquants/virtualscroll": "^3.23.1",
|
|
44
44
|
"@playwright/test": "^1.64.1",
|
|
45
45
|
"@tailwindcss/cli": "^4.1.18",
|
|
46
46
|
"@tailwindcss/vite": "^4.1.18",
|
package/src/PeriodSlider.tsx
CHANGED
|
@@ -284,6 +284,8 @@ export interface BasePeriodSliderProps {
|
|
|
284
284
|
labelPosition?: PeriodSliderLabelPosition
|
|
285
285
|
/** Whether to automatically slant labels when a pair comes close, in range mode and on both vernier rails (default: true) / Range モードとノギスの両レールで、対が接近した時に自動斜め表示するか (既定: true) */
|
|
286
286
|
autoSlantLabels?: boolean
|
|
287
|
+
/** Stands the one label a pair holding the same value leaves upright on its knob, level with the upright labels of a pair that stands apart, instead of at the angle the approach ramped up to. Such a label reads neither the room nor `labelCeiling` / `labelFloor`, a pair holding two values slants as before, and the angle jumps where the pair merges or separates; a slider that does not slant is unaffected (default: false) / 同じ値に重なった対の残った 1 枚を、接近で上がった角度のまま立てず、離れた対の直立のラベルと同じ高さでつまみの中心に直立させるか。その 1 枚は余白も `labelCeiling` / `labelFloor` も読まず、違う値の対は今までどおり傾き、角度は畳む・離れる所で飛ぶ。傾けないスライダーには効かない (既定: false) */
|
|
288
|
+
keepMergedLabelUpright?: boolean
|
|
287
289
|
/** Element whose bottom edge the slanted labels of a horizontal slider are never drawn above, besides the viewport and every ancestor that clips them; null or omitted names none, an element not in the document bounds nothing, and anything else (a ref object included) throws RangeError / 横向きのスライダーの傾けたラベルを、その下端より上へ描かない要素 (画面の端とラベルを切る祖先に加える。null・省略は無し、文書に無い要素は何も区切らず、それ以外 (ref オブジェクトを含む) は RangeError) */
|
|
288
290
|
labelCeiling?: Element | null
|
|
289
291
|
/** Element whose top edge the slanted labels of a horizontal slider are never drawn below, besides the viewport and every ancestor that clips them; null or omitted names none, an element not in the document bounds nothing, and anything else (a ref object included) throws RangeError / 横向きのスライダーの傾けたラベルを、その上端より下へ描かない要素 (画面の端とラベルを切る祖先に加える。null・省略は無し、文書に無い要素は何も区切らず、それ以外 (ref オブジェクトを含む) は RangeError) */
|
|
@@ -2000,6 +2002,48 @@ export const calculateLabelSlant = (lowPct: number, highPct: number, trackWidthP
|
|
|
2000
2002
|
*/
|
|
2001
2003
|
const withoutHorizontalPush = (geometry: LabelSlantResult): LabelSlantResult => ({ ...geometry, lowOffsetX: 0, highOffsetX: 0 })
|
|
2002
2004
|
|
|
2005
|
+
/**
|
|
2006
|
+
* What the slant of one label pair depends on besides its two positions and its geometry.
|
|
2007
|
+
* 1 対のラベルの傾斜が、2 つの位置と幾何のほかに依存するもの。
|
|
2008
|
+
*/
|
|
2009
|
+
interface PairSlantInput {
|
|
2010
|
+
/** Measured track length in pixels / 実測トラック長 (ピクセル) */
|
|
2011
|
+
trackLengthPx: number
|
|
2012
|
+
/** Side of the track the pair's labels stand on / 対のラベルが載るトラックの側 */
|
|
2013
|
+
labelPosition: PeriodSliderLabelPosition
|
|
2014
|
+
/** Whether the pair holds one value and therefore shows one label / 対が同一値で 1 枚だけ見えている状態か */
|
|
2015
|
+
isMerged: boolean
|
|
2016
|
+
/** Whether a merged pair's one label stands upright instead of at the ramp's angle / 畳んだ対の 1 枚を、ランプの角度でなく直立で立てるか */
|
|
2017
|
+
keepMergedLabelUpright: boolean
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
/**
|
|
2021
|
+
* Solves the slant of one label pair for two positions, through what merging changes about it.
|
|
2022
|
+
* 1 対のラベルの傾斜を、畳むことで変わるものを通して 2 つの位置に対して解く関数。
|
|
2023
|
+
*
|
|
2024
|
+
* Every reader of a pair's slant goes through here, so a merged pair the host keeps upright is upright for all of them:
|
|
2025
|
+
* the pair's own placement, both tiers of it, and the other vernier rail, which stands a flipped pair beyond these labels.
|
|
2026
|
+
* Such a pair takes the upright baseline itself rather than a rotation of 0, so it stands where an upright pair stands and
|
|
2027
|
+
* leaves the room out of it, exactly as a pair standing apart does.
|
|
2028
|
+
* 対の傾斜を読む側はすべてここを通る。そのためホストが直立を求めた畳んだ対は、対自身の配置 (両層とも) にも、倒れた対をこのラベルの
|
|
2029
|
+
* 外へ積むもう一方のノギスのレールにも直立に見える。この対は角度 0 の回転ではなく直立の基準配置そのものを取るため、直立の対と同じ位置に
|
|
2030
|
+
* 立ち、離れた対と同じく余白に関わらない。
|
|
2031
|
+
*
|
|
2032
|
+
* @param lowPct - Lower label position along the track in percent / トラック上の下限ラベル位置 (百分率)
|
|
2033
|
+
* @param highPct - Upper label position along the track in percent / トラック上の上限ラベル位置 (百分率)
|
|
2034
|
+
* @param pair - Everything the slant depends on besides the two positions and the geometry / 2 つの位置と幾何のほかに傾斜が依存するもの一式
|
|
2035
|
+
* @param config - Geometry the pair is solved with / 対を解く幾何
|
|
2036
|
+
* @returns Geometry of the pair / 対の幾何
|
|
2037
|
+
*/
|
|
2038
|
+
const solvePairSlant = (lowPct: number, highPct: number, pair: PairSlantInput, config: LabelSlantConfig | undefined): LabelSlantResult => {
|
|
2039
|
+
if (pair.isMerged && pair.keepMergedLabelUpright) return buildHorizontalSlantResult(pair.labelPosition, config)
|
|
2040
|
+
const solved = calculateLabelSlant(lowPct, highPct, pair.trackLengthPx, pair.labelPosition, config)
|
|
2041
|
+
// 併合時に残る 1 枚は前面側であり、front は焦点・押下・交差のたび入れ替わる。押し退けを残すと
|
|
2042
|
+
// 唯一のラベルが ±shiftX の間を飛び、離す相手も居ない。角度と垂直オフセットは 90deg のラベルを
|
|
2043
|
+
// つまみから逃がすために必要なので保持し、接近から一致まで角度も位置も連続させる
|
|
2044
|
+
return pair.isMerged ? withoutHorizontalPush(solved) : solved
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2003
2047
|
/**
|
|
2004
2048
|
* How a macro window moved, which is what decides whether the micro selection keeps its length.
|
|
2005
2049
|
* マクロ窓の動き方 (ミクロ選択が長さを保つかを決めるもの)。
|
|
@@ -3197,8 +3241,7 @@ const solveVernierPairPlacement = (rail: "macro" | "micro", lowRatio: number, hi
|
|
|
3197
3241
|
// 直立のラベルの中心は、自分の側の基準線から高さの半分の所に居る
|
|
3198
3242
|
if (!input.isSlantable) return { slant: baseline, lowStyle: undefined, highStyle: undefined, lowLeaderStyle: undefined, highLeaderStyle: undefined, centreFromAnchorPx: Math.abs(baseline.lowOffsetY) - resolveLabelClearancePx(config), placements: null }
|
|
3199
3243
|
|
|
3200
|
-
const
|
|
3201
|
-
const slant = input.isMerged ? withoutHorizontalPush(solved) : solved
|
|
3244
|
+
const slant = solvePairSlant(lowRatio * 100, highRatio * 100, input, config)
|
|
3202
3245
|
const prefixes = DRAG_LABEL_VARIABLE_PREFIXES[rail]
|
|
3203
3246
|
// 範囲領域が読むのは、ラベルが立つ側の基準線からの到達距離。反対側へ倒れた対は、もう一方のレールの基準線の側に立つ
|
|
3204
3247
|
const anchorLinePx = fit !== null && slant.isFlipped ? fit.oppositeAnchorPx : resolveLabelClearancePx(config)
|
|
@@ -3256,15 +3299,9 @@ const resolveVernierRoomFit = (input: VernierPairPlacementInput): { config: Labe
|
|
|
3256
3299
|
* Everything a vernier label pair's placement depends on besides the two positions it is solved for.
|
|
3257
3300
|
* ノギスのラベルの対の配置が、解く対象の 2 つの位置以外に依存するもの一式。
|
|
3258
3301
|
*/
|
|
3259
|
-
interface VernierPairPlacementInput {
|
|
3260
|
-
/** Measured track length in pixels / 実測トラック長 (ピクセル) */
|
|
3261
|
-
trackLengthPx: number
|
|
3262
|
-
/** Side of the track this rail draws its labels on / このレールがラベルを描くトラックの側 */
|
|
3263
|
-
labelPosition: PeriodSliderLabelPosition
|
|
3302
|
+
interface VernierPairPlacementInput extends PairSlantInput {
|
|
3264
3303
|
/** Measured geometry of this pair, or undefined while unmeasured / この対の実測幾何 (未実測時は undefined) */
|
|
3265
3304
|
config: LabelSlantConfig | undefined
|
|
3266
|
-
/** Whether the pair holds one value and therefore shows one label / 対が同一値で 1 枚だけ見えている状態か */
|
|
3267
|
-
isMerged: boolean
|
|
3268
3305
|
/** Whether this rail may slant at all / このレールが傾斜してよいか */
|
|
3269
3306
|
isSlantable: boolean
|
|
3270
3307
|
/** Room around the rail the labels must stay within, or undefined while unmeasured / ラベルが収まるべきレールの周りの余白 (未実測時は undefined) */
|
|
@@ -3288,10 +3325,11 @@ interface VernierOppositeLabels {
|
|
|
3288
3325
|
|
|
3289
3326
|
/**
|
|
3290
3327
|
* Resolves the other vernier rail's labels as a pair that may stand across them sees them: where they start and how far
|
|
3291
|
-
* they reach, standing on their own side, rotated as far as their anti-collision ramp asks
|
|
3292
|
-
* scale - that is, before the room is read.
|
|
3328
|
+
* 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) and drawn at the emphasised scale - that is, before the room is read.
|
|
3293
3330
|
* 反対側へ立ちうる対から見た、もう一方のノギスのレールのラベル (どこから始まり、どこまで届くか) を解決する関数。
|
|
3294
|
-
* ラベルは余白を読む前の姿 (
|
|
3331
|
+
* ラベルは余白を読む前の姿 (自分の側に立ち、衝突回避のランプが求める角度まで回り (ホストが直立を求めた畳んだ対は直立)、
|
|
3332
|
+
* 強調の倍率で描かれる) で取る。
|
|
3295
3333
|
*
|
|
3296
3334
|
* That is where they are whenever the pair may stand across them: the pair moves over only when it fits beyond those
|
|
3297
3335
|
* labels, and the other rail's labels, needing less of the same room, then fit on their own side unmoved and at the full
|
|
@@ -3307,7 +3345,7 @@ interface VernierOppositeLabels {
|
|
|
3307
3345
|
*/
|
|
3308
3346
|
const resolveVernierOppositeLabels = (lowRatio: number, highRatio: number, other: Omit<VernierPairPlacementInput, "opposite">, box: MeasuredBoxPx | null): VernierOppositeLabels | null => {
|
|
3309
3347
|
if (other.anchor === null || box === null) return null
|
|
3310
|
-
const angleDeg = other.isSlantable ?
|
|
3348
|
+
const angleDeg = other.isSlantable ? solvePairSlant(lowRatio * 100, highRatio * 100, other, other.config).lowAngleDeg : 0
|
|
3311
3349
|
// 強調中のラベルは中心を基準に拡大されるため、外縁は中心から倍率ぶん遠くなる (余白の判定と同じ形)
|
|
3312
3350
|
return { anchorPx: other.anchor.anchorPx, reachPx: (1 + LABEL_EMPHASIS_SCALE) * resolveRotatedHalfExtents(box.widthPx, box.heightPx, angleDeg).acrossPx }
|
|
3313
3351
|
}
|
|
@@ -3335,19 +3373,13 @@ interface FlatPairPlacement {
|
|
|
3335
3373
|
* Everything the flat rail's label placement depends on besides the two positions it is solved for.
|
|
3336
3374
|
* 平レールのラベル配置が、解く対象の 2 つの位置以外に依存するもの一式。
|
|
3337
3375
|
*/
|
|
3338
|
-
interface FlatPairPlacementInput {
|
|
3376
|
+
interface FlatPairPlacementInput extends PairSlantInput {
|
|
3339
3377
|
/** Whether one handle selects a single point / つまみ 1 つで時点を選ぶ形態か */
|
|
3340
3378
|
isPointMode: boolean
|
|
3341
3379
|
/** Whether the slider is drawn vertically / 縦向き描画か */
|
|
3342
3380
|
isVertical: boolean
|
|
3343
3381
|
/** Whether the host allows the anti-collision rotation / ホストが重なり回避の回転を許すか */
|
|
3344
3382
|
autoSlantLabels: boolean
|
|
3345
|
-
/** Whether the pair holds one value and therefore shows one label / 対が同一値で 1 枚だけ見えている状態か */
|
|
3346
|
-
isMerged: boolean
|
|
3347
|
-
/** Measured track length in pixels / 実測トラック長 (ピクセル) */
|
|
3348
|
-
trackLengthPx: number
|
|
3349
|
-
/** Side of the track the labels sit on / ラベルが載るトラックの側 */
|
|
3350
|
-
labelPosition: PeriodSliderLabelPosition
|
|
3351
3383
|
/** Measured geometry of the pair, or undefined while unmeasured / 対の実測幾何 (未実測時は undefined) */
|
|
3352
3384
|
config: LabelSlantConfig | undefined
|
|
3353
3385
|
/** Room around the rail the labels must stay within, or undefined while unmeasured / ラベルが収まるべきレールの周りの余白 (未実測時は undefined) */
|
|
@@ -3386,11 +3418,7 @@ const solveFlatPairPlacement = (lowPct: number, highPct: number, input: FlatPair
|
|
|
3386
3418
|
if (isSolvable) {
|
|
3387
3419
|
// 強調中の倍率も余白の判定へ渡す。等倍で判定すると、掴んだ瞬間に拡大したラベルだけが余白の外へはみ出す
|
|
3388
3420
|
const config = input.config === undefined || input.room === undefined ? input.config : { ...input.config, room: input.room, drawnScale: LABEL_EMPHASIS_SCALE }
|
|
3389
|
-
|
|
3390
|
-
// 併合時に残る 1 枚は前面側であり、front は焦点・押下・交差のたび入れ替わる。押し退けを残すと
|
|
3391
|
-
// 唯一のラベルが ±shiftX の間を飛び、離す相手も居ない。角度と垂直オフセットは 90deg のラベルを
|
|
3392
|
-
// つまみから逃がすために必要なので保持し、接近から一致まで角度も位置も連続させる
|
|
3393
|
-
slant = input.isMerged ? withoutHorizontalPush(solved) : solved
|
|
3421
|
+
slant = solvePairSlant(lowPct, highPct, input, config)
|
|
3394
3422
|
}
|
|
3395
3423
|
|
|
3396
3424
|
const prefixes = DRAG_LABEL_VARIABLE_PREFIXES.flat
|
|
@@ -3493,6 +3521,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3493
3521
|
tooltipStyle = "always",
|
|
3494
3522
|
labelPosition = "top",
|
|
3495
3523
|
autoSlantLabels = true,
|
|
3524
|
+
keepMergedLabelUpright = false,
|
|
3496
3525
|
showLabelLeaderLines = false,
|
|
3497
3526
|
isVertical = false,
|
|
3498
3527
|
hideConnectBar = false,
|
|
@@ -4186,7 +4215,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
4186
4215
|
// ラベルを離す距離が「描かれている距離」から外れることが構造的に起こらない。
|
|
4187
4216
|
// マクロとミクロは同じトラックの上で比率も単位空間もラベル幅も異なるため、対ごとに独立して解く
|
|
4188
4217
|
const labelRoom = labelSurroundings === null ? undefined : labelSurroundings.room
|
|
4189
|
-
const flatPlacementInput: FlatPairPlacementInput = { isPointMode, isVertical, autoSlantLabels, isMerged: isLabelMerged, trackLengthPx: trackLength, labelPosition, config: labelSlantConfig, room: labelRoom }
|
|
4218
|
+
const flatPlacementInput: FlatPairPlacementInput = { isPointMode, isVertical, autoSlantLabels, isMerged: isLabelMerged, keepMergedLabelUpright, trackLengthPx: trackLength, labelPosition, config: labelSlantConfig, room: labelRoom }
|
|
4190
4219
|
// 時点形態のミクロはラベルが 1 枚で、その 1 枚の箱がレールのラベルの箱になる。傾かない時点のラベルも、
|
|
4191
4220
|
// 自分の側の基準線から実寸の高さの半分の所に中心を置くため、その箱から幾何を組む (既定の高さを捏造しない)
|
|
4192
4221
|
const macroLabelBox = resolvePairBox(macroLowLabelBox, macroHighLabelBox)
|
|
@@ -4196,6 +4225,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
4196
4225
|
labelPosition: macroRailLabelPosition,
|
|
4197
4226
|
config: buildBoxSlantConfig(macroLabelBox),
|
|
4198
4227
|
isMerged: isVernierMacroLabelMerged,
|
|
4228
|
+
keepMergedLabelUpright,
|
|
4199
4229
|
isSlantable: isVernierSlantable,
|
|
4200
4230
|
room: labelRoom,
|
|
4201
4231
|
anchor: labelSurroundings === null ? null : labelSurroundings.macro,
|
|
@@ -4205,6 +4235,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
4205
4235
|
labelPosition: microRailLabelPosition,
|
|
4206
4236
|
config: buildBoxSlantConfig(microLabelBox),
|
|
4207
4237
|
isMerged: isVernierMicroLabelMerged,
|
|
4238
|
+
keepMergedLabelUpright,
|
|
4208
4239
|
isSlantable: isMicroPairSlantable,
|
|
4209
4240
|
room: labelRoom,
|
|
4210
4241
|
anchor: labelSurroundings === null ? null : labelSurroundings.micro,
|
|
@@ -6262,6 +6293,7 @@ export const arePeriodSliderPropsEqual = (prev: PeriodSliderProps, next: PeriodS
|
|
|
6262
6293
|
if (
|
|
6263
6294
|
prev.labelPosition !== next.labelPosition ||
|
|
6264
6295
|
prev.autoSlantLabels !== next.autoSlantLabels ||
|
|
6296
|
+
prev.keepMergedLabelUpright !== next.keepMergedLabelUpright ||
|
|
6265
6297
|
// 境の要素は同一性で比べる。同じ要素の中身や位置の変化は Props ではなく測定が追う
|
|
6266
6298
|
prev.labelCeiling !== next.labelCeiling ||
|
|
6267
6299
|
prev.labelFloor !== next.labelFloor ||
|