dsh-plugin-cyrene-live2d 0.2.9 → 0.3.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.
Files changed (210) hide show
  1. package/README.md +8 -2
  2. package/assets/default-prefs.json +8 -8
  3. package/assets/icon.svg +89 -89
  4. package/assets/locale/notes/en.json +6 -6
  5. package/assets/locale/notes/zh-CN.json +6 -6
  6. package/assets/locale/reminder/en.json +6 -6
  7. package/assets/locale/reminder/zh-CN.json +6 -6
  8. package/assets/model/Cyrene.model3.json +441 -441
  9. package/assets/model/bongo-standard/Live2d_expression0.exp3.json +9 -9
  10. package/assets/model/bongo-standard/cat.cdi3.json +296 -296
  11. package/assets/model/bongo-standard/cat.model3.json +33 -33
  12. package/assets/model/bongo-standard/cat.physics3.json +232 -232
  13. package/assets/model/expressions/0.exp3.json +24 -24
  14. package/assets/model/expressions/1.exp3.json +11 -11
  15. package/assets/model/expressions/10.exp3.json +9 -9
  16. package/assets/model/expressions/11.exp3.json +9 -9
  17. package/assets/model/expressions/2.exp3.json +9 -9
  18. package/assets/model/expressions/3.exp3.json +9 -9
  19. package/assets/model/expressions/4.exp3.json +11 -11
  20. package/assets/model/expressions/5.exp3.json +11 -11
  21. package/assets/model/expressions/6.exp3.json +11 -11
  22. package/assets/model/expressions/7.exp3.json +11 -11
  23. package/assets/model/expressions/8.exp3.json +11 -11
  24. package/assets/model/expressions/9.exp3.json +9 -9
  25. package/assets/model/model.physics3.json +641 -641
  26. package/assets/model/motions/Tick3_3.motion3.json +1347 -1347
  27. package/assets/model/motions//345/212/250/344/275/2346_0.motion3.json +699 -699
  28. package/assets/model/motions//345/212/250/344/275/2346_1.motion3.json +1241 -1241
  29. package/assets/model/motions//345/212/250/344/275/2346_2.motion3.json +1117 -1117
  30. package/assets/model/motions//345/212/250/344/275/2346_3.motion3.json +1106 -1106
  31. package/assets/model/we-q/expressions/FileReferences_Expressions_0_File_0.exp3.json +19 -19
  32. package/assets/model/we-q/expressions/FileReferences_Expressions_1_File_0.exp3.json +41 -41
  33. package/assets/model/we-q/expressions/FileReferences_Expressions_2_File_0.exp3.json +104 -104
  34. package/assets/model/we-q/model0.model3.json +245 -245
  35. package/assets/model/we-q/motions/FileReferences_Motions_shake#1_0_File_0.motion3.json +520 -520
  36. package/assets/model/we-q/motions/FileReferences_Motions_talk#1_0_File_0.motion3.json +499 -499
  37. package/assets/model/we-q/motions/FileReferences_Motions_talk#1_1_File_0.motion3.json +453 -453
  38. package/assets/model/we-q/motions/FileReferences_Motions_wink#1_0_File_0.motion3.json +478 -478
  39. package/assets/model/we-q/motions/FileReferences_Motions_/346/212/254/346/211/213_0_File_0.motion3.json +450 -450
  40. package/assets/model/we-q/motions/FileReferences_Motions_/346/212/254/346/211/213_1_File_0.motion3.json +450 -450
  41. package/assets/model/we-q/motions/idle/FileReferences_Motions_Idleidle_0_File_0.motion3.json +422 -422
  42. package/assets/model/we-q/physics/FileReferences_Physics_0.physic3.json +236 -236
  43. package/assets/runtime/live2dcubismcore.min.js +8 -8
  44. package/assets/stickers.json +84 -84
  45. package/assets/vendor/cubism4.min.js +1 -1
  46. package/assets/vendor/pixi.min.js +9 -9
  47. package/assets/vendor/theme-cyrene-factory.js +4314 -4314
  48. package/assets/vendor/theme-cyrene.js +4317 -4317
  49. package/assets/voice/angry-00.opus +0 -0
  50. package/assets/voice/angry-02.opus +0 -0
  51. package/assets/voice/approval-00.opus +0 -0
  52. package/assets/voice/approval-01.opus +0 -0
  53. package/assets/voice/approval-02.opus +0 -0
  54. package/assets/voice/askAck-00.opus +0 -0
  55. package/assets/voice/away-01.opus +0 -0
  56. package/assets/voice/away-02.opus +0 -0
  57. package/assets/voice/away-03.opus +0 -0
  58. package/assets/voice/away-05.opus +0 -0
  59. package/assets/voice/back-00.opus +0 -0
  60. package/assets/voice/back-01.opus +0 -0
  61. package/assets/voice/backLong-05.opus +0 -0
  62. package/assets/voice/backShort-03.opus +0 -0
  63. package/assets/voice/backShort-04.opus +0 -0
  64. package/assets/voice/backShort-07.opus +0 -0
  65. package/assets/voice/backVeryLong-01.opus +0 -0
  66. package/assets/voice/backVeryLong-02.opus +0 -0
  67. package/assets/voice/backVeryLong-03.opus +0 -0
  68. package/assets/voice/backVeryLong-04.opus +0 -0
  69. package/assets/voice/backVeryLong-05.opus +0 -0
  70. package/assets/voice/backVeryLong-07.opus +0 -0
  71. package/assets/voice/backVeryLong-08.opus +0 -0
  72. package/assets/voice/balLow-00.opus +0 -0
  73. package/assets/voice/balLow-01.opus +0 -0
  74. package/assets/voice/birthday-02.opus +0 -0
  75. package/assets/voice/click-00.opus +0 -0
  76. package/assets/voice/click-01.opus +0 -0
  77. package/assets/voice/click-07.opus +0 -0
  78. package/assets/voice/click-10.opus +0 -0
  79. package/assets/voice/click-11.opus +0 -0
  80. package/assets/voice/click-12.opus +0 -0
  81. package/assets/voice/click-16.opus +0 -0
  82. package/assets/voice/click-17.opus +0 -0
  83. package/assets/voice/click-18.opus +0 -0
  84. package/assets/voice/comfort-03.opus +0 -0
  85. package/assets/voice/comfort-04.opus +0 -0
  86. package/assets/voice/cost10-00.opus +0 -0
  87. package/assets/voice/cost2-00.opus +0 -0
  88. package/assets/voice/cost5-00.opus +0 -0
  89. package/assets/voice/costTurn-01.opus +0 -0
  90. package/assets/voice/costTurn-02.opus +0 -0
  91. package/assets/voice/ctxFull-01.opus +0 -0
  92. package/assets/voice/ctxHigh-00.opus +0 -0
  93. package/assets/voice/dawn-01.opus +0 -0
  94. package/assets/voice/dawn-04.opus +0 -0
  95. package/assets/voice/dawn-06.opus +0 -0
  96. package/assets/voice/dawn-07.opus +0 -0
  97. package/assets/voice/deepWake-03.opus +0 -0
  98. package/assets/voice/deepWake-04.opus +0 -0
  99. package/assets/voice/deepWake-06.opus +0 -0
  100. package/assets/voice/deepWake-07.opus +0 -0
  101. package/assets/voice/done-05.opus +0 -0
  102. package/assets/voice/done-08.opus +0 -0
  103. package/assets/voice/done-09.opus +0 -0
  104. package/assets/voice/done-11.opus +0 -0
  105. package/assets/voice/empty-00.opus +0 -0
  106. package/assets/voice/encourage-02.opus +0 -0
  107. package/assets/voice/failed-01.opus +0 -0
  108. package/assets/voice/failed-05.opus +0 -0
  109. package/assets/voice/failkind-auth-01.opus +0 -0
  110. package/assets/voice/failkind-auth-02.opus +0 -0
  111. package/assets/voice/failkind-ctx-00.opus +0 -0
  112. package/assets/voice/failkind-missing-01.opus +0 -0
  113. package/assets/voice/focusEnd-02.opus +0 -0
  114. package/assets/voice/focusEnd-04.opus +0 -0
  115. package/assets/voice/forgive-00.opus +0 -0
  116. package/assets/voice/hello-00.opus +0 -0
  117. package/assets/voice/hello-03.opus +0 -0
  118. package/assets/voice/hold-00.opus +0 -0
  119. package/assets/voice/idleTap-00.opus +0 -0
  120. package/assets/voice/idleTapLong-02.opus +0 -0
  121. package/assets/voice/lateNight-00.opus +0 -0
  122. package/assets/voice/lateNight-02.opus +0 -0
  123. package/assets/voice/lateNight-03.opus +0 -0
  124. package/assets/voice/lateNight-06.opus +0 -0
  125. package/assets/voice/lateNight-07.opus +0 -0
  126. package/assets/voice/murmur-04.opus +0 -0
  127. package/assets/voice/night-01.opus +0 -0
  128. package/assets/voice/night-03.opus +0 -0
  129. package/assets/voice/night-05.opus +0 -0
  130. package/assets/voice/noon-04.opus +0 -0
  131. package/assets/voice/petArm-02.opus +0 -0
  132. package/assets/voice/petCheek-00.opus +0 -0
  133. package/assets/voice/petCheek-01.opus +0 -0
  134. package/assets/voice/petCheek-02.opus +0 -0
  135. package/assets/voice/petHead-01.opus +0 -0
  136. package/assets/voice/petHead-03.opus +0 -0
  137. package/assets/voice/petHead-04.opus +0 -0
  138. package/assets/voice/praised-01.opus +0 -0
  139. package/assets/voice/praised-03.opus +0 -0
  140. package/assets/voice/question-00.opus +0 -0
  141. package/assets/voice/question-03.opus +0 -0
  142. package/assets/voice/question-04.opus +0 -0
  143. package/assets/voice/question-06.opus +0 -0
  144. package/assets/voice/shy-00.opus +0 -0
  145. package/assets/voice/spot-0-0.opus +0 -0
  146. package/assets/voice/spot-0-1.opus +0 -0
  147. package/assets/voice/spot-0-2.opus +0 -0
  148. package/assets/voice/spot-3-0.opus +0 -0
  149. package/assets/voice/spot-4-0.opus +0 -0
  150. package/assets/voice/spot-4-2.opus +0 -0
  151. package/assets/voice/spot-5-2.opus +0 -0
  152. package/assets/voice/spot-6-0.opus +0 -0
  153. package/assets/voice/spot-6-1.opus +0 -0
  154. package/assets/voice/spot-7-0.opus +0 -0
  155. package/assets/voice/spot-7-2.opus +0 -0
  156. package/assets/voice/spot-8-1.opus +0 -0
  157. package/assets/voice/tagent-00.opus +0 -0
  158. package/assets/voice/thinkFast-01.opus +0 -0
  159. package/assets/voice/thinkFast-02.opus +0 -0
  160. package/assets/voice/thinkFast-03.opus +0 -0
  161. package/assets/voice/thinkSlow-01.opus +0 -0
  162. package/assets/voice/thinkSlow-03.opus +0 -0
  163. package/assets/voice/thinking-01.opus +0 -0
  164. package/assets/voice/thinking-02.opus +0 -0
  165. package/assets/voice/thinking-03.opus +0 -0
  166. package/assets/voice/thinking-09.opus +0 -0
  167. package/assets/voice/tread-00.opus +0 -0
  168. package/assets/voice/tread-01.opus +0 -0
  169. package/assets/voice/trun-02.opus +0 -0
  170. package/assets/voice/tsun-00.opus +0 -0
  171. package/assets/voice/tsun-01.opus +0 -0
  172. package/assets/voice/tsun-04.opus +0 -0
  173. package/assets/voice/twrite-00.opus +0 -0
  174. package/assets/voice/unknown-01.opus +0 -0
  175. package/assets/voice/waitApproval-00.opus +0 -0
  176. package/assets/voice/waitApproval-01.opus +0 -0
  177. package/assets/voice/waitApproval-02.opus +0 -0
  178. package/assets/voice/waitApproval-03.opus +0 -0
  179. package/assets/voice/waitApprovalLate-02.opus +0 -0
  180. package/assets/voice/waitApprovalLate-03.opus +0 -0
  181. package/assets/voice/waitAsk-00.opus +0 -0
  182. package/assets/voice/waitAsk-02.opus +0 -0
  183. package/assets/voice/waitAskLate-03.opus +0 -0
  184. package/assets/voice/wake-03.opus +0 -0
  185. package/assets/voice/wake-04.opus +0 -0
  186. package/assets/voice/wake-05.opus +0 -0
  187. package/assets/voice/wake-06.opus +0 -0
  188. package/lib/client.js +7 -7
  189. package/lib/features/notes.js +172 -172
  190. package/lib/features/reminder.js +216 -216
  191. package/lib/l2d-plan.js +295 -295
  192. package/lib/l2d-tools.js +293 -293
  193. package/lib/ledger.js +163 -163
  194. package/lib/mys/config.js +183 -183
  195. package/lib/mys/ds.js +209 -209
  196. package/lib/mys/http.js +85 -85
  197. package/lib/mys/mys.js +419 -419
  198. package/lib/mys/qr.js +434 -434
  199. package/lib/mys/scheduler.js +206 -206
  200. package/lib/mys/store.js +248 -248
  201. package/lib/mys/tz.js +174 -174
  202. package/lib/wavtrim.js +245 -245
  203. package/lib/worldbook/NOTICE.md +18 -18
  204. package/lib/worldbook/data/Cyrene.md +111 -111
  205. package/lib/worldbook/data/_glossary.md +181 -181
  206. package/lib/worldbook/data/characters.md +289 -289
  207. package/lib/worldbook/data/story.md +130 -130
  208. package/lib/worldbook/data/world.md +182 -182
  209. package/lib/worldbook.js +189 -189
  210. package/package.json +72 -69
