-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathModel.js
More file actions
825 lines (759 loc) · 29.8 KB
/
Copy pathModel.js
File metadata and controls
825 lines (759 loc) · 29.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
.import "Engine.js" as Engine
var EngineRef = typeof Engine !== "undefined" ? Engine : require("./Engine.js")
var METHODS = EngineRef.METHODS
var PRAYERS = ["Fajr", "Dhuhr", "Asr", "Maghrib", "Isha"]
var DAY_ORDER = ["Fajr", "Sunrise", "Dhuhr", "Asr", "Maghrib", "Isha"]
var NIGHT_ORDER = ["Imsak", "Midnight", "Firstthird", "Lastthird"]
var TUNE_ORDER = [
"Imsak", "Fajr", "Sunrise", "Dhuhr", "Asr", "Maghrib", "Sunset", "Isha", "Midnight"
]
var TUNE_EDITABLE = ["Fajr", "Sunrise", "Dhuhr", "Asr", "Maghrib", "Isha"]
var LOCATION_RESPONSE_LIMIT = 65536
var DETECT_RESPONSE_LIMIT = 1024
var LOCATION_RESULT_LIMIT = 6
var LOCATION_FIELD_LIMIT = 128
var LOCATION_ZONE_LIMIT = 64
var ARABIC_NAMES = {
Fajr: "\u0627\u0644\u0641\u062c\u0631",
Sunrise: "\u0627\u0644\u0634\u0631\u0648\u0642",
Dhuhr: "\u0627\u0644\u0638\u0647\u0631",
Asr: "\u0627\u0644\u0639\u0635\u0631",
Sunset: "\u0627\u0644\u063a\u0631\u0648\u0628",
Maghrib: "\u0627\u0644\u0645\u063a\u0631\u0628",
Isha: "\u0627\u0644\u0639\u0634\u0627\u0621",
Imsak: "\u0627\u0644\u0625\u0645\u0633\u0627\u0643",
Midnight: "\u0645\u0646\u062a\u0635\u0641 \u0627\u0644\u0644\u064a\u0644",
Firstthird: "\u0627\u0644\u062b\u0644\u062b \u0627\u0644\u0623\u0648\u0644",
Lastthird: "\u0627\u0644\u062b\u0644\u062b \u0627\u0644\u0623\u062e\u064a\u0631"
}
var ENGLISH_NAMES = {
Fajr: "Fajr",
Sunrise: "Sunrise",
Dhuhr: "Dhuhr",
Asr: "Asr",
Sunset: "Sunset",
Maghrib: "Maghrib",
Isha: "Isha",
Imsak: "Imsak",
Midnight: "Midnight",
Firstthird: "First third",
Lastthird: "Last third"
}
// Option rings for the settings the panel lets the user change in place. Each
// one mirrors the enum in manifest.json, and the order is the click order of
// the panel's cycle buttons.
var PANEL_STYLES = ["Horizon", "Compact"]
var TIME_FORMATS = ["24-hour", "12-hour"]
var LANGUAGES = ["English", "Arabic"]
var SCHOOLS = ["Shafi", "Hanafi"]
var BAR_DISPLAYS = [
"Strip + countdown", "Icon only", "Name + countdown", "Name + time",
"Countdown only"
]
// English then Arabic for every string the display section paints. The panel
// is bilingual everywhere else, so its own controls follow `language` too
// rather than staying English inside an otherwise Arabic panel.
var UI_LABELS = {
location: ["Location", "الموقع"],
detect: ["Detect", "تحديد"],
detectPrivacy: ["Detect asks wttr.in for an approximate city using your IP.", "يطلب تحديد الموقع مدينة تقريبية من wttr.in باستخدام عنوان IP الخاص بك."],
citySearch: ["Search for a city", "ابحث عن مدينة"],
citySearchPrivacy: ["City search sends your text to Open-Meteo.", "يرسل بحث المدينة النص الذي تكتبه إلى Open-Meteo."],
searching: ["Searching…", "جاري البحث…"],
noMatches: ["No matching city", "لا توجد مدينة مطابقة"],
searchFailed: ["City search failed", "فشل البحث عن المدينة"],
detectFailed: ["Could not detect a location", "تعذر تحديد الموقع"],
detectHint: ["Detected from your connection — confirm it", "محدد من اتصالك — تأكيده"],
calculation: ["Calculation", "الحساب"],
method: ["Method", "طريقة الحساب"],
asr: ["Asr", "العصر"],
tuning: ["Adjust minutes", "تعديل الدقائق"],
reset: ["Reset", "إعادة ضبط"],
edit: ["Edit", "تعديل"],
done: ["Done", "تم"],
none: ["None", "لا شيء"],
suggested: ["Suggested for", "المقترح لـ"],
apply: ["Apply", "تطبيق"],
dismiss: ["Dismiss", "تجاهل"],
approximate: ["High-latitude approximation: nearest valid latitude used", "تقريب للمناطق القطبية: استُخدم أقرب خط عرض صالح"],
nojumiNote: ["Standard Asr; sunset-to-Fajr midnight. Isha 15° is an estimate, not published by Nojumi. Saved school and midnight preferences are preserved.", "العصر بالظل المعتاد؛ منتصف الليل بين الغروب والفجر. العشاء بزاوية 15° تقديري ولا ينشره نجومي. تبقى تفضيلات العصر ومنتصف الليل محفوظة."],
searchMethod: ["Search methods", "ابحث عن طريقة"],
noMethod: ["No matching method", "لا توجد طريقة مطابقة"],
display: ["Display", "العرض"],
layout: ["Layout", "التصميم"],
clock: ["Clock", "الساعة"],
names: ["Names", "الأسماء"],
barLabel: ["Bar label", "شريط النظام"],
sunrise: ["Sunrise row", "صف الشروق"],
nightMarkers: ["Night markers", "علامات الليل"],
centerPanel: ["Center panel", "توسيط اللوحة"],
notifications: ["Notifications", "التنبيهات"],
accentLead: ["Accent lead", "التلوين المسبق"],
minutes: ["min", "دقيقة"],
off: ["Off", "معطل"],
settingsTip: ["Display settings", "إعدادات العرض"],
nextTip: ["Switch to", "تحويل إلى"]
}
// Short forms of the enum values. The bar-display names are abbreviated
// because they ride a 150px control rather than the manifest's settings form.
var OPTION_LABELS = {
Horizon: ["Horizon", "أفق"],
Compact: ["Compact", "مضغوط"],
"24-hour": ["24h", "24h"],
"12-hour": ["12h", "12h"],
English: ["English", "إنجليزي"],
Arabic: ["Arabic", "عربي"],
Shafi: ["Shafi", "شافعي"],
Hanafi: ["Hanafi", "حنفي"],
"Strip + countdown": ["Strip", "شريط"],
"Icon only": ["Icon", "أيقونة"],
"Name + countdown": ["Name + left", "الاسم والمتبقي"],
"Name + time": ["Name + time", "الاسم والوقت"],
"Countdown only": ["Countdown", "المتبقي"]
}
function parseEnvelope(raw) {
try {
var value = JSON.parse(String(raw || "{}"))
return value && typeof value === "object" && !(value instanceof Array) ? value : null
} catch (e) {
return null
}
}
function text(value) {
return value === undefined || value === null ? "" : String(value)
}
function latinDigits(value) {
return text(value).replace(/[\u0660-\u0669\u06f0-\u06f9]/g, function(digit) {
var code = digit.charCodeAt(0)
return String(code >= 0x06f0 ? code - 0x06f0 : code - 0x0660)
})
}
function number(value, fallback) {
var parsed = Number(value)
return isFinite(parsed) ? parsed : fallback
}
function bool(value) {
return value === true || value === 1 || text(value).toLowerCase() === "true"
}
function sameNumber(left, right) {
return Math.abs(number(left, NaN) - number(right, NaN)) < 0.000001
}
function sameConfig(actual, expected) {
if (!actual || !expected) return false
return text(actual.locationLabel) === text(expected.locationLabel)
&& sameNumber(actual.latitude, expected.latitude)
&& sameNumber(actual.longitude, expected.longitude)
&& text(actual.timezone) === text(expected.timezone)
&& number(actual.method, -1) === number(expected.method, -2)
&& number(actual.school, -1) === number(expected.school, -2)
&& number(actual.latitudeAdjustmentMethod, -1) === number(expected.latitudeAdjustmentMethod, -2)
&& number(actual.midnightMode, -1) === number(expected.midnightMode, -2)
&& number(actual.hijriAdjustment, 0) === number(expected.hijriAdjustment, 0)
&& text(actual.tune) === text(expected.tune)
&& text(actual.shafaq) === text(expected.shafaq)
&& text(actual.methodSettings) === text(expected.methodSettings)
}
function label(name, language) {
var names = text(language) === "Arabic" ? ARABIC_NAMES : ENGLISH_NAMES
return names[name] || text(name)
}
function localized(table, key, language) {
var pair = table[text(key)]
if (!pair) return ""
return text(language) === "Arabic" ? pair[1] : pair[0]
}
function uiLabel(key, language) {
return localized(UI_LABELS, key, language)
}
// Falls back to the raw value so a hand-edited shell.json still names itself
// in the panel instead of rendering an empty control.
function optionLabel(value, language) {
return localized(OPTION_LABELS, value, language) || text(value)
}
// Builds the { value, label } list a Dropdown or ButtonGroup wants, with the
// values kept as the canonical strings that go back into shell.json.
function optionModel(ring, language) {
var out = []
for (var i = 0; i < ring.length; i++)
out.push({ value: ring[i], label: optionLabel(ring[i], language) })
return out
}
function methodLabel(id, language) {
var method = EngineRef.methodById(id)
if (!method) return text(id)
return text(language) === "Arabic" ? method.name[1] : method.name[0]
}
function hanafiSupported(id) {
return EngineRef.hanafiSupported(id)
}
function decimalText(value) {
var numberValue = Number(value)
if (!isFinite(numberValue)) return "0"
return String(numberValue)
}
function methodValueText(name, value, minutes, language) {
var prefix = label(name, language) + " "
if (minutes > 0)
return prefix + decimalText(minutes) + (text(language) === "Arabic" ? " د" : " min")
return prefix + decimalText(value) + "°"
}
function methodDescription(method, language, methodSettings) {
var params = method.id === 99
? EngineRef.methodParameters({ method: 99, methodSettings: methodSettings })
: method
var parts = [methodValueText("Fajr", params.fajr, 0, language)]
if (method.code === "NOJUMI") {
parts.push(label("Maghrib", language) + (text(language) === "Arabic"
? " 3.75° / 4.5° إيران" : " 3.75° / 4.5° Iran"))
parts.push(methodValueText("Isha", params.isha, params.ishaMinutes, language)
+ (text(language) === "Arabic" ? " (تقديري)" : " (estimated)"))
return parts.join(" · ")
}
if (method.id === 99) {
if (params.maghrib > 0)
parts.push(methodValueText("Maghrib", params.maghrib, 0, language))
else
parts.push(label("Maghrib", language) + " "
+ (text(language) === "Arabic" ? "الغروب" : "sunset"))
} else if (params.maghribMinutes > 0) {
parts.push(methodValueText("Maghrib", 0, params.maghribMinutes, language))
} else if (params.maghrib > 0) {
parts.push(methodValueText("Maghrib", params.maghrib, 0, language))
}
parts.push(methodValueText("Isha", params.isha, params.ishaMinutes, language))
return parts.join(" · ")
}
function methodOptions(language, methodSettings) {
var out = []
for (var i = 0; i < METHODS.length; i++) {
out.push({
value: String(METHODS[i].id),
label: methodLabel(METHODS[i].id, language),
description: methodDescription(METHODS[i], language, methodSettings)
})
}
return out
}
function suggestedMethod(countryCode, currentMethod) {
var country = text(countryCode).toUpperCase()
if (country === "") return null
for (var i = 0; i < METHODS.length; i++) {
if (METHODS[i].regions.indexOf(country) !== -1) {
if (Number(currentMethod) === METHODS[i].id) return null
return { id: METHODS[i].id, label: METHODS[i].name[0] }
}
}
return null
}
function tuneValues(value) {
var source = value instanceof Array ? value : text(value).split(",")
var out = []
for (var i = 0; i < TUNE_ORDER.length; i++) {
var parsed = Number(source[i])
out.push(isFinite(parsed) ? Math.round(parsed) : 0)
}
return out
}
function tuneText(values) {
return tuneValues(values).join(",")
}
function tuneSummary(values, language) {
var normalized = tuneValues(values)
var parts = []
for (var i = 0; i < TUNE_ORDER.length; i++) {
if (normalized[i] === 0) continue
var amount = normalized[i] > 0 ? "+" + normalized[i] : "−" + Math.abs(normalized[i])
parts.push(label(TUNE_ORDER[i], language) + " " + amount)
}
return parts.join(" · ")
}
function schoolLabel(school, language) {
return optionLabel(Number(school) === 1 || text(school) === "Hanafi" ? "Hanafi" : "Shafi", language)
}
// curl >= 8.4 enforces max-filesize even without Content-Length. Disable the
// user's curlrc so it cannot add extra transfers or automatic decompression.
function geocodeCommand(query) {
return ["curl", "-q", "-fsS", "--max-time", "6",
"--max-filesize", String(LOCATION_RESPONSE_LIMIT),
"https://geocoding-api.open-meteo.com/v1/search?name="
+ encodeURIComponent(query) + "&count=" + LOCATION_RESULT_LIMIT + "&language=en&format=json"]
}
function detectLocationCommand() {
return ["curl", "-q", "-fsS", "--max-time", "5",
"--max-filesize", String(DETECT_RESPONSE_LIMIT), "https://wttr.in/?format=%l"]
}
function locationField(value, limit) {
if (value === undefined || value === null) return ""
if (typeof value !== "string" || value.length > limit) return null
return value.replace(/^\s+|\s+$/g, "")
}
// Open-Meteo geocoding response to a list of choices. The timezone is why this
// endpoint is used at all: prayer times are computed against an absolute zone,
// and deriving one from coordinates would be a silent correctness risk. A
// result without a zone is therefore dropped rather than guessed at — a search
// for "Springfield" spans two different zones, so the zone has to come from the
// row the user actually picked.
function parseLocationResults(raw) {
// Guard before JSON.parse too. The transport cap is in bytes; a decoded
// UTF-8 response cannot contain more UTF-16 code units than input bytes.
if (typeof raw !== "string" || raw.length > LOCATION_RESPONSE_LIMIT) return []
var data = parseEnvelope(raw)
if (!data || !(data.results instanceof Array)) return []
var out = []
for (var i = 0; i < Math.min(data.results.length, LOCATION_RESULT_LIMIT); i++) {
var result = data.results[i]
if (!result || typeof result !== "object") continue
var name = locationField(result.name, LOCATION_FIELD_LIMIT)
var admin = locationField(result.admin1, LOCATION_FIELD_LIMIT)
var country = locationField(result.country, LOCATION_FIELD_LIMIT)
var countryCode = locationField(result.country_code, 2)
var timezone = locationField(result.timezone, LOCATION_ZONE_LIMIT)
if (!name || !timezone || admin === null || country === null || countryCode === null) continue
var latitude = result.latitude
var longitude = result.longitude
if (typeof latitude !== "number" || typeof longitude !== "number"
|| !isFinite(latitude) || !isFinite(longitude)
|| Math.abs(latitude) > 90 || Math.abs(longitude) > 180) continue
var region = [admin, country]
.filter(function(part) { return part !== "" })
.join(", ")
out.push({
name: name,
region: region,
country: country,
countryCode: countryCode.toUpperCase(),
latitude: latitude,
longitude: longitude,
timezone: timezone
})
}
return out
}
// wttr.in answers `?format=%l` with "City, Region, CC". Only the leading
// segment is kept, and it is used to seed the search box rather than treated as
// a location: the address it derives from the connection can be a long way from
// where the user actually is.
function detectedLocationQuery(raw) {
if (typeof raw !== "string" || raw.length > DETECT_RESPONSE_LIMIT) return ""
var value = raw.replace(/^\s+|\s+$/g, "")
if (value === "") return ""
var query = value.split(",")[0].replace(/\+/g, " ").replace(/^\s+|\s+$/g, "")
return query.length <= LOCATION_FIELD_LIMIT ? query : ""
}
// The four location keys are written as one unit. A partial write would leave
// the timezone describing a different place than the coordinates.
// locationLabelAr is
// cleared because an Arabic label kept from the previous city would name the
// wrong place; the panel falls back to locationLabel when it is empty.
function locationSettings(choice) {
if (!choice) return null
var latitude = Number(choice.latitude)
var longitude = Number(choice.longitude)
if (!isFinite(latitude) || !isFinite(longitude)) return null
if (text(choice.timezone) === "" || text(choice.name) === "") return null
return {
locationLabel: text(choice.name),
locationLabelAr: "",
latitude: String(latitude),
longitude: String(longitude),
timezone: text(choice.timezone)
}
}
// A value outside the ring lands on the first option rather than nowhere, so a
// typo in shell.json cannot strand a cycle button on a value it does not know.
function nextInRing(ring, current) {
if (!(ring instanceof Array) || ring.length === 0) return ""
var index = ring.indexOf(text(current))
return index < 0 ? ring[0] : ring[(index + 1) % ring.length]
}
// Keep values handed to inherited Omarchy controls inside their fixed option
// ring. In v4.0.1 Dropdown renders an unmatched raw value with Text.AutoText.
function valueInRing(ring, current) {
if (!(ring instanceof Array) || ring.length === 0) return ""
var value = text(current)
return ring.indexOf(value) >= 0 ? value : ring[0]
}
function dayForDate(schedule, dateKey) {
var days = schedule && schedule.days instanceof Array ? schedule.days : []
for (var i = 0; i < days.length; i++) {
if (text(days[i].date) === text(dateKey)) return days[i]
}
return null
}
function today(schedule) {
return dayForDate(schedule, schedule ? schedule.today : "")
}
function timing(day, name) {
return day && day.timings && day.timings[name] ? day.timings[name] : null
}
function instant(value) {
if (!value || !value.at) return null
var parsed = new Date(value.at)
return isNaN(parsed.getTime()) ? null : parsed
}
function scheduleEvents(schedule, names) {
var days = schedule && schedule.days instanceof Array ? schedule.days : []
var wanted = names || PRAYERS
var result = []
for (var d = 0; d < days.length; d++) {
for (var p = 0; p < wanted.length; p++) {
var value = timing(days[d], wanted[p])
var at = instant(value)
if (!at) continue
result.push({
name: wanted[p],
date: days[d].date,
at: at,
iso: value.at,
time: value.time || "",
day: days[d]
})
}
}
result.sort(function(a, b) { return a.at.getTime() - b.at.getTime() })
return result
}
function nextPrayer(schedule, now) {
var epoch = now instanceof Date ? now.getTime() : Number(now)
if (!isFinite(epoch)) epoch = Date.now()
var events = scheduleEvents(schedule, PRAYERS)
for (var i = 0; i < events.length; i++) {
if (events[i].at.getTime() > epoch) return events[i]
}
return null
}
function currentPrayer(schedule, now) {
var epoch = now instanceof Date ? now.getTime() : Number(now)
if (!isFinite(epoch)) epoch = Date.now()
var events = scheduleEvents(schedule, PRAYERS)
var current = null
for (var i = 0; i < events.length; i++) {
if (events[i].at.getTime() > epoch) break
current = events[i]
}
return current
}
function minutesUntil(event, now) {
if (!event || !event.at) return Infinity
var epoch = now instanceof Date ? now.getTime() : Number(now)
if (!isFinite(epoch)) epoch = Date.now()
return Math.ceil((event.at.getTime() - epoch) / 60000)
}
function remaining(event, now, language) {
var minutes = minutesUntil(event, now)
if (!isFinite(minutes)) return ""
if (minutes <= 0) return text(language) === "Arabic" ? "\u0627\u0644\u0622\u0646" : "now"
return formatDuration(minutes, language)
}
function formatClock(clock, format) {
var match = /^(\d{1,2}):(\d{2})/.exec(text(clock))
if (!match) return text(clock)
var hour = parseInt(match[1], 10)
var minute = match[2]
if (text(format) !== "12-hour") return (hour < 10 ? "0" : "") + hour + ":" + minute
var suffix = hour >= 12 ? "PM" : "AM"
var displayHour = hour % 12
if (displayHour === 0) displayHour = 12
return displayHour + ":" + minute + " " + suffix
}
function minutesOfDay(value) {
var match = /^(\d{1,2}):(\d{2})/.exec(text(value && value.time))
if (!match) return NaN
var hour = parseInt(match[1], 10)
var minute = parseInt(match[2], 10)
if (hour < 0 || hour > 23 || minute < 0 || minute > 59) return NaN
return hour * 60 + minute
}
function formatDuration(minutes, language) {
var value = Number(minutes)
if (!isFinite(value) || value < 0) return ""
value = Math.round(value)
var hours = Math.floor(value / 60)
var rest = value % 60
var hourUnit = text(language) === "Arabic" ? " س" : "h"
var minuteUnit = text(language) === "Arabic" ? " د" : "m"
if (hours <= 0) return rest + minuteUnit
if (rest === 0) return hours + hourUnit
return hours + hourUnit + " " + rest + minuteUnit
}
function methodShortName(methodId, fallbackName, language) {
var method = EngineRef.methodById(methodId)
if (method) return text(language) === "Arabic" ? method.short[1] : method.short[0]
var words = text(fallbackName).match(/[A-Za-z0-9]+/g) || []
var acronym = ""
for (var i = 0; i < words.length && acronym.length < 5; i++) {
if (words[i].length >= 3) acronym += words[i].charAt(0).toUpperCase()
}
return acronym || "METHOD " + methodId
}
function tomorrowPrayerLabel(prayer, language, timeFormat) {
if (!prayer) return ""
if (text(language) === "Arabic")
return "\u2067\u063a\u062f\u064b\u0627 " + label(prayer.name, language) + " \u00b7 "
+ formatClock(prayer.time, timeFormat) + "\u2069"
return "Tomorrow \u2068" + label(prayer.name, language) + "\u2069 \u00b7 "
+ formatClock(prayer.time, timeFormat)
}
function barText(next, now, language, mode, timeFormat) {
var icon = "\ueed3"
if (!next) return icon
var prayer = label(next.name, language)
if (mode === "Icon only") return icon
if (mode === "Countdown only") return remaining(next, now, language)
var value = mode === "Name + time"
? formatClock(next.time, timeFormat)
: remaining(next, now, language)
if (text(language) === "Arabic") return "\u2067" + prayer + " " + value + "\u2069"
return prayer + " " + value
}
function tooltip(schedule, next, now, language, timeFormat, locationOverride) {
var arabic = text(language) === "Arabic"
if (!next) return arabic ? "مواقيت الصلاة غير متاحة" : "Prayer times unavailable"
var location = text(locationOverride)
if (!location && schedule && schedule.config) location = text(schedule.config.locationLabel)
var prefix = location ? location + " \u00b7 " : ""
var prayerDay = dayForDate(schedule, next.date) || next.day
var methodName = prayerDay ? text(prayerDay.methodName) : ""
var method = methodName ? " \u00b7 " + methodName : ""
var result = prefix + label(next.name, language) + (arabic ? " بعد " : " in ")
+ remaining(next, now, language)
+ " (" + formatClock(next.time, timeFormat) + ")" + method
// Omarchy 4.0.1's shared bar tooltip uses Text.AutoText. Location and
// calculation-method labels can come from network responses, so neutralize
// markup delimiters at the inherited rendering boundary.
return result.replace(/</g, "‹").replace(/>/g, "›")
}
function dayRows(day, showSunrise) {
var result = []
for (var i = 0; i < DAY_ORDER.length; i++) {
if (DAY_ORDER[i] === "Sunrise" && !showSunrise) continue
var value = timing(day, DAY_ORDER[i])
if (value) result.push({ name: DAY_ORDER[i], value: value })
}
return result
}
function daySegments(day, showSunrise) {
if (!day) return []
var boundaries = []
for (var i = 0; i < DAY_ORDER.length; i++) {
if (DAY_ORDER[i] === "Sunrise" && !showSunrise) continue
var value = timing(day, DAY_ORDER[i])
var minutes = minutesOfDay(value)
if (!value || !isFinite(minutes)) return []
while (boundaries.length && minutes <= boundaries[boundaries.length - 1].minutes)
minutes += 1440
if (boundaries.length && minutes >= boundaries[0].minutes + 1440) return []
boundaries.push({ name: DAY_ORDER[i], value: value, minutes: minutes })
}
var result = []
for (var b = 0; b < boundaries.length; b++) {
var start = boundaries[b].minutes
var end = b + 1 < boundaries.length
? boundaries[b + 1].minutes
: boundaries[0].minutes + 1440
result.push({
name: boundaries[b].name,
value: boundaries[b].value,
start: start,
end: end,
length: end - start
})
}
return result
}
function nightRows(day) {
var result = []
for (var i = 0; i < NIGHT_ORDER.length; i++) {
var value = timing(day, NIGHT_ORDER[i])
if (value) result.push({ name: NIGHT_ORDER[i], value: value })
}
return result
}
function nightMarkers(day) {
if (!day) return null
var start = minutesOfDay(timing(day, "Maghrib"))
var fajr = minutesOfDay(timing(day, "Fajr"))
if (!isFinite(start) || !isFinite(fajr)) return null
var end = fajr + 1440
var span = end - start
if (span <= 0) return null
var names = NIGHT_ORDER.slice(1)
names.push("Isha")
var marks = []
for (var i = 0; i < names.length; i++) {
var minutes = minutesOfDay(timing(day, names[i]))
if (!isFinite(minutes)) continue
if (minutes < start) minutes += 1440
var fraction = Math.max(0, Math.min(1, (minutes - start) / span))
marks.push({ name: names[i], minutes: minutes, fraction: fraction })
}
marks.sort(function(left, right) { return left.fraction - right.fraction })
return { start: start, end: end, span: span, marks: marks }
}
function fractionOfDay(day, now) {
var fajr = instant(timing(day, "Fajr"))
if (!fajr) return 0
var epoch = now instanceof Date ? now.getTime() : Number(now)
if (!isFinite(epoch)) return 0
var fraction = (epoch - fajr.getTime()) / 86400000
if (fraction < 0) fraction += 1
return Math.max(0, Math.min(1, fraction))
}
function windowLabel(segment, language) {
return formatDuration(segment ? segment.length : NaN, language)
}
function hijriLabel(day, language) {
if (!day || !day.hijri) return ""
if (text(language) === "Arabic" && day.hijri.displayAr)
return text(day.hijri.displayAr)
if (day.hijri.display) return text(day.hijri.display)
return [day.hijri.day, day.hijri.month, day.hijri.year].filter(function(value) {
return text(value) !== ""
}).join(" ")
}
function statusLabel(status, language) {
if (text(language) === "Arabic") {
if (status === "local") return "محسوبة دون اتصال"
return "غير محمل"
}
if (status === "local") return "calculated offline"
return "not loaded"
}
function notificationEvents(schedule, previousEpoch, currentEpoch, beforeMinutes, graceMinutes) {
var previous = Number(previousEpoch)
var current = Number(currentEpoch)
if (!isFinite(previous) || !isFinite(current) || current <= previous) return []
var before = Math.max(0, Math.floor(number(beforeMinutes, 0)))
var graceMs = Math.max(1, Math.floor(number(graceMinutes, 10))) * 60000
var events = scheduleEvents(schedule, PRAYERS)
var result = []
for (var i = 0; i < events.length; i++) {
var prayerAt = events[i].at.getTime()
if (before > 0) {
var reminderAt = prayerAt - before * 60000
if (previous < reminderAt && reminderAt <= current
&& current - reminderAt <= graceMs && current < prayerAt) {
result.push({
key: events[i].iso + "|before-" + before,
name: events[i].name,
kind: "before",
minutes: before,
time: events[i].time,
triggerEpoch: reminderAt
})
}
}
if (previous < prayerAt && prayerAt <= current && current - prayerAt <= graceMs) {
result.push({
key: events[i].iso + "|at",
name: events[i].name,
kind: "at",
minutes: 0,
time: events[i].time,
triggerEpoch: prayerAt
})
}
}
return result
}
function notificationText(event, language, timeFormat) {
var prayer = label(event.name, language)
var arabic = text(language) === "Arabic"
if (event.kind === "before") {
if (arabic) {
return {
title: prayer + " بعد " + formatDuration(event.minutes, language),
body: "الموعد " + formatClock(event.time, timeFormat)
}
}
return {
title: prayer + " in " + event.minutes + " minutes",
body: "Scheduled for " + formatClock(event.time, timeFormat)
}
}
if (arabic) {
return {
title: "حان وقت " + prayer,
body: formatClock(event.time, timeFormat)
}
}
return {
title: "It is time for " + prayer,
body: formatClock(event.time, timeFormat)
}
}
function filePath(url) {
var value = decodeURIComponent(text(url))
return value.replace(/^file:\/\//, "")
}
if (typeof module !== "undefined") {
module.exports = {
LOCATION_RESPONSE_LIMIT: LOCATION_RESPONSE_LIMIT,
DETECT_RESPONSE_LIMIT: DETECT_RESPONSE_LIMIT,
LOCATION_RESULT_LIMIT: LOCATION_RESULT_LIMIT,
LOCATION_FIELD_LIMIT: LOCATION_FIELD_LIMIT,
LOCATION_ZONE_LIMIT: LOCATION_ZONE_LIMIT,
geocodeCommand: geocodeCommand,
detectLocationCommand: detectLocationCommand,
METHODS: METHODS,
PRAYERS: PRAYERS,
DAY_ORDER: DAY_ORDER,
NIGHT_ORDER: NIGHT_ORDER,
PANEL_STYLES: PANEL_STYLES,
TIME_FORMATS: TIME_FORMATS,
LANGUAGES: LANGUAGES,
BAR_DISPLAYS: BAR_DISPLAYS,
SCHOOLS: SCHOOLS,
TUNE_ORDER: TUNE_ORDER,
TUNE_EDITABLE: TUNE_EDITABLE,
parseEnvelope: parseEnvelope,
latinDigits: latinDigits,
sameConfig: sameConfig,
label: label,
uiLabel: uiLabel,
optionLabel: optionLabel,
optionModel: optionModel,
methodOptions: methodOptions,
hanafiSupported: hanafiSupported,
methodLabel: methodLabel,
suggestedMethod: suggestedMethod,
tuneValues: tuneValues,
tuneText: tuneText,
tuneSummary: tuneSummary,
schoolLabel: schoolLabel,
nextInRing: nextInRing,
valueInRing: valueInRing,
parseLocationResults: parseLocationResults,
detectedLocationQuery: detectedLocationQuery,
locationSettings: locationSettings,
dayForDate: dayForDate,
today: today,
timing: timing,
instant: instant,
scheduleEvents: scheduleEvents,
nextPrayer: nextPrayer,
currentPrayer: currentPrayer,
minutesUntil: minutesUntil,
remaining: remaining,
formatClock: formatClock,
minutesOfDay: minutesOfDay,
formatDuration: formatDuration,
methodShortName: methodShortName,
tomorrowPrayerLabel: tomorrowPrayerLabel,
barText: barText,
tooltip: tooltip,
dayRows: dayRows,
daySegments: daySegments,
nightRows: nightRows,
nightMarkers: nightMarkers,
fractionOfDay: fractionOfDay,
windowLabel: windowLabel,
hijriLabel: hijriLabel,
statusLabel: statusLabel,
notificationEvents: notificationEvents,
notificationText: notificationText,
filePath: filePath,
bool: bool,
number: number
}
}