@celestia-island/hikari 0.55.241 → 0.55.243
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/package.json +1 -1
- package/src/components/HkCrossfade.test.tsx +48 -0
- package/src/components/HkCrossfade.tsx +45 -3
- package/src/components/HkFaceShell.rail.test.tsx +37 -0
- package/src/components/HkSidebar.rail.test.tsx +36 -0
- package/src/components/HkSidebarRailSwap.tsx +11 -5
- package/src/components/HkSolarLocationSetting.scss +91 -0
- package/src/components/HkSolarLocationSetting.test.tsx +379 -0
- package/src/components/HkSolarLocationSetting.tsx +267 -0
- package/src/composables/useSidebarRail.test.ts +158 -1
- package/src/composables/useSidebarRail.ts +72 -4
- package/src/i18n/locales/ar/platform.json +14 -0
- package/src/i18n/locales/de/platform.json +14 -0
- package/src/i18n/locales/en/platform.json +14 -0
- package/src/i18n/locales/es/platform.json +14 -0
- package/src/i18n/locales/fr/platform.json +14 -0
- package/src/i18n/locales/ja/platform.json +14 -0
- package/src/i18n/locales/ko/platform.json +14 -0
- package/src/i18n/locales/pt/platform.json +14 -0
- package/src/i18n/locales/ru/platform.json +14 -0
- package/src/i18n/locales/zh-Hans/platform.json +14 -0
- package/src/i18n/locales/zh-Hant/platform.json +14 -0
- package/src/index.ts +8 -0
- package/src/theme/index.ts +12 -2
- package/src/theme/useSolarTime.test.ts +295 -4
- package/src/theme/useSolarTime.ts +273 -27
- package/src/theme/useTheme.test.ts +19 -0
- package/src/theme/useTheme.ts +15 -1
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
// AI-generated: developed with the ZCode agent (model GLM-5.3); human-directed.
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { createApp, h, nextTick } from "vue";
|
|
4
|
+
|
|
5
|
+
import { HkSolarLocationSetting } from "./HkSolarLocationSetting";
|
|
6
|
+
import { setLocale } from "../i18n/context";
|
|
7
|
+
import {
|
|
8
|
+
SOLAR_LOCATION_STRATEGY_STORAGE_KEY,
|
|
9
|
+
SOLAR_MANUAL_LOCATION_STORAGE_KEY,
|
|
10
|
+
listTimeZones,
|
|
11
|
+
manualLocationOf,
|
|
12
|
+
setSolarLocationStrategy,
|
|
13
|
+
setSolarManualLocation,
|
|
14
|
+
solarLocationStrategy,
|
|
15
|
+
solarManualLocation,
|
|
16
|
+
systemTimeZoneId,
|
|
17
|
+
type SolarLocationStrategy,
|
|
18
|
+
} from "../theme/useSolarTime";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* HkSolarLocationSetting — the solar clock's location-strategy row.
|
|
22
|
+
* The strategy engine (theme/useSolarTime.ts) has its own suite; these
|
|
23
|
+
* cases pin the COMPONENT contract: the live summary row, the secondary
|
|
24
|
+
* HkModal editor (strategy tabs / IANA zone select / explicit
|
|
25
|
+
* hemisphere), OK applying through setSolarManualLocation →
|
|
26
|
+
* setSolarLocationStrategy → refreshThemeClock with storage evidence,
|
|
27
|
+
* and cancel leaving the engine untouched.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
31
|
+
const appliedEvents: SolarLocationStrategy[] = [];
|
|
32
|
+
|
|
33
|
+
const ORIGINAL_WIDTH = window.innerWidth;
|
|
34
|
+
|
|
35
|
+
function setViewportWidth(px: number): void {
|
|
36
|
+
Object.defineProperty(window, "innerWidth", {
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: px,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function resetEngineState(): void {
|
|
44
|
+
// Back to the offline default; manual config cleared. The setters are
|
|
45
|
+
// the engine's own reset surface (they heal refs AND storage).
|
|
46
|
+
setSolarLocationStrategy("timezone");
|
|
47
|
+
setSolarManualLocation(null);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function mountSetting(): HTMLElement {
|
|
51
|
+
const container = document.createElement("div");
|
|
52
|
+
document.body.appendChild(container);
|
|
53
|
+
const app = createApp({
|
|
54
|
+
render: () =>
|
|
55
|
+
h(HkSolarLocationSetting, {
|
|
56
|
+
onApplied: (strategy: SolarLocationStrategy) => {
|
|
57
|
+
appliedEvents.push(strategy);
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
});
|
|
61
|
+
app.mount(container);
|
|
62
|
+
mounts.push({ app, container });
|
|
63
|
+
return container;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function settle(): Promise<void> {
|
|
67
|
+
await nextTick();
|
|
68
|
+
// Surface transitions (modal enter/leave, tab swaps) resolve through
|
|
69
|
+
// short macrotask windows in happy-dom.
|
|
70
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
71
|
+
await nextTick();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function rowSummary(container: HTMLElement): HTMLElement {
|
|
75
|
+
const el = container.querySelector<HTMLElement>(".hk-solar-summary");
|
|
76
|
+
expect(el, "summary row renders").toBeTruthy();
|
|
77
|
+
return el!;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function editButton(container: HTMLElement): HTMLButtonElement {
|
|
81
|
+
const btn = container.querySelector<HTMLButtonElement>(".hk-solar-edit");
|
|
82
|
+
expect(btn, "edit button renders").toBeTruthy();
|
|
83
|
+
return btn!;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The modal chrome teleports to document.body (HkModal Teleport). */
|
|
87
|
+
function modalHeader(): HTMLElement | null {
|
|
88
|
+
return document.body.querySelector<HTMLElement>(".hk-modal-header");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function strategyTriggers(): HTMLButtonElement[] {
|
|
92
|
+
// The strategy strip is the DIRECT child group of the editor body —
|
|
93
|
+
// scoped so the hemisphere strip never pollutes the query.
|
|
94
|
+
return [
|
|
95
|
+
...document.body.querySelectorAll<HTMLButtonElement>(
|
|
96
|
+
".hk-solar-editor > .hk-tabs .hk-tabs-trigger",
|
|
97
|
+
),
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function hemisphereTriggers(): HTMLButtonElement[] {
|
|
102
|
+
return [
|
|
103
|
+
...document.body.querySelectorAll<HTMLButtonElement>(
|
|
104
|
+
".hk-solar-hemisphere .hk-tabs-trigger",
|
|
105
|
+
),
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function activeStrategyOf(triggers: HTMLButtonElement[]): string | undefined {
|
|
110
|
+
return triggers.find((b) => b.hasAttribute("data-active"))?.textContent ?? undefined;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function footerButton(label: string): HTMLButtonElement {
|
|
114
|
+
const btn = [...document.body.querySelectorAll<HTMLButtonElement>(".hk-modal-footer button")]
|
|
115
|
+
.find((b) => b.textContent?.trim() === label);
|
|
116
|
+
expect(btn, `footer button "${label}" renders`).toBeTruthy();
|
|
117
|
+
return btn!;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function clickStrategyTab(label: string): void {
|
|
121
|
+
const trigger = strategyTriggers().find((b) => b.textContent?.trim() === label);
|
|
122
|
+
expect(trigger, `strategy tab "${label}" renders`).toBeTruthy();
|
|
123
|
+
trigger!.click();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function clickStrategy(key: "timezone" | "ip" | "manual"): void {
|
|
127
|
+
clickStrategyTab({ timezone: "Time zone", ip: "IP location", manual: "Manual" }[key]);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Opens the manual pane's IANA zone select and picks a zone. */
|
|
131
|
+
async function pickTimeZone(zone: string): Promise<void> {
|
|
132
|
+
const trigger = document.body.querySelector<HTMLButtonElement>(".hk-select-trigger");
|
|
133
|
+
expect(trigger, "zone select trigger renders").toBeTruthy();
|
|
134
|
+
trigger!.click();
|
|
135
|
+
await settle();
|
|
136
|
+
const option = [...document.body.querySelectorAll<HTMLElement>(".hk-select-option")]
|
|
137
|
+
.find((el) => el.textContent?.trim() === zone);
|
|
138
|
+
expect(option, `zone option "${zone}" renders`).toBeTruthy();
|
|
139
|
+
option!.click();
|
|
140
|
+
await settle();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function openEditor(container: HTMLElement): Promise<void> {
|
|
144
|
+
editButton(container).click();
|
|
145
|
+
await settle();
|
|
146
|
+
expect(modalHeader(), "modal opened with a header").toBeTruthy();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
beforeEach(() => {
|
|
150
|
+
// Hermetic geo: apply flows through refreshThemeClock, whose IP leg
|
|
151
|
+
// must never reach the network in tests.
|
|
152
|
+
vi.stubGlobal("fetch", vi.fn(() => Promise.resolve({ ok: false })));
|
|
153
|
+
// Desktop geometry: the zone select opens as an anchored popout.
|
|
154
|
+
setViewportWidth(1280);
|
|
155
|
+
appliedEvents.length = 0;
|
|
156
|
+
resetEngineState();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
afterEach(async () => {
|
|
160
|
+
for (const { app, container } of mounts.splice(0)) {
|
|
161
|
+
app.unmount();
|
|
162
|
+
container.remove();
|
|
163
|
+
}
|
|
164
|
+
setViewportWidth(ORIGINAL_WIDTH);
|
|
165
|
+
vi.unstubAllGlobals();
|
|
166
|
+
localStorage.clear();
|
|
167
|
+
await setLocale("en");
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe("HkSolarLocationSetting row", () => {
|
|
171
|
+
it("renders the live summary with the strategy icon and the edit button", async () => {
|
|
172
|
+
const container = mountSetting();
|
|
173
|
+
await settle();
|
|
174
|
+
|
|
175
|
+
const summary = rowSummary(container);
|
|
176
|
+
expect(summary.getAttribute("data-strategy")).toBe("timezone");
|
|
177
|
+
// Offline default: the summary names the strategy AND the live
|
|
178
|
+
// system zone id (systemTimeZoneId), so the row is self-explaining.
|
|
179
|
+
expect(summary.textContent).toContain("Time zone");
|
|
180
|
+
expect(summary.textContent).toContain(systemTimeZoneId());
|
|
181
|
+
expect(summary.querySelector("svg"), "strategy glyph renders").toBeTruthy();
|
|
182
|
+
|
|
183
|
+
const btn = editButton(container);
|
|
184
|
+
expect(btn.textContent?.trim()).toBe("Edit");
|
|
185
|
+
// No editor in the DOM before the first open.
|
|
186
|
+
expect(document.body.querySelector(".hk-solar-editor")).toBeNull();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("reflects the manual strategy in the row once applied", async () => {
|
|
190
|
+
setSolarManualLocation({ timeZone: "Australia/Sydney", hemisphere: "south" });
|
|
191
|
+
setSolarLocationStrategy("manual");
|
|
192
|
+
const container = mountSetting();
|
|
193
|
+
await settle();
|
|
194
|
+
|
|
195
|
+
const summary = rowSummary(container);
|
|
196
|
+
expect(summary.getAttribute("data-strategy")).toBe("manual");
|
|
197
|
+
expect(summary.textContent).toContain("Australia/Sydney");
|
|
198
|
+
expect(summary.textContent).toContain("Southern");
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe("HkSolarLocationSetting editor", () => {
|
|
203
|
+
it("opens the secondary modal with the three strategy tabs and the offline-first hint", async () => {
|
|
204
|
+
const container = mountSetting();
|
|
205
|
+
await openEditor(container);
|
|
206
|
+
|
|
207
|
+
expect(modalHeader()!.textContent).toContain("Sun clock location");
|
|
208
|
+
const triggers = strategyTriggers();
|
|
209
|
+
expect(triggers).toHaveLength(3);
|
|
210
|
+
expect(triggers.map((b) => b.textContent?.trim())).toEqual([
|
|
211
|
+
"Time zone",
|
|
212
|
+
"IP location",
|
|
213
|
+
"Manual",
|
|
214
|
+
]);
|
|
215
|
+
expect(activeStrategyOf(triggers)).toBe("Time zone");
|
|
216
|
+
// Every tab carries its lucide glyph (Clock / Globe2 / MapPin).
|
|
217
|
+
for (const trigger of triggers) {
|
|
218
|
+
expect(trigger.querySelector("svg")).toBeTruthy();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const editor = document.body.querySelector<HTMLElement>(".hk-solar-editor");
|
|
222
|
+
expect(editor!.textContent).toContain("No network request, no permission prompt");
|
|
223
|
+
// Manual controls stay hidden while the draft is not manual.
|
|
224
|
+
expect(document.body.querySelector(".hk-solar-manual")).toBeNull();
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("switching strategies swaps the hint and reveals the manual pane", async () => {
|
|
228
|
+
const container = mountSetting();
|
|
229
|
+
await openEditor(container);
|
|
230
|
+
|
|
231
|
+
clickStrategy("ip");
|
|
232
|
+
await settle();
|
|
233
|
+
expect(document.body.querySelector<HTMLElement>(".hk-solar-editor")!.getAttribute("data-strategy")).toBe("ip");
|
|
234
|
+
expect(document.body.querySelector<HTMLElement>(".hk-solar-editor")!.textContent)
|
|
235
|
+
.toContain("IP lookup");
|
|
236
|
+
|
|
237
|
+
clickStrategy("manual");
|
|
238
|
+
await settle();
|
|
239
|
+
const editor = document.body.querySelector<HTMLElement>(".hk-solar-editor")!;
|
|
240
|
+
expect(editor.getAttribute("data-strategy")).toBe("manual");
|
|
241
|
+
expect(document.body.querySelector(".hk-solar-manual")).toBeTruthy();
|
|
242
|
+
expect(document.body.querySelector<HTMLButtonElement>(".hk-select-trigger")).toBeTruthy();
|
|
243
|
+
const hemi = hemisphereTriggers();
|
|
244
|
+
expect(hemi.map((b) => b.textContent?.trim())).toEqual(["Northern", "Southern"]);
|
|
245
|
+
// Draft default: the system zone, northern hemisphere (explicit
|
|
246
|
+
// pick — never inferred).
|
|
247
|
+
expect(activeStrategyOf(hemi)).toBe("Northern");
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("keeps the hemisphere explicit when the zone changes; the resolved readout follows the engine", async () => {
|
|
251
|
+
const container = mountSetting();
|
|
252
|
+
await openEditor(container);
|
|
253
|
+
clickStrategy("manual");
|
|
254
|
+
await settle();
|
|
255
|
+
|
|
256
|
+
await pickTimeZone("Australia/Sydney");
|
|
257
|
+
// The zone moved to the southern hemisphere's side of the globe,
|
|
258
|
+
// but the hemisphere knob is the USER's pick — it must NOT move.
|
|
259
|
+
expect(activeStrategyOf(hemisphereTriggers())).toBe("Northern");
|
|
260
|
+
|
|
261
|
+
hemisphereTriggers()[1].click();
|
|
262
|
+
await settle();
|
|
263
|
+
expect(activeStrategyOf(hemisphereTriggers())).toBe("Southern");
|
|
264
|
+
|
|
265
|
+
const resolved = document.body.querySelector<HTMLElement>('[data-test="hk-solar-resolved"]');
|
|
266
|
+
expect(resolved, "resolved-coordinates readout renders").toBeTruthy();
|
|
267
|
+
const geo = manualLocationOf({ timeZone: "Australia/Sydney", hemisphere: "south" });
|
|
268
|
+
expect(resolved!.textContent).toContain(geo.lat.toFixed(1));
|
|
269
|
+
expect(resolved!.textContent).toContain(geo.lng.toFixed(1));
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it("OK applies the manual draft: engine refs, storage, inline summary, applied emit", async () => {
|
|
273
|
+
const container = mountSetting();
|
|
274
|
+
await openEditor(container);
|
|
275
|
+
clickStrategy("manual");
|
|
276
|
+
await settle();
|
|
277
|
+
await pickTimeZone("Australia/Sydney");
|
|
278
|
+
hemisphereTriggers()[1].click();
|
|
279
|
+
await settle();
|
|
280
|
+
|
|
281
|
+
footerButton("Apply").click();
|
|
282
|
+
await settle();
|
|
283
|
+
|
|
284
|
+
// Engine state moved.
|
|
285
|
+
expect(solarLocationStrategy.value).toBe("manual");
|
|
286
|
+
expect(solarManualLocation.value).toEqual({
|
|
287
|
+
timeZone: "Australia/Sydney",
|
|
288
|
+
hemisphere: "south",
|
|
289
|
+
});
|
|
290
|
+
// Persistence evidence — the exact keys the engine owns.
|
|
291
|
+
expect(localStorage.getItem(SOLAR_LOCATION_STRATEGY_STORAGE_KEY)).toBe("manual");
|
|
292
|
+
expect(JSON.parse(localStorage.getItem(SOLAR_MANUAL_LOCATION_STORAGE_KEY) ?? "null")).toEqual({
|
|
293
|
+
timeZone: "Australia/Sydney",
|
|
294
|
+
hemisphere: "south",
|
|
295
|
+
});
|
|
296
|
+
// The row summary reflects the new strategy IMMEDIATELY.
|
|
297
|
+
const summary = rowSummary(container);
|
|
298
|
+
expect(summary.getAttribute("data-strategy")).toBe("manual");
|
|
299
|
+
expect(summary.textContent).toContain("Australia/Sydney");
|
|
300
|
+
expect(summary.textContent).toContain("Southern");
|
|
301
|
+
// The host was notified.
|
|
302
|
+
expect(appliedEvents).toEqual(["manual"]);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("OK applies the timezone strategy with no manual payload written", async () => {
|
|
306
|
+
const container = mountSetting();
|
|
307
|
+
await openEditor(container);
|
|
308
|
+
clickStrategy("timezone");
|
|
309
|
+
await settle();
|
|
310
|
+
footerButton("Apply").click();
|
|
311
|
+
await settle();
|
|
312
|
+
|
|
313
|
+
expect(solarLocationStrategy.value).toBe("timezone");
|
|
314
|
+
expect(localStorage.getItem(SOLAR_LOCATION_STRATEGY_STORAGE_KEY)).toBe("timezone");
|
|
315
|
+
expect(localStorage.getItem(SOLAR_MANUAL_LOCATION_STORAGE_KEY)).toBeNull();
|
|
316
|
+
expect(appliedEvents).toEqual(["timezone"]);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it("cancel discards the draft and leaves the engine untouched", async () => {
|
|
320
|
+
const container = mountSetting();
|
|
321
|
+
await openEditor(container);
|
|
322
|
+
clickStrategy("ip");
|
|
323
|
+
await settle();
|
|
324
|
+
footerButton("Cancel").click();
|
|
325
|
+
await settle();
|
|
326
|
+
|
|
327
|
+
expect(solarLocationStrategy.value).toBe("timezone");
|
|
328
|
+
expect(localStorage.getItem(SOLAR_LOCATION_STRATEGY_STORAGE_KEY)).not.toContain("ip");
|
|
329
|
+
expect(appliedEvents).toEqual([]);
|
|
330
|
+
expect(rowSummary(container).getAttribute("data-strategy")).toBe("timezone");
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
describe("HkSolarLocationSetting i18n", () => {
|
|
335
|
+
it("flows zh-Hans messages through the row and the editor", async () => {
|
|
336
|
+
await setLocale("zh-Hans");
|
|
337
|
+
const container = mountSetting();
|
|
338
|
+
await settle();
|
|
339
|
+
|
|
340
|
+
const summary = rowSummary(container);
|
|
341
|
+
expect(summary.textContent).toContain("时区");
|
|
342
|
+
expect(editButton(container).textContent?.trim()).toBe("编辑");
|
|
343
|
+
|
|
344
|
+
await openEditor(container);
|
|
345
|
+
expect(modalHeader()!.textContent).toContain("太阳钟定位");
|
|
346
|
+
expect(strategyTriggers().map((b) => b.textContent?.trim())).toEqual([
|
|
347
|
+
"时区",
|
|
348
|
+
"IP 定位",
|
|
349
|
+
"手动",
|
|
350
|
+
]);
|
|
351
|
+
|
|
352
|
+
clickStrategyTab("手动");
|
|
353
|
+
await settle();
|
|
354
|
+
expect(hemisphereTriggers().map((b) => b.textContent?.trim())).toEqual([
|
|
355
|
+
"北半球",
|
|
356
|
+
"南半球",
|
|
357
|
+
]);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it("seeds the zone list from the engine's listTimeZones catalog", async () => {
|
|
361
|
+
const container = mountSetting();
|
|
362
|
+
await openEditor(container);
|
|
363
|
+
clickStrategy("manual");
|
|
364
|
+
await settle();
|
|
365
|
+
|
|
366
|
+
const trigger = document.body.querySelector<HTMLButtonElement>(".hk-select-trigger");
|
|
367
|
+
trigger!.click();
|
|
368
|
+
await settle();
|
|
369
|
+
|
|
370
|
+
const rendered = [...document.body.querySelectorAll<HTMLElement>(".hk-select-option")]
|
|
371
|
+
.map((el) => el.textContent?.trim());
|
|
372
|
+
const catalog = listTimeZones();
|
|
373
|
+
expect(rendered.length).toBe(catalog.length);
|
|
374
|
+
expect(rendered).toContain("Asia/Shanghai");
|
|
375
|
+
// A catalog-present zone on every ICU: "UTC" itself is NOT part of
|
|
376
|
+
// Intl.supportedValuesOf("timeZone") on some ICU builds.
|
|
377
|
+
expect(rendered).toContain("Australia/Sydney");
|
|
378
|
+
});
|
|
379
|
+
});
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
// AI-generated: developed with the ZCode agent (model GLM-5.3); human-directed.
|
|
2
|
+
import { computed, defineComponent, ref } from "vue";
|
|
3
|
+
import { Clock, Globe2, MapPin } from "lucide-vue-next";
|
|
4
|
+
|
|
5
|
+
import { useI18n } from "../i18n/context";
|
|
6
|
+
import { refreshThemeClock } from "../theme/useTheme";
|
|
7
|
+
import {
|
|
8
|
+
hydrateSolarLocationState,
|
|
9
|
+
listTimeZones,
|
|
10
|
+
manualLocationOf,
|
|
11
|
+
setSolarLocationStrategy,
|
|
12
|
+
setSolarManualLocation,
|
|
13
|
+
solarLocationStrategy,
|
|
14
|
+
solarManualLocation,
|
|
15
|
+
systemTimeZoneId,
|
|
16
|
+
type SolarHemisphere,
|
|
17
|
+
type SolarLocationStrategy,
|
|
18
|
+
type SolarManualLocation,
|
|
19
|
+
} from "../theme/useSolarTime";
|
|
20
|
+
import HkButton from "./HkButton";
|
|
21
|
+
import HkModal, { type ModalAction } from "./HkModal";
|
|
22
|
+
import HkSelect, { type HkSelectOption } from "./HkSelect";
|
|
23
|
+
import HTabs, { type TabItem } from "./HkTabs";
|
|
24
|
+
import "./HkSolarLocationSetting.scss";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* HkSolarLocationSetting — the solar clock's location STRATEGY row
|
|
28
|
+
* (2026-10-31 product direction: strategies, not a fixed cascade).
|
|
29
|
+
*
|
|
30
|
+
* hikari's sun-driven theming resolves a geographic fix through a
|
|
31
|
+
* user-visible, user-editable strategy ladder:
|
|
32
|
+
*
|
|
33
|
+
* 1. "timezone" (default, highest priority) — fully offline: derive the
|
|
34
|
+
* longitude from the device's IANA time zone. No network request and
|
|
35
|
+
* no permission prompt, ever;
|
|
36
|
+
* 2. "ip" — the classic web cascade (already-granted browser
|
|
37
|
+
* geolocation → ipapi lookup → time-zone estimate fallback);
|
|
38
|
+
* 3. "manual" — an explicitly picked IANA time zone plus hemisphere,
|
|
39
|
+
* for users who want the sun clock pinned regardless of device or
|
|
40
|
+
* network.
|
|
41
|
+
*
|
|
42
|
+
* The component is a generic business part (peer of HkTemplateText, not
|
|
43
|
+
* of the HkInput family): any host project drops ONE row at the bottom
|
|
44
|
+
* of its settings page — shittim-chest, the ERP panels, wowsp — and the
|
|
45
|
+
* row plus its secondary HkModal editor cover the whole interaction.
|
|
46
|
+
* The engine (state, persistence, resolution) lives in
|
|
47
|
+
* theme/useSolarTime.ts; this component only edits it:
|
|
48
|
+
*
|
|
49
|
+
* - the row shows the live strategy summary (timezone → system zone id,
|
|
50
|
+
* manual → zone + hemisphere, ip → the IP label) and an Edit button;
|
|
51
|
+
* - the modal drafts a strategy (segmented Clock/Globe2/MapPin tabs),
|
|
52
|
+
* with the manual pane exposing the IANA zone select and an explicit
|
|
53
|
+
* hemisphere segmented group — hemisphere is NEVER inferred from the
|
|
54
|
+
* zone: picking it is the entire point of the manual knob;
|
|
55
|
+
* - OK applies setSolarManualLocation (manual only) →
|
|
56
|
+
* setSolarLocationStrategy → refreshThemeClock() (the setters drop
|
|
57
|
+
* the engine's geo memo but do not re-resolve on their own), and the
|
|
58
|
+
* row's summary reflects the new state immediately.
|
|
59
|
+
*/
|
|
60
|
+
export const HkSolarLocationSetting = defineComponent({
|
|
61
|
+
name: "HkSolarLocationSetting",
|
|
62
|
+
emits: {
|
|
63
|
+
/** Fired after OK applied the draft (and refreshed the clock). */
|
|
64
|
+
applied: (_strategy: SolarLocationStrategy) => true,
|
|
65
|
+
},
|
|
66
|
+
setup(_props, { emit }) {
|
|
67
|
+
const { t } = useI18n();
|
|
68
|
+
// The engine hydrates lazily (storage-silent imports): a host that
|
|
69
|
+
// mounts this row before initTheme() still sees the stored strategy.
|
|
70
|
+
hydrateSolarLocationState();
|
|
71
|
+
const open = ref(false);
|
|
72
|
+
|
|
73
|
+
// ── Draft state (seeded from the engine on every open) ───────────
|
|
74
|
+
const draftStrategy = ref<SolarLocationStrategy>(solarLocationStrategy.value);
|
|
75
|
+
const draftTimeZone = ref<string>(systemTimeZoneId());
|
|
76
|
+
// Hemisphere default is the explicit-pick contract's neutral start;
|
|
77
|
+
// the segmented group is one tap away from "south".
|
|
78
|
+
const draftHemisphere = ref<SolarHemisphere>("north");
|
|
79
|
+
|
|
80
|
+
function seedDraft(): void {
|
|
81
|
+
draftStrategy.value = solarLocationStrategy.value;
|
|
82
|
+
const stored = solarManualLocation.value;
|
|
83
|
+
draftTimeZone.value = stored?.timeZone ?? systemTimeZoneId();
|
|
84
|
+
draftHemisphere.value = stored?.hemisphere ?? "north";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function openEditor(): void {
|
|
88
|
+
seedDraft();
|
|
89
|
+
open.value = true;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** IANA zone list for the manual pane's select. Plain data (no
|
|
93
|
+
* vnodes), static for the process lifetime — cached once. */
|
|
94
|
+
let timeZoneOptionsCache: HkSelectOption[] | null = null;
|
|
95
|
+
function timeZoneOptions(): HkSelectOption[] {
|
|
96
|
+
timeZoneOptionsCache ??= listTimeZones().map((id) => ({ value: id, label: id }));
|
|
97
|
+
return timeZoneOptionsCache;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ── Live summary (the row's label) ────────────────────────────────
|
|
101
|
+
const summaryText = computed(() => {
|
|
102
|
+
const strategy = solarLocationStrategy.value;
|
|
103
|
+
if (strategy === "ip") return t("hikari::theme.solar.strategyIp");
|
|
104
|
+
if (strategy === "manual") {
|
|
105
|
+
const loc = solarManualLocation.value;
|
|
106
|
+
const hemi = (loc?.hemisphere ?? "north") === "south"
|
|
107
|
+
? t("hikari::theme.solar.south")
|
|
108
|
+
: t("hikari::theme.solar.north");
|
|
109
|
+
const zone = loc?.timeZone ?? systemTimeZoneId();
|
|
110
|
+
return `${t("hikari::theme.solar.strategyManual")} · ${zone} · ${hemi}`;
|
|
111
|
+
}
|
|
112
|
+
return `${t("hikari::theme.solar.strategyTimezone")} · ${systemTimeZoneId()}`;
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
function summaryIcon() {
|
|
116
|
+
const strategy = solarLocationStrategy.value;
|
|
117
|
+
if (strategy === "ip") return <Globe2 size={16} />;
|
|
118
|
+
if (strategy === "manual") return <MapPin size={16} />;
|
|
119
|
+
return <Clock size={16} />;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ── Editor: strategy tabs ─────────────────────────────────────────
|
|
123
|
+
// Fresh option objects and icon vnodes per call (house rule from
|
|
124
|
+
// HkThemePanelContent: caching vnodes re-mounts them on re-render).
|
|
125
|
+
function strategyOptions(): TabItem[] {
|
|
126
|
+
return [
|
|
127
|
+
{ key: "timezone", label: t("hikari::theme.solar.strategyTimezone"), icon: <Clock size={16} /> },
|
|
128
|
+
{ key: "ip", label: t("hikari::theme.solar.strategyIp"), icon: <Globe2 size={16} /> },
|
|
129
|
+
{ key: "manual", label: t("hikari::theme.solar.strategyManual"), icon: <MapPin size={16} /> },
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function hemisphereOptions(): TabItem[] {
|
|
134
|
+
return [
|
|
135
|
+
{ key: "north", label: t("hikari::theme.solar.north") },
|
|
136
|
+
{ key: "south", label: t("hikari::theme.solar.south") },
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function onSelectStrategy(value: string): void {
|
|
141
|
+
draftStrategy.value = value as SolarLocationStrategy;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function onSelectHemisphere(value: string): void {
|
|
145
|
+
draftHemisphere.value = value as SolarHemisphere;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Zone change only moves the zone — the hemisphere is the user's
|
|
149
|
+
* explicit pick and is never re-derived from the zone. */
|
|
150
|
+
function onSelectTimeZone(value: string): void {
|
|
151
|
+
draftTimeZone.value = value;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const hintText = computed(() => {
|
|
155
|
+
if (draftStrategy.value === "ip") return t("hikari::theme.solar.ipHint");
|
|
156
|
+
if (draftStrategy.value === "manual") return t("hikari::theme.solar.manualHint");
|
|
157
|
+
return t("hikari::theme.solar.timezoneHint");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
/** Resolved-coordinates readout for the manual pane, from the same
|
|
161
|
+
* resolver the engine feeds the sun clock — so the number the user
|
|
162
|
+
* reads here IS the number that drives the theme. */
|
|
163
|
+
const resolvedHint = computed(() => {
|
|
164
|
+
if (draftStrategy.value !== "manual") return null;
|
|
165
|
+
const geo = manualLocationOf({
|
|
166
|
+
timeZone: draftTimeZone.value,
|
|
167
|
+
hemisphere: draftHemisphere.value,
|
|
168
|
+
});
|
|
169
|
+
return t("hikari::theme.solar.resolvedAt")
|
|
170
|
+
.replace("{lat}", geo.lat.toFixed(1))
|
|
171
|
+
.replace("{lng}", geo.lng.toFixed(1));
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// ── Apply ─────────────────────────────────────────────────────────
|
|
175
|
+
function applyDraft(): void {
|
|
176
|
+
if (draftStrategy.value === "manual") {
|
|
177
|
+
setSolarManualLocation({
|
|
178
|
+
timeZone: draftTimeZone.value,
|
|
179
|
+
hemisphere: draftHemisphere.value,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
setSolarLocationStrategy(draftStrategy.value);
|
|
183
|
+
// Setters drop the engine's geo memo; resolution is the caller's
|
|
184
|
+
// job — refresh so the theme clock re-resolves immediately.
|
|
185
|
+
void refreshThemeClock();
|
|
186
|
+
open.value = false;
|
|
187
|
+
emit("applied", draftStrategy.value);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const footerActions = computed<ModalAction[]>(() => [
|
|
191
|
+
{
|
|
192
|
+
label: t("hikari::theme.solar.cancel"),
|
|
193
|
+
variant: "secondary" as const,
|
|
194
|
+
onClick: () => { open.value = false; },
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
label: t("hikari::theme.solar.apply"),
|
|
198
|
+
variant: "primary" as const,
|
|
199
|
+
onClick: applyDraft,
|
|
200
|
+
},
|
|
201
|
+
]);
|
|
202
|
+
|
|
203
|
+
return () => (
|
|
204
|
+
<div class="hk-solar-setting">
|
|
205
|
+
<div class="hk-solar-summary" data-strategy={solarLocationStrategy.value}>
|
|
206
|
+
<span class="hk-solar-summary-icon" aria-hidden="true">{summaryIcon()}</span>
|
|
207
|
+
<span class="hk-solar-summary-text">{summaryText.value}</span>
|
|
208
|
+
</div>
|
|
209
|
+
<HkButton
|
|
210
|
+
size="sm"
|
|
211
|
+
variant="outline"
|
|
212
|
+
class="hk-solar-edit"
|
|
213
|
+
onClick={openEditor}
|
|
214
|
+
>
|
|
215
|
+
{t("hikari::theme.solar.edit")}
|
|
216
|
+
</HkButton>
|
|
217
|
+
|
|
218
|
+
<HkModal
|
|
219
|
+
modelValue={open.value}
|
|
220
|
+
onUpdate:modelValue={(v: boolean) => { open.value = v; }}
|
|
221
|
+
title={t("hikari::theme.solar.title")}
|
|
222
|
+
width="sm"
|
|
223
|
+
footerActions={footerActions.value}
|
|
224
|
+
>
|
|
225
|
+
<div class="hk-solar-editor" data-strategy={draftStrategy.value}>
|
|
226
|
+
<HTabs
|
|
227
|
+
variant="segmented"
|
|
228
|
+
block
|
|
229
|
+
tabs={strategyOptions()}
|
|
230
|
+
modelValue={draftStrategy.value}
|
|
231
|
+
onUpdate:modelValue={onSelectStrategy}
|
|
232
|
+
ariaLabel={t("hikari::theme.solar.title")}
|
|
233
|
+
/>
|
|
234
|
+
<p class="hk-solar-hint">{hintText.value}</p>
|
|
235
|
+
{draftStrategy.value === "manual" && (
|
|
236
|
+
<div class="hk-solar-manual">
|
|
237
|
+
<HkSelect
|
|
238
|
+
modelValue={draftTimeZone.value}
|
|
239
|
+
onUpdate:modelValue={onSelectTimeZone}
|
|
240
|
+
options={timeZoneOptions()}
|
|
241
|
+
label={t("hikari::theme.solar.strategyTimezone")}
|
|
242
|
+
panelTitle={t("hikari::theme.solar.strategyTimezone")}
|
|
243
|
+
/>
|
|
244
|
+
<div class="hk-solar-hemisphere">
|
|
245
|
+
<label class="hk-solar-field-label">{t("hikari::theme.solar.hemisphere")}</label>
|
|
246
|
+
<HTabs
|
|
247
|
+
variant="segmented"
|
|
248
|
+
block
|
|
249
|
+
tabs={hemisphereOptions()}
|
|
250
|
+
modelValue={draftHemisphere.value}
|
|
251
|
+
onUpdate:modelValue={onSelectHemisphere}
|
|
252
|
+
ariaLabel={t("hikari::theme.solar.hemisphere")}
|
|
253
|
+
/>
|
|
254
|
+
</div>
|
|
255
|
+
{resolvedHint.value && (
|
|
256
|
+
<p class="hk-solar-resolved" data-test="hk-solar-resolved">{resolvedHint.value}</p>
|
|
257
|
+
)}
|
|
258
|
+
</div>
|
|
259
|
+
)}
|
|
260
|
+
</div>
|
|
261
|
+
</HkModal>
|
|
262
|
+
</div>
|
|
263
|
+
);
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
export default HkSolarLocationSetting;
|