package/lib/mys/tz.js CHANGED
@@ -1,174 +1,174 @@
1
- /**
2
- * Time-zone aware helpers for the daily schedule.
3
- *
4
- * The schedule is expressed in the user's local wall clock ("18:00"–"18:30"),
5
- * but the host runs in whatever zone the operating system reports. Everything
6
- * here converts between wall-clock minutes and absolute instants, so DST and
7
- * travel cannot silently shift a window by an hour.
8
- */
9
-
10
- const FORMATTERS = new Map()
11
-
12
- function formatter(timeZone) {
13
- let value = FORMATTERS.get(timeZone)
14
- if (value === undefined) {
15
- value = new Intl.DateTimeFormat('en-US', {
16
- timeZone,
17
- hourCycle: 'h23',
18
- year: 'numeric',
19
- month: '2-digit',
20
- day: '2-digit',
21
- hour: '2-digit',
22
- minute: '2-digit',
23
- second: '2-digit',
24
- })
25
- FORMATTERS.set(timeZone, value)
26
- }
27
- return value
28
- }
29
-
30
- /** Resolve a usable IANA zone name, falling back to the host zone. */
31
- export function resolveTimeZone(candidate) {
32
- if (typeof candidate === 'string' && candidate.trim() !== '') {
33
- try {
34
- formatter(candidate.trim())
35
- return candidate.trim()
36
- } catch {
37
- /* fall through to the host zone */
38
- }
39
- }
40
- try {
41
- const zone = new Intl.DateTimeFormat().resolvedOptions().timeZone
42
- if (typeof zone === 'string' && zone !== '') {
43
- formatter(zone)
44
- return zone
45
- }
46
- } catch {
47
- /* fall through */
48
- }
49
- return 'Asia/Shanghai'
50
- }
51
-
52
- /** Wall-clock fields of one instant in the given zone. */
53
- export function zonedParts(date, timeZone) {
54
- const parts = formatter(timeZone).formatToParts(date)
55
- const field = (type) => {
56
- const found = parts.find((part) => part.type === type)
57
- return found === undefined ? 0 : Number(found.value)
58
- }
59
- return {
60
- year: field('year'),
61
- month: field('month'),
62
- day: field('day'),
63
- hour: field('hour'),
64
- minute: field('minute'),
65
- second: field('second'),
66
- }
67
- }
68
-
69
- /** Offset of the zone at one instant, in milliseconds east of UTC. */
70
- function offsetAt(date, timeZone) {
71
- const parts = zonedParts(date, timeZone)
72
- const asUtc = Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second)
73
- // Drop sub-second noise so the offset lands on a whole second.
74
- return asUtc - Math.floor(date.getTime() / 1000) * 1000
75
- }
76
-
77
- /**
78
- * Convert wall-clock fields in `timeZone` to the instant they name.
79
- * Two passes let the result settle across a DST boundary.
80
- */
81
- export function zonedToInstant(fields, timeZone) {
82
- const { year, month, day, hour, minute, second = 0 } = fields
83
- const guess = Date.UTC(year, month - 1, day, hour, minute, second)
84
- let offset = offsetAt(new Date(guess), timeZone)
85
- let instant = guess - offset
86
- offset = offsetAt(new Date(instant), timeZone)
87
- instant = guess - offset
88
- return new Date(instant)
89
- }
90
-
91
- /** Calendar day key (`YYYY-MM-DD`) of an instant in the given zone. */
92
- export function dayKey(date, timeZone) {
93
- const parts = zonedParts(date, timeZone)
94
- const pad = (value) => String(value).padStart(2, '0')
95
- return `${parts.year}-${pad(parts.month)}-${pad(parts.day)}`
96
- }
97
-
98
- /**
99
- * 米哈游的「游戏日」从凌晨 04:00 开始,不是 00:00。
100
- *
101
- * 为什么不能直接用 `dayKey`:签到接口按游戏日算「今天签没签」。
102
- * 如果按自然日记,凌晨 0–4 点补跑会拿到服务器的 `already`(那边还是昨天),
103
- * 代码又把 `already` 当成成功、写下 `lastRunDate = 今天` —— 等 04:00 真正刷新,
104
- * 它认为今天已经跑过了,于是这一天漏签。
105
- *
106
- * 做法是往前挪 4 小时再取日期:
107
- * 11-02 00:30 → 11-01 20:30 → "2026-11-01"(还是昨天的游戏日)
108
- * 11-02 04:00 → 11-02 00:00 → "2026-11-02"(刷新了)
109
- *
110
- * 注意:整个 mys 模块里「今天」必须只有这一个定义 ——
111
- * 判断该不该跑、记 lastRunDate、角色缓存,三处对不上就会互相打架。
112
- */
113
- const GAME_DAY_SHIFT_MS = 4 * 60 * 60 * 1000
114
- export function gameDayKey(date, timeZone) {
115
- return dayKey(new Date(date.getTime() - GAME_DAY_SHIFT_MS), timeZone)
116
- }
117
-
118
- /** Minutes since local midnight for an instant. */
119
- export function minuteOfDay(date, timeZone) {
120
- const parts = zonedParts(date, timeZone)
121
- return parts.hour * 60 + parts.minute
122
- }
123
-
124
- /** Parse `"HH:MM"` into minutes since midnight, or `null` when invalid. */
125
- export function parseClock(text) {
126
- if (typeof text !== 'string') return null
127
- const match = /^(\d{1,2}):(\d{2})$/.exec(text.trim())
128
- if (match === null) return null
129
- const hour = Number(match[1])
130
- const minute = Number(match[2])
131
- if (hour > 23 || minute > 59) return null
132
- return hour * 60 + minute
133
- }
134
-
135
- /** Format minutes since midnight back to `"HH:MM"`. */
136
- export function formatClock(minutes) {
137
- const bounded = ((Math.round(minutes) % 1440) + 1440) % 1440
138
- const hour = Math.floor(bounded / 60)
139
- const minute = bounded % 60
140
- return `${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}`
141
- }
142
-
143
- /** Add whole days to a `YYYY-MM-DD` key without any zone arithmetic. */
144
- export function shiftDayKey(key, days) {
145
- const [year, month, day] = key.split('-').map(Number)
146
- const next = new Date(Date.UTC(year, month - 1, day + days))
147
- const pad = (value) => String(value).padStart(2, '0')
148
- return `${next.getUTCFullYear()}-${pad(next.getUTCMonth() + 1)}-${pad(next.getUTCDate())}`
149
- }
150
-
151
- /**
152
- * Pick one instant inside a window on a given local day.
153
- *
154
- * `window` is `{ start, end }` in local minutes; a zero-length window becomes
155
- * exactly its start. `random()` must return [0, 1).
156
- */
157
- export function pickInstantInWindow(dayKeyValue, window, timeZone, random) {
158
- const start = Math.min(window.start, window.end)
159
- const end = Math.max(window.start, window.end)
160
- const span = Math.max(0, end - start)
161
- // Half-open window: the last possible moment is one minute before `end`.
162
- const offset = span === 0 ? 0 : Math.floor(random() * span)
163
- const minutes = Math.min(1439, start + offset)
164
- const [year, month, day] = dayKeyValue.split('-').map(Number)
165
- return zonedToInstant(
166
- { year, month, day, hour: Math.floor(minutes / 60), minute: minutes % 60 },
167
- timeZone,
168
- )
169
- }
170
-
171
- /** Human description of a window, for logs and status payloads. */
172
- export function describeWindow(window) {
173
- return `${formatClock(window.start)}–${formatClock(window.end)}`
174
- }
1
+ /**
2
+ * Time-zone aware helpers for the daily schedule.
3
+ *
4
+ * The schedule is expressed in the user's local wall clock ("18:00"–"18:30"),
5
+ * but the host runs in whatever zone the operating system reports. Everything
6
+ * here converts between wall-clock minutes and absolute instants, so DST and
7
+ * travel cannot silently shift a window by an hour.
8
+ */
9
+
10
+ const FORMATTERS = new Map()
11
+
12
+ function formatter(timeZone) {
13
+ let value = FORMATTERS.get(timeZone)
14
+ if (value === undefined) {
15
+ value = new Intl.DateTimeFormat('en-US', {
16
+ timeZone,
17
+ hourCycle: 'h23',
18
+ year: 'numeric',
19
+ month: '2-digit',
20
+ day: '2-digit',
21
+ hour: '2-digit',
22
+ minute: '2-digit',
23
+ second: '2-digit',
24
+ })
25
+ FORMATTERS.set(timeZone, value)
26
+ }
27
+ return value
28
+ }
29
+
30
+ /** Resolve a usable IANA zone name, falling back to the host zone. */
31
+ export function resolveTimeZone(candidate) {
32
+ if (typeof candidate === 'string' && candidate.trim() !== '') {
33
+ try {
34
+ formatter(candidate.trim())
35
+ return candidate.trim()
36
+ } catch {
37
+ /* fall through to the host zone */
38
+ }
39
+ }
40
+ try {
41
+ const zone = new Intl.DateTimeFormat().resolvedOptions().timeZone
42
+ if (typeof zone === 'string' && zone !== '') {
43
+ formatter(zone)
44
+ return zone
45
+ }
46
+ } catch {
47
+ /* fall through */
48
+ }
49
+ return 'Asia/Shanghai'
50
+ }
51
+
52
+ /** Wall-clock fields of one instant in the given zone. */
53
+ export function zonedParts(date, timeZone) {
54
+ const parts = formatter(timeZone).formatToParts(date)
55
+ const field = (type) => {
56
+ const found = parts.find((part) => part.type === type)
57
+ return found === undefined ? 0 : Number(found.value)
58
+ }
59
+ return {
60
+ year: field('year'),
61
+ month: field('month'),
62
+ day: field('day'),
63
+ hour: field('hour'),
64
+ minute: field('minute'),
65
+ second: field('second'),
66
+ }
67
+ }
68
+
69
+ /** Offset of the zone at one instant, in milliseconds east of UTC. */
70
+ function offsetAt(date, timeZone) {
71
+ const parts = zonedParts(date, timeZone)
72
+ const asUtc = Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second)
73
+ // Drop sub-second noise so the offset lands on a whole second.
74
+ return asUtc - Math.floor(date.getTime() / 1000) * 1000
75
+ }
76
+
77
+ /**
78
+ * Convert wall-clock fields in `timeZone` to the instant they name.
79
+ * Two passes let the result settle across a DST boundary.
80
+ */
81
+ export function zonedToInstant(fields, timeZone) {
82
+ const { year, month, day, hour, minute, second = 0 } = fields
83
+ const guess = Date.UTC(year, month - 1, day, hour, minute, second)
84
+ let offset = offsetAt(new Date(guess), timeZone)
85
+ let instant = guess - offset
86
+ offset = offsetAt(new Date(instant), timeZone)
87
+ instant = guess - offset
88
+ return new Date(instant)
89
+ }
90
+
91
+ /** Calendar day key (`YYYY-MM-DD`) of an instant in the given zone. */
92
+ export function dayKey(date, timeZone) {
93
+ const parts = zonedParts(date, timeZone)
94
+ const pad = (value) => String(value).padStart(2, '0')
95
+ return `${parts.year}-${pad(parts.month)}-${pad(parts.day)}`
96
+ }
97
+
98
+ /**
99
+ * 米哈游的「游戏日」从凌晨 04:00 开始,不是 00:00。
100
+ *
101
+ * 为什么不能直接用 `dayKey`:签到接口按游戏日算「今天签没签」。
102
+ * 如果按自然日记,凌晨 0–4 点补跑会拿到服务器的 `already`(那边还是昨天),
103
+ * 代码又把 `already` 当成成功、写下 `lastRunDate = 今天` —— 等 04:00 真正刷新,
104
+ * 它认为今天已经跑过了,于是这一天漏签。
105
+ *
106
+ * 做法是往前挪 4 小时再取日期:
107
+ * 11-02 00:30 → 11-01 20:30 → "2026-11-01"(还是昨天的游戏日)
108
+ * 11-02 04:00 → 11-02 00:00 → "2026-11-02"(刷新了)
109
+ *
110
+ * 注意:整个 mys 模块里「今天」必须只有这一个定义 ——
111
+ * 判断该不该跑、记 lastRunDate、角色缓存,三处对不上就会互相打架。
112
+ */
113
+ const GAME_DAY_SHIFT_MS = 4 * 60 * 60 * 1000
114
+ export function gameDayKey(date, timeZone) {
115
+ return dayKey(new Date(date.getTime() - GAME_DAY_SHIFT_MS), timeZone)
116
+ }
117
+
118
+ /** Minutes since local midnight for an instant. */
119
+ export function minuteOfDay(date, timeZone) {
120
+ const parts = zonedParts(date, timeZone)
121
+ return parts.hour * 60 + parts.minute
122
+ }
123
+
124
+ /** Parse `"HH:MM"` into minutes since midnight, or `null` when invalid. */
125
+ export function parseClock(text) {
126
+ if (typeof text !== 'string') return null
127
+ const match = /^(\d{1,2}):(\d{2})$/.exec(text.trim())
128
+ if (match === null) return null
129
+ const hour = Number(match[1])
130
+ const minute = Number(match[2])
131
+ if (hour > 23 || minute > 59) return null
132
+ return hour * 60 + minute
133
+ }
134
+
135
+ /** Format minutes since midnight back to `"HH:MM"`. */
136
+ export function formatClock(minutes) {
137
+ const bounded = ((Math.round(minutes) % 1440) + 1440) % 1440
138
+ const hour = Math.floor(bounded / 60)
139
+ const minute = bounded % 60
140
+ return `${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}`
141
+ }
142
+
143
+ /** Add whole days to a `YYYY-MM-DD` key without any zone arithmetic. */
144
+ export function shiftDayKey(key, days) {
145
+ const [year, month, day] = key.split('-').map(Number)
146
+ const next = new Date(Date.UTC(year, month - 1, day + days))
147
+ const pad = (value) => String(value).padStart(2, '0')
148
+ return `${next.getUTCFullYear()}-${pad(next.getUTCMonth() + 1)}-${pad(next.getUTCDate())}`
149
+ }
150
+
151
+ /**
152
+ * Pick one instant inside a window on a given local day.
153
+ *
154
+ * `window` is `{ start, end }` in local minutes; a zero-length window becomes
155
+ * exactly its start. `random()` must return [0, 1).
156
+ */
157
+ export function pickInstantInWindow(dayKeyValue, window, timeZone, random) {
158
+ const start = Math.min(window.start, window.end)
159
+ const end = Math.max(window.start, window.end)
160
+ const span = Math.max(0, end - start)
161
+ // Half-open window: the last possible moment is one minute before `end`.
162
+ const offset = span === 0 ? 0 : Math.floor(random() * span)
163
+ const minutes = Math.min(1439, start + offset)
164
+ const [year, month, day] = dayKeyValue.split('-').map(Number)
165
+ return zonedToInstant(
166
+ { year, month, day, hour: Math.floor(minutes / 60), minute: minutes % 60 },
167
+ timeZone,
168
+ )
169
+ }
170
+
171
+ /** Human description of a window, for logs and status payloads. */
172
+ export function describeWindow(window) {
173
+ return `${formatClock(window.start)}–${formatClock(window.end)}`
174
+ }