@aiquants/period-slider 0.10.1 → 0.11.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.
@@ -0,0 +1,175 @@
1
+ /**
2
+ * @fileoverview Lazily derived option domain of a bounded or discrete day-resolution selector.
3
+ *
4
+ * Describes the option set of a date dropdown as an index space instead of an array: the count is
5
+ * computed from the bounds, and the date / machine value / human label of index `i` are derived on
6
+ * demand. A bound change therefore costs O(1) for a continuous range and O(log n) for a discrete
7
+ * one, never O(count), and nothing proportional to the option count is ever allocated.
8
+ *
9
+ * 日単位セレクタの選択肢集合を「配列」ではなく「添字空間」として記述するモジュール。
10
+ * 件数は境界から算出し、添字 i の日付・機械可読値・表示ラベルは要求時に導出する。
11
+ * 境界変更の費用は連続範囲で O(1)、離散集合で O(log n) であり、件数に比例した確保は一切行わない。
12
+ */
13
+ /**
14
+ * Index returned for a date that is not a member of the option set.
15
+ * 選択肢集合に属さない日付に対して返される添字。
16
+ *
17
+ * Every consumer compares against this name rather than against a bare `-1`, so the sentinel has
18
+ * one definition and a caller cannot accidentally treat it as a usable index.
19
+ * 全ての利用側は裸の `-1` ではなく本名で比較する (番兵の定義を 1 箇所に保ち、使える添字として
20
+ * 誤って扱われることを防ぐため)。
21
+ */
22
+ export declare const NO_OPTION_INDEX = -1;
23
+ /**
24
+ * Converts a calendar day to a civil day serial number.
25
+ * 暦日を「日通番」へ変換する関数。
26
+ *
27
+ * Counting days through `Date.UTC` of the *local* calendar parts makes the serial exact across DST
28
+ * transitions and across time zones whose offset is not a whole number of hours: a local day is
29
+ * never 23 or 25 hours long in the serial space, so `serial(a) - serial(b)` is the true number of
30
+ * calendar days between two dates.
31
+ * ローカル暦の構成要素を `Date.UTC` へ渡して数えるため、通番は夏時間の遷移や 30 分刻みの
32
+ * タイムゾーンでも厳密 (通番空間ではローカル日が 23 時間や 25 時間になることがない)。
33
+ *
34
+ * @param date - Date whose local calendar day is counted / ローカル暦日を数える対象の日付
35
+ * @returns Integer day serial, monotonically increasing by 1 per calendar day / 暦日ごとに 1 増える整数の日通番
36
+ */
37
+ export declare const toDaySerial: (date: Date) => number;
38
+ /**
39
+ * Rebuilds the local-midnight Date of a civil day serial number.
40
+ * 日通番からローカル 0 時の Date を復元する関数。
41
+ *
42
+ * @param serial - Integer day serial produced by {@link toDaySerial} / {@link toDaySerial} が返した整数の日通番
43
+ * @returns Date at 00:00:00.000 local time of that calendar day / その暦日のローカル 0 時を指す Date
44
+ */
45
+ export declare const fromDaySerial: (serial: number) => Date;
46
+ /**
47
+ * Renders a date as the machine-readable yyyy-MM-dd value of an option.
48
+ * 日付を選択肢の機械可読値 (yyyy-MM-dd) へ整形する関数。
49
+ *
50
+ * Built from the calendar parts rather than through a date library because this runs once per
51
+ * rendered row and per commit, and a token-driven formatter costs about 19x more for identical
52
+ * output. Output is byte-identical to `date-fns` `format(date, "yyyy-MM-dd")` for every year from 1
53
+ * to 275760; at and below year 0 it emits the ISO 8601 rendering (`0000-01-01`, `-000001-01-01`)
54
+ * rather than the era year the library reports (`0001-01-01`, `0002-01-01`), because ISO 8601 is
55
+ * what this package's value surface promises.
56
+ * 日付ライブラリを介さず暦の構成要素から組むのは、描画行ごと・確定ごとに走る経路であり、
57
+ * トークン解釈型の書式化は同一出力に約 19 倍の費用を要するため。
58
+ * 出力は 1〜275760 年で `date-fns` の `format(date, "yyyy-MM-dd")` とバイト一致。
59
+ * 0 年以下では紀元表記ではなく ISO 8601 の拡張表記を出す (本パッケージの値の面が約束するのは
60
+ * ISO 8601 であるため)。
61
+ *
62
+ * @param date - Date to render / 整形対象の日付
63
+ * @returns Zero-padded yyyy-MM-dd of the local calendar day / ローカル暦日の 0 埋め yyyy-MM-dd
64
+ */
65
+ export declare const formatIsoDay: (date: Date) => string;
66
+ /**
67
+ * Index space of the option set a day-resolution dropdown presents, in descending date order.
68
+ * 日単位ドロップダウンが提示する選択肢集合の添字空間 (日付の降順)。
69
+ *
70
+ * Index 0 is the latest selectable day, matching the descending order the package has always
71
+ * presented. Every accessor is O(1) for a continuous range and O(1) for a discrete one once the
72
+ * index range is resolved; none of them allocates per option.
73
+ * 添字 0 は最新の選択可能日で、本パッケージが従来提示してきた降順と一致。
74
+ * 各アクセサは連続範囲で O(1)、離散集合でも添字範囲解決後は O(1) であり、選択肢ごとの確保を行わない。
75
+ */
76
+ export interface DateOptionDomain {
77
+ /** Number of selectable days; 0 means nothing is selectable / 選択可能日数 (0 は「選択可能日なし」) */
78
+ readonly count: number;
79
+ /** Local-midnight Date of the option at `index` / 添字 index の選択肢が表す日付 (ローカル 0 時) */
80
+ dateAt(index: number): Date;
81
+ /** Machine-readable yyyy-MM-dd of the option at `index` / 添字 index の選択肢の機械可読値 (yyyy-MM-dd) */
82
+ valueAt(index: number): string;
83
+ /** Human-facing option text of the option at `index` / 添字 index の選択肢の表示テキスト */
84
+ labelAt(index: number): string;
85
+ /** Index of a date inside the set, or {@link NO_OPTION_INDEX} when it is not selectable / 集合内での添字 (選択不可なら {@link NO_OPTION_INDEX}) */
86
+ indexOf(date: Date): number;
87
+ }
88
+ /**
89
+ * Builds the option domain of a continuous, bounded day range without materializing it.
90
+ * 連続した境界付き日付範囲の選択肢領域を、実体化せずに構築する関数。
91
+ *
92
+ * @param minBound - Inclusive lower bound, normalized to local midnight / 下限 (ローカル 0 時に正規化済み・含む)
93
+ * @param maxBound - Inclusive upper bound, normalized to local midnight / 上限 (ローカル 0 時に正規化済み・含む)
94
+ * @param locale - BCP 47 language tag enabling Intl label formatting / Intl ラベル書式を有効化する BCP 47 言語タグ
95
+ * @returns Descending option domain of every calendar day in the range / 範囲内全暦日の降順選択肢領域
96
+ */
97
+ export declare const createContinuousDateOptionDomain: (minBound: Date, maxBound: Date, locale: string | undefined) => DateOptionDomain;
98
+ /**
99
+ * Builds the option domain of a discrete date set, addressing the caller's own ascending array.
100
+ * 離散日付集合の選択肢領域を、呼び出し側の昇順配列をそのまま参照して構築する関数。
101
+ *
102
+ * The bounds are applied as an index window `[loIndex, hiIndex]` found by binary search, so a
103
+ * moving bound never copies, filters or re-sorts the array the host owns.
104
+ * 境界は二分探索で求めた添字窓 `[loIndex, hiIndex]` として適用するため、境界が動いても
105
+ * ホストが所有する配列の複製・絞り込み・再ソートは発生しない。
106
+ *
107
+ * @param ascending - Ascending, deduplicated, local-midnight dates owned by the caller / 呼び出し側が所有する昇順・重複排除済みのローカル 0 時日付
108
+ * @param loIndex - First in-bounds index, or a value greater than hiIndex when the window is empty / 境界内の先頭添字 (空窓時は hiIndex より大きい値)
109
+ * @param hiIndex - Last in-bounds index / 境界内の末尾添字
110
+ * @param locale - BCP 47 language tag enabling Intl label formatting / Intl ラベル書式を有効化する BCP 47 言語タグ
111
+ * @returns Descending option domain over the in-bounds window / 境界内の窓を降順に見せる選択肢領域
112
+ */
113
+ export declare const createDiscreteDateOptionDomain: (ascending: readonly Date[], loIndex: number, hiIndex: number, locale: string | undefined) => DateOptionDomain;
114
+ /**
115
+ * Option domain presented when no day is selectable at all.
116
+ * 選択可能な日が 1 つも無い場合に提示される選択肢領域。
117
+ *
118
+ * The three accessors throw rather than inventing a date, because an empty domain has no index to
119
+ * serve and a substituted value would propagate a day the user never chose.
120
+ * 3 つのアクセサは日付を捏造せず送出する (空領域には提供できる添字が無く、代替値は利用者が
121
+ * 選んでいない日を伝播させるため)。
122
+ */
123
+ export declare const EMPTY_DATE_OPTION_DOMAIN: DateOptionDomain;
124
+ /**
125
+ * Index window of a discrete ascending date list that falls inside the resolved bounds.
126
+ * 昇順離散日付配列のうち、解決済み境界の内側に入る添字窓。
127
+ */
128
+ export interface DiscreteIndexWindow {
129
+ /** First in-bounds index / 境界内の先頭添字 */
130
+ readonly loIndex: number;
131
+ /** Last in-bounds index; smaller than loIndex when the window is empty / 境界内の末尾添字 (空窓時は loIndex より小さい) */
132
+ readonly hiIndex: number;
133
+ }
134
+ /**
135
+ * Finds the index window of a discrete ascending date list that falls inside the resolved bounds.
136
+ * 昇順離散日付配列のうち、解決済み境界の内側に入る添字窓を求める関数。
137
+ *
138
+ * @param ascending - Ascending, deduplicated dates / 昇順・重複排除済みの日付
139
+ * @param minBound - Inclusive lower bound, or null when unbounded / 下限 (無制限時は null・含む)
140
+ * @param maxBound - Inclusive upper bound, or null when unbounded / 上限 (無制限時は null・含む)
141
+ * @returns First and last in-bounds index; `loIndex > hiIndex` when the window is empty / 境界内の先頭・末尾添字 (空窓時は loIndex > hiIndex)
142
+ */
143
+ export declare const resolveDiscreteIndexWindow: (ascending: readonly Date[], minBound: Date | null, maxBound: Date | null) => DiscreteIndexWindow;
144
+ /**
145
+ * Finds the nearest date of a discrete set strictly on one side of a reference time.
146
+ * 離散集合のうち、基準時刻の片側にある最も近い日付を求める関数。
147
+ *
148
+ * Binary search inside the in-bounds window replaces the linear scan a stepper button would
149
+ * otherwise run per render, which is what makes a discrete set of any size cost the same.
150
+ * 境界内の窓に対する二分探索が、ステッパーボタンが本来レンダーごとに行う線形走査を置き換える
151
+ * (これにより任意の大きさの離散集合が同一費用になる)。
152
+ *
153
+ * @param ascending - Ascending, deduplicated dates / 昇順・重複排除済みの日付
154
+ * @param loIndex - First in-bounds index / 境界内の先頭添字
155
+ * @param hiIndex - Last in-bounds index / 境界内の末尾添字
156
+ * @param time - Reference epoch milliseconds, excluded from the result / 基準のエポックミリ秒 (結果から除外)
157
+ * @param direction - -1 for the latest earlier date, 1 for the earliest later date / -1 で直前の日付、1 で直後の日付
158
+ * @returns Neighbouring date, or null when the window holds none on that side / 隣接日付 (その側に無い場合は null)
159
+ */
160
+ export declare const findDiscreteNeighbour: (ascending: readonly Date[], loIndex: number, hiIndex: number, time: number, direction: -1 | 1) => Date | null;
161
+ /**
162
+ * Normalizes, deduplicates and sorts the discrete allowed dates without applying the bounds.
163
+ * 離散日付配列を正規化・重複排除・昇順ソートする関数 (境界は適用しない)。
164
+ *
165
+ * Leaving the bounds out is what lets a moving bound cost O(log n): the array is derived once per
166
+ * `allowedDates` content, and the bounds are then an index window over it.
167
+ * 境界を含めないことが、動く境界の費用を O(log n) にする鍵
168
+ * (配列は `allowedDates` の内容ごとに 1 度導出し、境界はその上の添字窓になる)。
169
+ *
170
+ * @param allowedDates - Caller supplied discrete dates / 呼び出し側が指定した離散日付
171
+ * @param assertValid - Per-entry validator invoked with the entry index / 要素添字付きで呼ばれる要素検証関数
172
+ * @returns Ascending, deduplicated local-midnight dates / 昇順・重複排除済みのローカル 0 時日付
173
+ */
174
+ export declare const normalizeAllowedDates: (allowedDates: readonly Date[], assertValid: (index: number, entry: Date) => void) => Date[];
175
+ //# sourceMappingURL=dateOptionDomain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dateOptionDomain.d.ts","sourceRoot":"","sources":["../src/dateOptionDomain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAgBH;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,KAAK,CAAA;AAEjC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,KAAG,MAMxC,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GAAI,QAAQ,MAAM,KAAG,IAO9C,CAAA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,IAAI,KAAG,MAIzC,CAAA;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC7B,uFAAuF;IACvF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,mFAAmF;IACnF,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,8FAA8F;IAC9F,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;IAC9B,+EAA+E;IAC/E,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;IAC9B,sIAAsI;IACtI,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAAA;CAC9B;AAED;;;;;;;;GAQG;AACH,eAAO,M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