Asem75 commited on
Commit
b83d0c2
·
verified ·
1 Parent(s): b6d4fb0

Upload 6 files

Browse files
astronomy_events_registry.json CHANGED
@@ -1,5 +1,5 @@
1
  {
2
- "schema_version": "astronomy_events_registry_v1_1",
3
  "project": "ساعة المسلم / الخط الزمني الروحي",
4
  "language": "ar",
5
  "direction": "rtl",
@@ -314,16 +314,15 @@
314
  "triggers": [
315
  {
316
  "id": "sunset_check",
317
- "when": "anchor",
318
- "anchor": {
 
 
 
 
 
319
  "event": "maghrib",
320
  "offset_minutes": 0
321
- },
322
- "condition": {
323
- "hijri_day_in": [
324
- 29,
325
- 30
326
- ]
327
  }
328
  }
329
  ],
@@ -586,7 +585,9 @@
586
  "v1_1: استبعاد الخسوف شبه الظل من الصلة الدينية وفحص الرؤية المحلية بقاعدة صريحة",
587
  "v1_1: توحيد last_quarter مع محرك المحاكاة (كان third_quarter)",
588
  "v1_1: category_controls: الكسوف والخسوف دائمًا فعّالان، وبقية الفئات يستطيع المستخدم إيقافها",
589
- "v1_1: إضافة crescent_visibility وmoonrise_moonset"
 
 
590
  ],
591
  "category_controls": {
592
  "note": "الكسوف والخسوف دائمًا فعّالان لارتباطهما بعبادة. الفئات الأخرى معلومات يستطيع المستخدم إيقافها.",
@@ -605,5 +606,13 @@
605
  "planetary": {
606
  "user_can_disable": true
607
  }
 
 
 
 
 
 
 
 
608
  }
609
  }
 
1
  {
2
+ "schema_version": "astronomy_events_registry_v1_2",
3
  "project": "ساعة المسلم / الخط الزمني الروحي",
4
  "language": "ar",
5
  "direction": "rtl",
 
314
  "triggers": [
315
  {
316
  "id": "sunset_check",
317
+ "when": "event_day",
318
+ "timing_authority": "engine",
319
+ "hijri_day_in": [
320
+ 29,
321
+ 30
322
+ ],
323
+ "at": {
324
  "event": "maghrib",
325
  "offset_minutes": 0
 
 
 
 
 
 
326
  }
327
  }
328
  ],
 
585
  "v1_1: استبعاد الخسوف شبه الظل من الصلة الدينية وفحص الرؤية المحلية بقاعدة صريحة",
586
  "v1_1: توحيد last_quarter مع محرك المحاكاة (كان third_quarter)",
587
  "v1_1: category_controls: الكسوف والخسوف دائمًا فعّالان، وبقية الفئات يستطيع المستخدم إيقافها",
588
+ "v1_1: إضافة crescent_visibility وmoonrise_moonset",
589
+ "v1_2: تصحيح مشغّل crescent_visibility إلى مفردات المشغّلات القائمة (event_day) مع شرط هجري",
590
+ "v1_2: engine_limits: أرقام البحث عن الكسوف والخسوف انتقلت من worship_event_engine.js"
591
  ],
592
  "category_controls": {
593
  "note": "الكسوف والخسوف دائمًا فعّالان لارتباطهما بعبادة. الفئات الأخرى معلومات يستطيع المستخدم إيقافها.",
 
606
  "planetary": {
607
  "user_can_disable": true
608
  }
609
+ },
610
+ "engine_limits": {
611
+ "eclipse_lookback_days": 1,
612
+ "eclipse_peak_lookahead_days": 1,
613
+ "eclipse_max_occurrences": 8,
614
+ "eclipse_cache_entries": 4,
615
+ "visibility_epsilon_ms": 1000,
616
+ "default_visibility_min_altitude_deg": 0
617
  }
618
  }
fiqh_time_registry.json CHANGED
@@ -38,9 +38,7 @@
38
  "continues_into_next_day": true,
39
  "end_boundary": "next_false_dawn",
40
  "ui_model": "continuous_horizontal_ruler",
41
- "note": "الدورة الزمنية متصلة؛ الوصول إلى نهاية الدورة يدخل مباشرة في دورة اليوم التالي.",
42
- "anchor_fallback": "true_dawn",
43
- "anchor_fallback_note_ar": "الفجر الكاذب بلا op في calculation_profile فقيمته null دائمًا؛ عندها تُثبَّت المسطرة على الفجر الصادق."
44
  },
45
  "authorities": {
46
  "astronomy_engine": {
@@ -102,7 +100,8 @@
102
  "source": "astronomy_engine",
103
  "kind": "solar_transition",
104
  "fixed_minutes": false,
105
- "relation": "بعد الاستواء عندما تبدأ الشمس بالميل عن أعلى ارتفاع"
 
106
  },
107
  {
108
  "id": "dhuhr",
@@ -269,13 +268,6 @@
269
  "semantic": "نافذة حسابية فقط؛ الحكم والعبادة خارج هذا الملف."
270
  }
271
  ],
272
- "aliases": {
273
- "_note_ar": "أسماء تُستخدم في calculation_profile.boundaries وهي حدود موجودة أعلاه",
274
- "fajr": "true_dawn",
275
- "dhuhr": "zawal",
276
- "maghrib": "sunset",
277
- "isha_entry_hanafi": "white_twilight_end"
278
- },
279
  "ordering": [
280
  "false_dawn",
281
  "true_dawn",
@@ -308,7 +300,8 @@
308
  "supports_madhhab_worship_registry": true,
309
  "shadow_factor_boundaries_present": true,
310
  "night_fraction_boundaries_present": true,
311
- "cross_registry_validator": "tools/validate_registries.js"
 
312
  },
313
  "integration_contract": {
314
  "worship_fiqh_registry": "worship_fiqh_registry.json",
@@ -338,7 +331,9 @@
338
  {
339
  "name": "عمّان",
340
  "lat": 31.9454,
341
- "lng": 35.9284
 
 
342
  }
343
  ],
344
  "observational_limits": {
@@ -346,6 +341,14 @@
346
  "next_false_dawn": null
347
  },
348
  "boundaries": {
 
 
 
 
 
 
 
 
349
  "solar_noon": {
350
  "op": "maximum"
351
  },
@@ -448,6 +451,10 @@
448
  "from": "sunset",
449
  "to": "next_true_dawn",
450
  "fraction": 0.6666666666666666
 
 
 
 
451
  }
452
  },
453
  "relation_bindings": {
@@ -518,12 +525,15 @@
518
  "solar_solver": {
519
  "time_tolerance_ms": 1000,
520
  "derivative_sample_ms": 1000,
521
- "note_ar": "دقة عددية للبحث عن انقلاب اتجاه الارتفاع؛ ليست مدة نهي أو إزاحة زمنية للزوال. bracket_ms نصف عرض نافذة البحث حول عبور الشمس للزوال، وuse_engine_search=true يعتمد SearchAltitude الأصلية في المكتبة مع إبقاء المسح بخطوة scan_step_ms احتياطًا.",
522
- "bracket_ms": 600000,
523
- "max_iterations": 80,
524
  "scan_step_ms": 300000,
525
  "bisect_iterations": 36,
526
- "use_engine_search": true
 
 
 
 
 
527
  },
528
  "solar_motion": {
529
  "engine": "local_solar_geometry",
@@ -546,7 +556,9 @@
546
  "url": "https://unpkg.com/adhan@4.4.6/lib/bundles/adhan.umd.min.js",
547
  "version": "4.4.6",
548
  "timeout_ms": 12000,
549
- "source": "Adhan JS 4.4.6؛ الحسابات الفلكية مبنية على Astronomical Algorithms لِـ Jean Meeus"
 
 
550
  },
551
  "methods": [
552
  {
@@ -638,11 +650,6 @@
638
  "asr_shadow_factor": 1,
639
  "adhan_madhab": "Shafi",
640
  "moonsighting_shafaq": "Ahmer"
641
- },
642
- "hanafi_sahibayn": {
643
- "asr_shadow_factor": 1,
644
- "adhan_madhab": "Shafi",
645
- "moonsighting_shafaq": "Ahmer"
646
  }
647
  },
648
  "output_bindings": {
@@ -679,12 +686,40 @@
679
  "minutes": 120,
680
  "storage_key": "clock_ummalqura_ramadan_v1"
681
  },
682
- "note_ar": "طريقة الأردن هي الافتراضية، وتستخدم معاملات وزارة الأوقاف المنشورة مع إبقاء صفحة دائرة الإفتاء مرجع المقارنة اليومي. فرق خمس دقائق يخص موعد المغرب في هذه الطريقة ولا يغيّر حد الغروب الشمسي المحسوب. تشمل القائمة جميع الطرق المسماة التي يوفرها Adhan JS 4.4.6 إضافة إلى طريقة الأردن المخصصة. مواقيت الصلاة لا تستبدل الحدود الشمسية المستقلة التي تحرك مؤشر الشمس. المذهب الحنفي يأخذ المثلين للعصر، والمذاهب الثلاثة تأخذ المثل؛ وتضبط طريقة لجنة تحري الهلال نوع الشفق كذلك. خيار رمضان لأم القرى يؤكد يدويًا ولا يستنتج من تقويم تقريبي."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
683
  },
684
  "changelog": [
685
- "1.6.0: solar_solver: bracket_ms وmax_iterations وscan_step_ms وbisect_iterations وuse_engine_search — معاملات حل عددي (ليست أحكامًا).",
686
- "1.6.0: madhhab_engine_bindings.hanafi_sahibayn.",
687
- "1.6.0: daily_cycle.anchor_fallback لأن false_dawn لا يملك op فيبقى null دائمًا.",
688
- "1.6.0: aliases توثّق الحدود المستعارة المستخدمة في calculation_profile (fajr وdhuhr وmaghrib وisha_entry_hanafi)."
 
689
  ]
690
  }
 
38
  "continues_into_next_day": true,
39
  "end_boundary": "next_false_dawn",
40
  "ui_model": "continuous_horizontal_ruler",
41
+ "note": "الدورة الزمنية متصلة؛ الوصول إلى نهاية الدورة يدخل مباشرة في دورة اليوم التالي."
 
 
42
  },
43
  "authorities": {
44
  "astronomy_engine": {
 
100
  "source": "astronomy_engine",
101
  "kind": "solar_transition",
102
  "fixed_minutes": false,
103
+ "relation": "بعد الاستواء عندما تبدأ الشمس بالميل عن أعلى ارتفاع",
104
+ "practical_equivalence": "يتطابق عمليًا مع الاستواء ضمن دقة الحل العددي (نحو ثانية). النافذة المنهيّ فيها قبيل الزوال سياسة عرض في worship_fiqh_registry ولا تُشتق من هذا الحد."
105
  },
106
  {
107
  "id": "dhuhr",
 
268
  "semantic": "نافذة حسابية فقط؛ الحكم والعبادة خارج هذا الملف."
269
  }
270
  ],
 
 
 
 
 
 
 
271
  "ordering": [
272
  "false_dawn",
273
  "true_dawn",
 
300
  "supports_madhhab_worship_registry": true,
301
  "shadow_factor_boundaries_present": true,
302
  "night_fraction_boundaries_present": true,
303
+ "false_dawn_boundary_defined": true,
304
+ "solver_numbers_in_registry": true
305
  },
306
  "integration_contract": {
307
  "worship_fiqh_registry": "worship_fiqh_registry.json",
 
331
  {
332
  "name": "عمّان",
333
  "lat": 31.9454,
334
+ "lng": 35.9284,
335
+ "timezone": "Asia/Amman",
336
+ "height": 0
337
  }
338
  ],
339
  "observational_limits": {
 
341
  "next_false_dawn": null
342
  },
343
  "boundaries": {
344
+ "false_dawn": {
345
+ "op": "altitude",
346
+ "degrees": -20,
347
+ "direction": "ascending",
348
+ "approximate": true,
349
+ "provisional": true,
350
+ "note_ar": "قيمة مؤقتة لتفعيل مرساة الدورة اليومية فقط، وهي رصدية تقديرية. تحتاج اعتماد المرجع الفلكي قبل الاعتماد النهائي، ولا تدخل في حساب أي عبادة."
351
+ },
352
  "solar_noon": {
353
  "op": "maximum"
354
  },
 
451
  "from": "sunset",
452
  "to": "next_true_dawn",
453
  "fraction": 0.6666666666666666
454
+ },
455
+ "next_false_dawn": {
456
+ "op": "next_day",
457
+ "boundary": "false_dawn"
458
  }
459
  },
460
  "relation_bindings": {
 
525
  "solar_solver": {
526
  "time_tolerance_ms": 1000,
527
  "derivative_sample_ms": 1000,
528
+ "note_ar": "دقة عددية للبحث عن انقلاب اتجاه الارتفاع؛ ليست مدة نهي أو إزاحة زمنية للزوال. جميع القيم العددية للمحرك تأتي من هنا ولا شيء منها مكتوب في solar_engine.js.",
 
 
529
  "scan_step_ms": 300000,
530
  "bisect_iterations": 36,
531
+ "maximum_iterations": 60,
532
+ "transition_iterations": 80,
533
+ "noon_search_half_window_ms": 21600000,
534
+ "crossing_window_ms": 43200000,
535
+ "alias_passes": 5,
536
+ "use_astronomy_search_functions": true
537
  },
538
  "solar_motion": {
539
  "engine": "local_solar_geometry",
 
556
  "url": "https://unpkg.com/adhan@4.4.6/lib/bundles/adhan.umd.min.js",
557
  "version": "4.4.6",
558
  "timeout_ms": 12000,
559
+ "source": "Adhan JS 4.4.6؛ الحسابات الفلكية مبنية على Astronomical Algorithms لِـ Jean Meeus",
560
+ "fallback_url": "vendor/adhan.umd.min.js",
561
+ "offline_note_ar": "يُحمَّل من الرابط أولًا ثم من النسخة المحلية عند فشله؛ ضع الملف بجوار index.html وأضفه إلى ملفات sw.js المخزنة مؤقتًا ليعمل التطبيق دون إنترنت."
562
  },
563
  "methods": [
564
  {
 
650
  "asr_shadow_factor": 1,
651
  "adhan_madhab": "Shafi",
652
  "moonsighting_shafaq": "Ahmer"
 
 
 
 
 
653
  }
654
  },
655
  "output_bindings": {
 
686
  "minutes": 120,
687
  "storage_key": "clock_ummalqura_ramadan_v1"
688
  },
689
+ "note_ar": "طريقة الأردن هي الافتراضية، وتستخدم معاملات وزارة الأوقاف المنشورة مع إبقاء صفحة دائرة الإفتاء مرجع المقارنة اليومي. فرق خمس دقائق يخص موعد المغرب في هذه الطريقة ولا يغيّر حد الغروب الشمسي المحسوب. تشمل القائمة جميع الطرق المسماة التي يوفرها Adhan JS 4.4.6 إضافة إلى طريقة الأردن المخصصة. مواقيت الصلاة لا تستبدل الحدود الشمسية المستقلة التي تحرك مؤشر الشمس. المذهب الحنفي يأخذ المثلين للعصر، والمذاهب الثلاثة تأخذ المثل؛ وتضبط طريقة لجنة تحري الهلال نوع الشفق كذلك. خيار رمضان لأم القرى يؤكد يدويًا ولا يستنتج من تقويم تقريبي.",
690
+ "high_latitude": {
691
+ "default": "recommended",
692
+ "storage_key": "clock_high_latitude_rule_v1",
693
+ "options": [
694
+ {
695
+ "id": "recommended",
696
+ "label_ar": "الموصى به حسب خط العرض",
697
+ "adhan": "HighLatitudeRule.recommended"
698
+ },
699
+ {
700
+ "id": "MiddleOfTheNight",
701
+ "label_ar": "منتصف الليل",
702
+ "adhan": "HighLatitudeRule.MiddleOfTheNight"
703
+ },
704
+ {
705
+ "id": "SeventhOfTheNight",
706
+ "label_ar": "سُبع الليل",
707
+ "adhan": "HighLatitudeRule.SeventhOfTheNight"
708
+ },
709
+ {
710
+ "id": "TwilightAngle",
711
+ "label_ar": "زاوية الشفق",
712
+ "adhan": "HighLatitudeRule.TwilightAngle"
713
+ }
714
+ ],
715
+ "note_ar": "في المناطق التي لا يغيب فيها الشفق أو لا تغرب فيها الشمس يخفق حساب الزاوية، فتُستخدم هذه القاعدة. يتحقق المطوّر من وجود recommended في إصدار Adhan المثبت. الحدود الشمسية المستقلة تعرض سبب التعذر في unavailable بدل قيمة وهمية."
716
+ }
717
  },
718
  "changelog": [
719
+ "1.6.0: تعريف حد الفجر الكاذب والتالي له (كانا مرساة الدورة ولا حساب لهما) بقيمة مؤقتة تحتاج اعتماد المرجع",
720
+ "1.6.0: نقل كل أرقام الحل العددي من solar_engine.js إلى solar_solver",
721
+ "1.6.0: سياسة خطوط العرض العليا (high_latitude) لمحرك الصلاة",
722
+ "1.6.0: مسار محلي احتياطي لمكتبة Adhan، وخط زمني ومنطقة زمنية للموقع",
723
+ "1.6.0: توضيح تطابق الزوال مع الاستواء عمليًا"
724
  ]
725
  }
hijri_calendar_engine.js CHANGED
@@ -1,44 +1,72 @@
1
  'use strict';
2
 
3
  // Pure Hijri-calendar matching. UI preferences and Registry access stay in RegistryApp.
4
- // v2: no dependence on `this` (safe to destructure), cached formatters, weekday without Intl,
5
- // and unsupported Islamic calendars are rejected instead of silently returning Gregorian dates.
6
  globalThis.HijriCalendarEngine = (() => {
7
- const DAY=86400000,WEEKDAYS=['sunday','monday','tuesday','wednesday','thursday','friday','saturday'];
 
 
 
8
  const formatters=new Map();
9
- function formatterFor(calendarId){
10
- if(formatters.has(calendarId))return formatters.get(calendarId);
11
- let entry=null;
12
- try{
13
- const formatter=new Intl.DateTimeFormat('en-US',{calendar:calendarId,year:'numeric',month:'numeric',day:'numeric'});
14
- // Intl silently falls back to Gregorian for unknown calendars; reject that case.
15
- entry=formatter.resolvedOptions().calendar===calendarId?formatter:null;
16
- }catch{entry=null;}
17
- formatters.set(calendarId,entry);
18
- return entry;
19
  }
20
- function supported(calendarId='islamic'){return formatterFor(calendarId)!==null;}
21
  function validConfirmation(value){
22
- if(!value||!Number.isInteger(value.year)||value.year<1||!Number.isInteger(value.month)||value.month<1||value.month>12||![29,30].includes(value.length)||!/^\d{4}-\d{2}-\d{2}$/.test(value.start||''))return false;
23
  const date=new Date(value.start+'T00:00:00Z');return Number.isFinite(date.getTime())&&date.toISOString().slice(0,10)===value.start;
24
  }
25
- function parts(ms,{calendarId='islamic',offsetDays=0,maxOffsetDays=0,confirmations=[]}={}){
26
  try{
27
  const actual=new Date(ms),civilStamp=Date.UTC(actual.getFullYear(),actual.getMonth(),actual.getDate());
28
  for(const month of confirmations){
29
  if(!validConfirmation(month))continue;
30
- const elapsed=Math.round((civilStamp-Date.parse(month.start+'T00:00:00Z'))/DAY);
31
  if(elapsed>=0&&elapsed<month.length)return {year:month.year,month:month.month,day:elapsed+1,confirmed:true};
32
  }
33
- const formatter=formatterFor(calendarId);if(!formatter)return null;
34
  const date=new Date(ms),offset=Number(offsetDays),limit=Number(maxOffsetDays);
35
  if(Number.isInteger(offset)&&Number.isFinite(limit)&&Math.abs(offset)<=limit)date.setDate(date.getDate()+offset);
36
- const formatted=formatter.formatToParts(date);
37
  const value=type=>Number(formatted.find(part=>part.type===type)?.value);
38
  const result={year:value('year'),month:value('month'),day:value('day')};
39
  return Object.values(result).every(Number.isFinite)?result:null;
40
  }catch{return null;}
41
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  function matches(event,ms,{parts:resolveParts,forBlocking=false}={}){
43
  const calendar=event?.calendar_rule||{};
44
  if(calendar.type==='daily')return true;
@@ -54,5 +82,5 @@ globalThis.HijriCalendarEngine = (() => {
54
  if(Array.isArray(calendar.odd_nights)&&!calendar.odd_nights.map(Number).includes(hijri.day))return false;
55
  return true;
56
  }
57
- return Object.freeze({parts,matches,validConfirmation,supported});
58
  })();
 
1
  'use strict';
2
 
3
  // Pure Hijri-calendar matching. UI preferences and Registry access stay in RegistryApp.
4
+ // Calendar facts (months per year, month lengths) are structural; every user/app choice is a parameter.
 
5
  globalThis.HijriCalendarEngine = (() => {
6
+ const MS_DAY=86400000;
7
+ const FACTS=Object.freeze({months_per_year:12,month_lengths:Object.freeze([29,30]),max_lunar_year_days:355});
8
+ const SEARCH_HORIZON_DAYS=FACTS.max_lunar_year_days*2;
9
+ const WEEKDAYS=Object.freeze(['sunday','monday','tuesday','wednesday','thursday','friday','saturday']);
10
  const formatters=new Map();
11
+ let defaults={calendarId:'islamic'};
12
+
13
+ // RegistryApp may set the calendar from the registry once: configure({calendarId:'islamic-umalqura'}).
14
+ function configure(options={}){defaults={...defaults,...options};return {...defaults};}
15
+ function formatter(calendarId){
16
+ let f=formatters.get(calendarId);
17
+ if(!f){f=new Intl.DateTimeFormat('en-US',{calendar:calendarId,year:'numeric',month:'numeric',day:'numeric'});formatters.set(calendarId,f);}
18
+ return f;
 
 
19
  }
 
20
  function validConfirmation(value){
21
+ if(!value||!Number.isInteger(value.year)||value.year<1||!Number.isInteger(value.month)||value.month<1||value.month>FACTS.months_per_year||!FACTS.month_lengths.includes(value.length)||!/^\d{4}-\d{2}-\d{2}$/.test(value.start||''))return false;
22
  const date=new Date(value.start+'T00:00:00Z');return Number.isFinite(date.getTime())&&date.toISOString().slice(0,10)===value.start;
23
  }
24
+ function parts(ms,{calendarId=defaults.calendarId,offsetDays=0,maxOffsetDays=0,confirmations=[]}={}){
25
  try{
26
  const actual=new Date(ms),civilStamp=Date.UTC(actual.getFullYear(),actual.getMonth(),actual.getDate());
27
  for(const month of confirmations){
28
  if(!validConfirmation(month))continue;
29
+ const elapsed=Math.round((civilStamp-Date.parse(month.start+'T00:00:00Z'))/MS_DAY);
30
  if(elapsed>=0&&elapsed<month.length)return {year:month.year,month:month.month,day:elapsed+1,confirmed:true};
31
  }
 
32
  const date=new Date(ms),offset=Number(offsetDays),limit=Number(maxOffsetDays);
33
  if(Number.isInteger(offset)&&Number.isFinite(limit)&&Math.abs(offset)<=limit)date.setDate(date.getDate()+offset);
34
+ const formatted=formatter(calendarId).formatToParts(date);
35
  const value=type=>Number(formatted.find(part=>part.type===type)?.value);
36
  const result={year:value('year'),month:value('month'),day:value('day')};
37
  return Object.values(result).every(Number.isFinite)?result:null;
38
  }catch{return null;}
39
  }
40
+ // The Hijri day begins at sunset: from sunsetMs onward the date belongs to the next civil day.
41
+ function partsAtSunset(ms,sunsetMs,options={}){
42
+ if(!Number.isFinite(sunsetMs)||ms<sunsetMs)return parts(ms,options);
43
+ const next=new Date(ms);next.setDate(next.getDate()+1);
44
+ return parts(next.getTime(),options);
45
+ }
46
+ const civilNoon=(ms,shiftDays=0)=>{const d=new Date(ms);return new Date(d.getFullYear(),d.getMonth(),d.getDate()+shiftDays,12).getTime();};
47
+ // Month containing ms: {year,month,day,length,startMs,endMs} with civil-noon stamps for the first and last day.
48
+ function monthInfo(ms,options={}){
49
+ const here=parts(ms,options);if(!here)return null;
50
+ const startMs=civilNoon(ms,-(here.day-1));
51
+ let length=here.day;
52
+ for(let i=1;i<=FACTS.month_lengths[FACTS.month_lengths.length-1]+1;i++){
53
+ const next=parts(civilNoon(ms,i),options);
54
+ if(!next||next.month!==here.month)break;
55
+ length=next.day;
56
+ }
57
+ return {year:here.year,month:here.month,day:here.day,length,startMs,endMs:civilNoon(startMs,length-1)};
58
+ }
59
+ // First civil day (noon stamp) from fromMs on whose Hijri date is {month,day}. month: number|null (any),
60
+ // day: number|'last'. Returns {ms,hijri} or null (e.g. day 30 in a 29-day month is skipped).
61
+ function nextOccurrence({month=null,day},fromMs,options={}){
62
+ for(let i=0;i<=SEARCH_HORIZON_DAYS;i++){
63
+ const stamp=civilNoon(fromMs,i),h=parts(stamp,options);
64
+ if(!h||(month!=null&&h.month!==Number(month)))continue;
65
+ if(day==='last'){const tomorrow=parts(civilNoon(stamp,1),options);if(tomorrow&&tomorrow.month!==h.month)return {ms:stamp,hijri:h};}
66
+ else if(h.day===Number(day))return {ms:stamp,hijri:h};
67
+ }
68
+ return null;
69
+ }
70
  function matches(event,ms,{parts:resolveParts,forBlocking=false}={}){
71
  const calendar=event?.calendar_rule||{};
72
  if(calendar.type==='daily')return true;
 
82
  if(Array.isArray(calendar.odd_nights)&&!calendar.odd_nights.map(Number).includes(hijri.day))return false;
83
  return true;
84
  }
85
+ return Object.freeze({version:'2.0.0',FACTS,configure,parts,partsAtSunset,monthInfo,nextOccurrence,matches,validConfirmation});
86
  })();
sky_simulation_registry.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "schema_name": "islamic_clock_celestial_simulation_registry",
3
- "schema_version": "1.2.0",
4
  "registry_id": "celestial_simulation_registry",
5
  "project": "ساعة المسلم / الخط الزمني الروحي",
6
  "purpose": "إعدادات العرض البصري لمحاكاة السماء والقبلة. لا يحتوي على أحكام فقهية أو مواقيت صلاة.",
@@ -11,16 +11,16 @@
11
  "أحجام رموز الشمس والقمر والكعبة في العرض",
12
  "نطاقات ظهور العناصر على الشاشة",
13
  "إعدادات ونصوص إتاحة توجيه القبلة والنطق والاهتزاز",
14
- "أطوار القمر الاحتياطية وعتبات رسمه وألوانه",
15
- "إسقاط العناصر على الشاشة وعتبات مراحل السماء",
16
- "نصوص عناوين العناصر ورسائل البوصلة الأساسية"
 
17
  ],
18
  "does_not_own": [
19
  "حساب مواقيت الصلاة",
20
  "الأحكام الفقهية",
21
  "حدود النهي والاستحباب",
22
- "محتوى الأذكار أو العبادات",
23
- "عوامل الظل للعصر (تأتي من fiqh_time_registry)"
24
  ]
25
  },
26
  "sky_color_model": {
@@ -97,8 +97,7 @@
97
  "no_prayer_rulings": true,
98
  "no_fixed_solar_minute_offsets": true,
99
  "visual_only": true,
100
- "shadow_factors_from_fiqh_time_registry": true,
101
- "no_inline_numbers_in_celestial_simulation": true
102
  },
103
  "qibla_accessibility": {
104
  "storage_key": "muslim_clock_qibla_accessibility_v1",
@@ -160,15 +159,18 @@
160
  }
161
  },
162
  "changelog": [
163
- "1.2.0: دمج celestial_core_registry (الجولة الأولى) في هذا السجل: لا ملف مستقل. ثوابت القمر والإسقاط والألوان والنصوص والبوصلة والظل.",
164
- "1.2.0: عوامل الظل (المثل/المثلين) لم تعد هنا؛ تُقرأ من fiqh_time_registry (shadow_factor_boundary)."
 
 
 
 
165
  ],
166
  "qibla": {
167
  "kaaba": {
168
  "lat": 21.422487,
169
  "lng": 39.826206
170
- },
171
- "note_ar": "إحداثيات الكعبة ثابت جغرافي وليست حكمًا."
172
  },
173
  "astronomy": {
174
  "refraction_model": "normal"
@@ -271,36 +273,31 @@
271
  "opacity_visible": "1",
272
  "opacity_dim": ".35"
273
  },
274
- "defaults": {
275
- "alignment_threshold_deg": 4,
276
- "near_alignment_threshold_deg": 12,
277
- "visible_below_horizon_deg": -5,
278
- "size_min_px": 24,
279
- "size_max_px": 44,
280
- "size_altitude_offset_deg": 5,
281
- "size_altitude_span_deg": 70,
282
- "update_interval_ms": 60000,
283
- "object_height_unit": 1,
284
- "observer_elevation_m": 0
285
- },
286
- "compass": {
287
- "no_signal_timeout_ms": 4000,
288
- "flat_projection_below": 0.35,
289
- "note_ar": "مقابض بسيطة تُستخدم فقط إن استُدعيت enableCompass داخل المحاكاة. ضبط الحساس المتقدم (الميل والدقة والمهلة) في qibla_accessibility."
290
- },
291
  "precision": {
292
  "altitude_digits": 1,
293
  "percent_digits": 0,
294
  "degree_digits": 0,
295
  "ratio_digits": 2
296
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
  "texts_ar": {
298
  "moon_title": "{phase} - إضاءة {percent}%",
299
- "qibla_aligned": "أنت متجه نحو القبلة",
300
- "qibla_turn": "حرّك الهاتف {direction} {degrees}° تقريبًا",
301
  "qibla_bearing": "القبلة {degrees}° من الشمال",
302
- "right": "يمينًا",
303
- "left": "يسارًا",
304
  "shadow_length": "طول الظل {ratio} من طول الجسم",
305
  "sun_below_horizon": "الشمس تحت الأفق",
306
  "info_sun": "الشمس {altitude}°",
@@ -308,26 +305,6 @@
308
  "info_qibla_bearing": "القبلة {degrees}°",
309
  "info_qibla_aligned": "القبلة أمامك",
310
  "info_qibla_delta": "فرق القبلة {degrees}°",
311
- "info_separator": " | ",
312
- "compass_secure_required": "الحساسات تحتاج اتصال HTTPS آمن.",
313
- "compass_unsupported": "هذا المتصفح لا يوفر حساس اتجاه للجافاسكربت على هذا الجهاز.",
314
- "compass_permission_denied": "لم يتم منح إذن حساس الاتجاه.",
315
- "compass_enabled": "تم تفعيل اتجاه الهاتف.",
316
- "compass_failed": "تعذر تفعيل حساس الاتجاه.",
317
- "compass_no_signal": "لا توجد قراءة اتجاه مطلقة من هذا الجهاز. يظهر اتجاه القبلة بالنسبة للشمال."
318
- },
319
- "shadow": {
320
- "cache_limit": 8,
321
- "milestones_source": {
322
- "registry": "fiqh_time_registry",
323
- "kind": "shadow_factor_boundary"
324
- },
325
- "render": {
326
- "px_per_ratio": 38,
327
- "min_px": 6,
328
- "max_px": 220,
329
- "opacity_visible": ".42",
330
- "opacity_hidden": "0"
331
- }
332
  }
333
  }
 
1
  {
2
  "schema_name": "islamic_clock_celestial_simulation_registry",
3
+ "schema_version": "2.0.0",
4
  "registry_id": "celestial_simulation_registry",
5
  "project": "ساعة المسلم / الخط الزمني الروحي",
6
  "purpose": "إعدادات العرض البصري لمحاكاة السماء والقبلة. لا يحتوي على أحكام فقهية أو مواقيت صلاة.",
 
11
  "أحجام رموز الشمس والقمر والكعبة في العرض",
12
  "نطاقات ظهور العناصر على الشاشة",
13
  "إعدادات ونصوص إتاحة توجيه القبلة والنطق والاهتزاز",
14
+ "ثوابت نموذج القمر الاحتياطي وأسماء الأطوار وألوان رسمه",
15
+ "إحداثيات الكعبة",
16
+ "إسقاط الأجرام على الشاشة وعتبات مراحل السماء",
17
+ "نصوص المحاكاة العربية"
18
  ],
19
  "does_not_own": [
20
  "حساب مواقيت الصلاة",
21
  "الأحكام الفقهية",
22
  "حدود النهي والاستحباب",
23
+ "محتوى الأذكار أو العبادات"
 
24
  ]
25
  },
26
  "sky_color_model": {
 
97
  "no_prayer_rulings": true,
98
  "no_fixed_solar_minute_offsets": true,
99
  "visual_only": true,
100
+ "merged_core_registry": true
 
101
  },
102
  "qibla_accessibility": {
103
  "storage_key": "muslim_clock_qibla_accessibility_v1",
 
159
  }
160
  },
161
  "changelog": [
162
+ "2.0.0: دمج celestial_core_registry في هذا الملف (مصدر واحد للمحاكاة)",
163
+ "2.0.0: عوامل ظل المثل والمثلين تُقرأ من fiqh_time_registry (asr_shadow_*) ولا تتكرر هنا",
164
+ "2.0.0: رسائل البوصلة والمهلة والميل الأقصى من qibla_accessibility الموجودة"
165
+ ],
166
+ "required_registries": [
167
+ "fiqh_time_registry.json"
168
  ],
169
  "qibla": {
170
  "kaaba": {
171
  "lat": 21.422487,
172
  "lng": 39.826206
173
+ }
 
174
  },
175
  "astronomy": {
176
  "refraction_model": "normal"
 
273
  "opacity_visible": "1",
274
  "opacity_dim": ".35"
275
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  "precision": {
277
  "altitude_digits": 1,
278
  "percent_digits": 0,
279
  "degree_digits": 0,
280
  "ratio_digits": 2
281
  },
282
+ "shadow": {
283
+ "cache_limit": 8,
284
+ "render": {
285
+ "px_per_ratio": 38,
286
+ "min_px": 6,
287
+ "max_px": 220,
288
+ "opacity_visible": ".42",
289
+ "opacity_hidden": "0"
290
+ }
291
+ },
292
+ "defaults": {
293
+ "update_interval_ms": 60000,
294
+ "observer_elevation_m": 0,
295
+ "size_altitude_offset_deg": 5,
296
+ "size_altitude_span_deg": 70
297
+ },
298
  "texts_ar": {
299
  "moon_title": "{phase} - إضاءة {percent}%",
 
 
300
  "qibla_bearing": "القبلة {degrees}° من الشمال",
 
 
301
  "shadow_length": "طول الظل {ratio} من طول الجسم",
302
  "sun_below_horizon": "الشمس تحت الأفق",
303
  "info_sun": "الشمس {altitude}°",
 
305
  "info_qibla_bearing": "القبلة {degrees}°",
306
  "info_qibla_aligned": "القبلة أمامك",
307
  "info_qibla_delta": "فرق القبلة {degrees}°",
308
+ "info_separator": " | "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
  }
310
  }
solar_engine.js CHANGED
@@ -1,15 +1,26 @@
1
- // Astronomy Engine 2.1.19 API adapter. UTC is used internally.
2
- // All display/ruling thresholds are read from fiqh_time_registry.json.
3
- // v2: engine-native altitude search (SearchAltitude/SearchHourAngle) with the original scan kept as fallback,
4
- // solver parameters from the registry, and selectable madhhab variants (worship_fiqh_registry.madhhab_variants).
5
  globalThis.SolarEngine = (() => {
6
- const H=3600000, D=24*H, rad=Math.PI/180;
 
 
 
7
  const ready=()=>Boolean(globalThis.Astronomy?.Equator&&globalThis.Astronomy?.Horizon);
 
 
 
 
 
 
 
 
 
8
  function position(ms,loc){
9
  if(!ready())return null;
10
- const A=globalThis.Astronomy,date=new Date(ms),observer=new A.Observer(loc.lat,loc.lng,loc.height||0);
11
  const equator=A.Equator(A.Body.Sun,date,observer,true,true);
12
- // No extra refraction here: the registry's -0.833 degree horizon already
13
  // incorporates the standard apparent limb/refraction allowance.
14
  const horizon=A.Horizon(date,observer,equator.ra,equator.dec,null);
15
  return {decl:equator.dec,ra:equator.ra,altitude:horizon.altitude,azimuth:horizon.azimuth};
@@ -17,106 +28,118 @@ globalThis.SolarEngine = (() => {
17
  function altitude(ms,loc){
18
  return position(ms,loc)?.altitude??null;
19
  }
20
- function observer(loc){return new globalThis.Astronomy.Observer(loc.lat,loc.lng,loc.height||0);}
21
- const positive=(value,fallback)=>Number(value)>0?Number(value):fallback;
22
- function maximum(day,loc){
23
- const guess=day+12*H-loc.lng/15*H;let lo=guess-6*H,hi=guess+6*H;
24
- for(let i=0;i<60;i++){const a=lo+(hi-lo)/3,b=hi-(hi-lo)/3;if(altitude(a,loc)<altitude(b,loc))lo=a;else hi=b;}
25
  return (lo+hi)/2;
26
  }
27
- // Meridian transit from the ephemeris. Used only as a search window centre, never as a ruling.
28
- function noonApprox(day,loc){
29
- const A=globalThis.Astronomy;
30
- if(ready()&&typeof A.SearchHourAngle==='function'){
31
- try{
32
- const found=A.SearchHourAngle(A.Body.Sun,observer(loc),0,new Date(day+12*H-loc.lng/15*H-6*H),1);
33
- const at=found?.time?.date?.getTime();if(Number.isFinite(at))return at;
34
- }catch{/* fall back to the numerical maximum */}
35
- }
36
- return maximum(day,loc);
37
- }
38
  // Resolve the sign change of the solar altitude rate. The bracket width is
39
  // numerical uncertainty, never a religious duration or an offset after noon.
40
- function transitTransition(day,loc,solver){
41
- const tolerance=Number(solver?.time_tolerance_ms),sample=Number(solver?.derivative_sample_ms);
42
- if(!(tolerance>0&&sample>0))return null;
43
- const half=positive(solver?.bracket_ms,6*H),maxIterations=positive(solver?.max_iterations,80);
44
- const centre=solver?.bracket_ms>0?noonApprox(day,loc):day+12*H-loc.lng/15*H;
45
  const rate=t=>altitude(t+sample/2,loc)-altitude(t-sample/2,loc);
46
- let lo=centre-half,hi=centre+half;
47
  if(!(rate(lo)>0&&rate(hi)<0))return null;
48
- for(let i=0;i<maxIterations&&hi-lo>tolerance;i++){
49
  const mid=(lo+hi)/2;if(rate(mid)<0)hi=mid;else lo=mid;
50
  }
51
  if(!(rate(hi)<0))return null;
52
  return {at:(lo+hi)/2,after:hi,before:lo,uncertainty_ms:hi-lo};
53
  }
54
- // Original fixed-step scan: kept as the fallback when the engine search is unavailable or finds nothing.
55
- function scanCrossing(lo,hi,target,direction,loc,solver){
56
- const step=positive(solver?.scan_step_ms,5*60000),iterations=positive(solver?.bisect_iterations,36);
57
- const rising=direction==='ascending';let prev=lo,pv=altitude(lo,loc)-target;
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  for(let t=lo+step;t<=hi+1;t=Math.min(t+step,hi)){
59
  const val=altitude(t,loc)-target;
60
  if(rising?pv<=0&&val>=0:pv>=0&&val<=0){
61
- let a=prev,b=t;for(let j=0;j<iterations;j++){const m=(a+b)/2,v=altitude(m,loc)-target;if(rising?v<0:v>0)a=m;else b=m;}return(a+b)/2;
62
  }
63
  if(t===hi)break;prev=t;pv=val;
64
  }
65
  return null;
66
  }
67
- // SearchAltitude uses the same geometric altitude as position() (no refraction), so targets such as -0.833 match.
68
- function crossing(lo,hi,target,direction,loc,solver){
69
- const A=globalThis.Astronomy;
70
- if(solver?.use_engine_search!==false&&ready()&&typeof A.SearchAltitude==='function'){
71
- try{
72
- const found=A.SearchAltitude(A.Body.Sun,observer(loc),direction==='ascending'?1:-1,new Date(lo),(hi-lo)/D,target);
73
- const at=found?.date?.getTime();if(Number.isFinite(at)&&at>=lo&&at<=hi)return at;
74
- }catch{/* use the scan below */}
75
- }
76
- return scanCrossing(lo,hi,target,direction,loc,solver);
77
- }
78
- // A madhhab id may name a variant of a base madhhab (worship_fiqh_registry.madhhab_variants).
79
- function choiceOf(rule,madhhab,worship){
80
- const variant=worship.madhhab_variants?.[madhhab],own=rule?.madhhab?.[variant?.base||madhhab],patch=variant?.overrides?.[rule?.id];
81
- return patch?{...(own&&typeof own==='object'?own:{}),...patch}:own;
82
  }
83
  function day(day,loc,profile,worship,madhhab){
84
- if(!ready())return {day,boundaries:{},engineUnavailable:true};
85
- const transition=transitTransition(day,loc,profile.solar_solver);
86
- const noon=transition?.at??maximum(day,loc), out={}, defs=profile.boundaries;
 
 
 
87
  const basic=(id,def)=>{
88
  if(def.op==='maximum')return noon;
89
  if(def.op==='post_transit_transition')return transition?.after??null;
90
- if(def.op==='altitude')return crossing(def.direction==='ascending'?noon-12*H:noon,def.direction==='ascending'?noon:noon+12*H,def.degrees,def.direction,loc,profile.solar_solver);
91
- if(def.op==='altitude_drop')return crossing(noon,noon+12*H,altitude(noon,loc)-def.degrees,'descending',loc,profile.solar_solver);
92
  if(def.op==='shadow'){
93
  const peak=altitude(noon,loc);if(peak<=0)return null;
94
  const target=Math.atan(1/(def.factor+1/Math.tan(peak*rad)))/rad;
95
- return crossing(noon,noon+12*H,target,'descending',loc,profile.solar_solver);
96
  }
97
  return null;
98
  };
99
  Object.entries(defs).forEach(([id,def])=>{out[id]=basic(id,def)});
100
- const nextNoon=noonApprox(day+D,loc);
101
- for(let pass=0;pass<5;pass++)Object.entries(defs).forEach(([id,def])=>{
102
  if(def.op==='alias')out[id]=out[def.boundary]??null;
103
  if(def.op==='next_day'){
104
- const target=defs[def.boundary];out[id]=target?.op==='altitude'?crossing(nextNoon-12*H,nextNoon,target.degrees,target.direction,loc,profile.solar_solver):null;
105
  }
106
  if(def.op==='rule_start'){
107
- const rule=worship.rules.find(r=>r.id===def.rule_id),choice=choiceOf(rule,madhhab,worship);
108
  out[id]=out[choice?.start||rule?.common?.start]??null;
109
  }
110
  if(def.op==='fraction')out[id]=out[def.from]!=null&&out[def.to]!=null?out[def.from]+def.fraction*(out[def.to]-out[def.from]):null;
111
  });
112
- return {day,boundaries:out,solar_transition:transition};
 
 
113
  }
114
- function periods(days,profile,worship,madhhab,styles,scheduleBindings=null){
 
 
 
115
  const out=[];
 
 
 
 
 
 
 
 
 
 
116
  for(const d of days){const b=d.boundaries;
117
  for(const rule of worship.rules){
118
  const state=styles.category_states[rule.category];if(!state)continue;
119
- const choice=choiceOf(rule,madhhab,worship);const common={...rule.common,...(typeof choice==='object'?choice:{}),...profile.rule_time_bindings?.[rule.id]};
 
120
  if(scheduleBindings&&d.methodUnavailable&&state!==styles.category_states.solar_prayer_restriction)continue;
121
  const scheduled=scheduleBindings?.[rule.id];const windows=scheduled?[scheduled]:(typeof choice==='object'&&choice.windows)||rule.windows||[common];
122
  for(const w of windows){
@@ -128,10 +151,10 @@ globalThis.SolarEngine = (() => {
128
  // Preserve the chosen school's outer limit, not a fabricated universal end.
129
  const endId=w.end||common.end||w.outer_end||common.outer_end||w.necessity_end||common.necessity_end||rule.trigger?.end;
130
  let start=b[startId],end=b[endId];
131
- const estimate=worship.display_estimates?.[w.display_estimate_id]||rule.window_display_estimates?.[w.display_estimate_id];
132
- if(estimate){const center=b[estimate.boundary];if(center!=null){start=center-Number(estimate.before_minutes||0)*60000;end=center+Number(estimate.after_minutes||0)*60000;}}
133
- const endEstimate=worship.display_estimates?.[w.display_end_estimate_id||common.display_end_estimate_id];
134
- if(endEstimate){const center=b[endEstimate.boundary];if(center!=null)end=center-Number(endEstimate.before_minutes||0)*60000;}
135
  if(start!=null&&end!=null&&end>=start){
136
  const row={id:rule.id,start,end,point:!estimate&&!endEstimate&&(end===start||Boolean(profile.boundaries[endId]?.transition_only)),startId,endId,state,rule,day:d.day,calculationMethod:scheduled?d.calculationMethod:null,conditional:rule.category==='prayer_restriction'||activation==='after_prayer'||Boolean(requires),requires,activation,displayEstimate:estimate||null,displayEndEstimate:endEstimate||null};out.push(row);
137
  for(const binding of styles.preference_bindings||[]){
@@ -147,5 +170,5 @@ globalThis.SolarEngine = (() => {
147
  }
148
  return out;
149
  }
150
- return {version:'2.0',ready,position,altitude,maximum,noonApprox,transitTransition,crossing,scanCrossing,choiceOf,day,periods};
151
  })();
 
1
+ // Astronomy Engine API adapter. UTC is used internally.
2
+ // Every threshold and every numeric solver setting is read from fiqh_time_registry.json
3
+ // (calculation_profile.solar_solver). Only unit conversions live in this file.
 
4
  globalThis.SolarEngine = (() => {
5
+ const H=3600000, D=24*H, MIN=60000, TURN=360, rad=Math.PI/(TURN/2);
6
+ const REQUIRED_SOLVER=['time_tolerance_ms','derivative_sample_ms','scan_step_ms','bisect_iterations','maximum_iterations',
7
+ 'transition_iterations','noon_search_half_window_ms','crossing_window_ms','alias_passes'];
8
+ let solverCfg=null;
9
  const ready=()=>Boolean(globalThis.Astronomy?.Equator&&globalThis.Astronomy?.Horizon);
10
+ function readSolver(solver){
11
+ if(!solver)return null;
12
+ return REQUIRED_SOLVER.every(key=>Number(solver[key])>0)?solver:null;
13
+ }
14
+ // Call once with profile.solar_solver; day() also does this automatically.
15
+ function configure(solver){solverCfg=readSolver(solver);return Boolean(solverCfg);}
16
+ const noonGuess=(day,loc)=>day+D/2-loc.lng/TURN*D;
17
+ const observerFor=loc=>new globalThis.Astronomy.Observer(loc.lat,loc.lng,loc.height||0);
18
+
19
  function position(ms,loc){
20
  if(!ready())return null;
21
+ const A=globalThis.Astronomy,date=new Date(ms),observer=observerFor(loc);
22
  const equator=A.Equator(A.Body.Sun,date,observer,true,true);
23
+ // No extra refraction here: the registry's sunrise/sunset altitude already
24
  // incorporates the standard apparent limb/refraction allowance.
25
  const horizon=A.Horizon(date,observer,equator.ra,equator.dec,null);
26
  return {decl:equator.dec,ra:equator.ra,altitude:horizon.altitude,azimuth:horizon.azimuth};
 
28
  function altitude(ms,loc){
29
  return position(ms,loc)?.altitude??null;
30
  }
31
+ function maximum(day,loc,cfg=solverCfg){
32
+ if(!cfg)return null;
33
+ const guess=noonGuess(day,loc);let lo=guess-cfg.noon_search_half_window_ms,hi=guess+cfg.noon_search_half_window_ms;
34
+ for(let i=0;i<cfg.maximum_iterations;i++){const a=lo+(hi-lo)/3,b=hi-(hi-lo)/3;if(altitude(a,loc)<altitude(b,loc))lo=a;else hi=b;}
 
35
  return (lo+hi)/2;
36
  }
 
 
 
 
 
 
 
 
 
 
 
37
  // Resolve the sign change of the solar altitude rate. The bracket width is
38
  // numerical uncertainty, never a religious duration or an offset after noon.
39
+ function transitTransition(day,loc,solver=solverCfg){
40
+ const cfg=readSolver(solver);if(!cfg)return null;
41
+ const tolerance=cfg.time_tolerance_ms,sample=cfg.derivative_sample_ms;
42
+ const guess=noonGuess(day,loc);
 
43
  const rate=t=>altitude(t+sample/2,loc)-altitude(t-sample/2,loc);
44
+ let lo=guess-cfg.noon_search_half_window_ms,hi=guess+cfg.noon_search_half_window_ms;
45
  if(!(rate(lo)>0&&rate(hi)<0))return null;
46
+ for(let i=0;i<cfg.transition_iterations&&hi-lo>tolerance;i++){
47
  const mid=(lo+hi)/2;if(rate(mid)<0)hi=mid;else lo=mid;
48
  }
49
  if(!(rate(hi)<0))return null;
50
  return {at:(lo+hi)/2,after:hi,before:lo,uncertainty_ms:hi-lo};
51
  }
52
+ // Fast exact search through Astronomy.SearchAltitude (geometric altitude, same
53
+ // convention as position()); the sampled scan below remains the reference path.
54
+ function searchAltitude(lo,hi,target,direction,loc){
55
+ const A=globalThis.Astronomy;
56
+ try{
57
+ const hit=A.SearchAltitude(A.Body.Sun,observerFor(loc),direction==='ascending'?1:-1,new Date(lo),(hi-lo)/D,target);
58
+ const at=hit?hit.date.getTime():null;
59
+ return {ok:true,at:at!=null&&at>=lo&&at<=hi?at:null};
60
+ }catch{return {ok:false,at:null};}
61
+ }
62
+ function crossing(lo,hi,target,direction,loc,cfg=solverCfg){
63
+ if(!cfg)return null;
64
+ if(cfg.use_astronomy_search_functions&&typeof globalThis.Astronomy?.SearchAltitude==='function'){
65
+ const fast=searchAltitude(lo,hi,target,direction,loc);
66
+ if(fast.ok)return fast.at;
67
+ }
68
+ const step=cfg.scan_step_ms,rising=direction==='ascending';let prev=lo,pv=altitude(lo,loc)-target;
69
  for(let t=lo+step;t<=hi+1;t=Math.min(t+step,hi)){
70
  const val=altitude(t,loc)-target;
71
  if(rising?pv<=0&&val>=0:pv>=0&&val<=0){
72
+ let a=prev,b=t;for(let j=0;j<cfg.bisect_iterations;j++){const m=(a+b)/2,v=altitude(m,loc)-target;if(rising?v<0:v>0)a=m;else b=m;}return(a+b)/2;
73
  }
74
  if(t===hi)break;prev=t;pv=val;
75
  }
76
  return null;
77
  }
78
+ // normal | always_up | always_down, from the registry's sunrise altitude. Lets the UI
79
+ // explain why twilight/sunrise boundaries are unavailable instead of showing nothing.
80
+ function polarState(noon,loc,profile){
81
+ const horizon=profile?.boundaries?.sunrise?.degrees;
82
+ if(!Number.isFinite(horizon)||!Number.isFinite(noon))return null;
83
+ const top=altitude(noon,loc),bottom=altitude(noon+D/2,loc);
84
+ if(top==null||bottom==null)return null;
85
+ return bottom>horizon?'always_up':top<horizon?'always_down':'normal';
 
 
 
 
 
 
 
86
  }
87
  function day(day,loc,profile,worship,madhhab){
88
+ if(!ready())return {day,boundaries:{},engineUnavailable:true,reason:'astronomy_engine_missing'};
89
+ const cfg=readSolver(profile.solar_solver);
90
+ if(!cfg)return {day,boundaries:{},engineUnavailable:true,reason:'solver_config_missing'};
91
+ solverCfg=cfg;
92
+ const transition=transitTransition(day,loc,cfg);
93
+ const noon=transition?.at??maximum(day,loc,cfg), out={}, defs=profile.boundaries, win=cfg.crossing_window_ms;
94
  const basic=(id,def)=>{
95
  if(def.op==='maximum')return noon;
96
  if(def.op==='post_transit_transition')return transition?.after??null;
97
+ if(def.op==='altitude')return crossing(def.direction==='ascending'?noon-win:noon,def.direction==='ascending'?noon:noon+win,def.degrees,def.direction,loc,cfg);
98
+ if(def.op==='altitude_drop')return crossing(noon,noon+win,altitude(noon,loc)-def.degrees,'descending',loc,cfg);
99
  if(def.op==='shadow'){
100
  const peak=altitude(noon,loc);if(peak<=0)return null;
101
  const target=Math.atan(1/(def.factor+1/Math.tan(peak*rad)))/rad;
102
+ return crossing(noon,noon+win,target,'descending',loc,cfg);
103
  }
104
  return null;
105
  };
106
  Object.entries(defs).forEach(([id,def])=>{out[id]=basic(id,def)});
107
+ const nextNoon=maximum(day+D,loc,cfg);
108
+ for(let pass=0;pass<cfg.alias_passes;pass++)Object.entries(defs).forEach(([id,def])=>{
109
  if(def.op==='alias')out[id]=out[def.boundary]??null;
110
  if(def.op==='next_day'){
111
+ const target=defs[def.boundary];out[id]=target?.op==='altitude'?crossing(nextNoon-win,nextNoon,target.degrees,target.direction,loc,cfg):null;
112
  }
113
  if(def.op==='rule_start'){
114
+ const rule=worship.rules.find(r=>r.id===def.rule_id),choice=rule?.madhhab?.[madhhab];
115
  out[id]=out[choice?.start||rule?.common?.start]??null;
116
  }
117
  if(def.op==='fraction')out[id]=out[def.from]!=null&&out[def.to]!=null?out[def.from]+def.fraction*(out[def.to]-out[def.from]):null;
118
  });
119
+ const unavailable={};
120
+ Object.entries(defs).forEach(([id,def])=>{if(out[id]==null)unavailable[id]=def.op==='altitude'||def.op==='shadow'||def.op==='next_day'||def.op==='altitude_drop'?'no_crossing':'dependency_missing';});
121
+ return {day,boundaries:out,solar_transition:transition,polar:polarState(noon,loc,profile),unavailable};
122
  }
123
+ // options.display_estimate_overrides: {[estimateId]:{before_minutes,after_minutes}} (user choice; honoured
124
+ // only for values listed in the estimate's user_choices_before_minutes).
125
+ // options.isRuleActive(rule,dayStamp): lets the calendar layer hide rules that apply only on certain dates.
126
+ function periods(days,profile,worship,madhhab,styles,scheduleBindings=null,options={}){
127
  const out=[];
128
+ const resolveEstimate=(id,rule)=>{
129
+ if(!id)return null;
130
+ const table={...(worship.display_estimates||{}),...(rule.window_display_estimates||{})};
131
+ let key=id,estimate=table[key];
132
+ if(estimate?.deprecated_alias_of){key=estimate.deprecated_alias_of;estimate=table[key];}
133
+ if(!estimate)return null;
134
+ const override=options.display_estimate_overrides?.[key];
135
+ if(override&&(!estimate.user_choices_before_minutes||estimate.user_choices_before_minutes.includes(Number(override.before_minutes))))return {...estimate,...override,id:key};
136
+ return {...estimate,id:key};
137
+ };
138
  for(const d of days){const b=d.boundaries;
139
  for(const rule of worship.rules){
140
  const state=styles.category_states[rule.category];if(!state)continue;
141
+ if(options.isRuleActive&&!options.isRuleActive(rule,d.day))continue;
142
+ const choice=rule.madhhab?.[madhhab];const common={...rule.common,...(typeof choice==='object'?choice:{}),...profile.rule_time_bindings?.[rule.id]};
143
  if(scheduleBindings&&d.methodUnavailable&&state!==styles.category_states.solar_prayer_restriction)continue;
144
  const scheduled=scheduleBindings?.[rule.id];const windows=scheduled?[scheduled]:(typeof choice==='object'&&choice.windows)||rule.windows||[common];
145
  for(const w of windows){
 
151
  // Preserve the chosen school's outer limit, not a fabricated universal end.
152
  const endId=w.end||common.end||w.outer_end||common.outer_end||w.necessity_end||common.necessity_end||rule.trigger?.end;
153
  let start=b[startId],end=b[endId];
154
+ const estimate=resolveEstimate(w.display_estimate_id,rule);
155
+ if(estimate){const center=b[estimate.boundary];if(center!=null){start=center-Number(estimate.before_minutes||0)*MIN;end=center+Number(estimate.after_minutes||0)*MIN;}}
156
+ const endEstimate=resolveEstimate(w.display_end_estimate_id||common.display_end_estimate_id,rule);
157
+ if(endEstimate){const center=b[endEstimate.boundary];if(center!=null)end=center-Number(endEstimate.before_minutes||0)*MIN;}
158
  if(start!=null&&end!=null&&end>=start){
159
  const row={id:rule.id,start,end,point:!estimate&&!endEstimate&&(end===start||Boolean(profile.boundaries[endId]?.transition_only)),startId,endId,state,rule,day:d.day,calculationMethod:scheduled?d.calculationMethod:null,conditional:rule.category==='prayer_restriction'||activation==='after_prayer'||Boolean(requires),requires,activation,displayEstimate:estimate||null,displayEndEstimate:endEstimate||null};out.push(row);
160
  for(const binding of styles.preference_bindings||[]){
 
170
  }
171
  return out;
172
  }
173
+ return {version:'2.0.0',ready,configure,position,altitude,maximum,transitTransition,crossing,polarState,day,periods};
174
  })();
worship_fiqh_registry.json CHANGED
@@ -21,33 +21,6 @@
21
  "shafii": "الشافعي",
22
  "hanbali": "الحنبلي"
23
  },
24
- "madhhab_variants": {
25
- "hanafi_sahibayn": {
26
- "base": "hanafi",
27
- "label_ar": "الحنفي — قول أبي يوسف ومحمد",
28
- "ui_exposed": false,
29
- "overrides": {
30
- "dhuhr": {
31
- "end": "asr_shadow_1"
32
- },
33
- "asr": {
34
- "start": "asr_shadow_1"
35
- },
36
- "isha_entry": {
37
- "start": "red_twilight_end"
38
- },
39
- "maghrib": {
40
- "end": "red_twilight_end"
41
- }
42
- },
43
- "derived_ar": "نهاية المغرب تتبع بداية العشاء عند الصاحبين (الشفق الأحمر).",
44
- "sources": [
45
- "hanafi_asr",
46
- "isha_twilight"
47
- ]
48
- }
49
- },
50
- "madhhab_variants_note_ar": "نسخ داخل المذهب الواحد. يمرَّر معرّف النسخة إلى المحرك بدل معرّف المذهب، فيُطبَّق overrides فوق قيم المذهب الأساسي. لا يُعرَض في الواجهة ما لم تُفعَّل ui_exposed.",
51
  "rules": [
52
  {
53
  "id": "fajr",
@@ -260,8 +233,7 @@
260
  },
261
  "sources": [
262
  "jumuah"
263
- ],
264
- "engine_note_ar": "لا يولّد periods() نافذة للجمعة لأن end_relation وصفية وليست معرّف حدّ. لعرضها أضف end (معرّف حدّ) لكل مذهب."
265
  },
266
  {
267
  "id": "after_fajr_nafl_restriction",
@@ -344,17 +316,21 @@
344
  "category": "solar_prayer_restriction",
345
  "scope": "absolute_solar_windows",
346
  "window_display_estimates": {
347
- "zawal_20_minutes": {
348
- "boundary": "zawal",
349
  "before_minutes": 10,
350
  "after_minutes": 0,
351
- "choices_before_minutes": [
352
  10,
353
  15
354
  ],
355
- "label_ar": "نافذة عرض تقديرية قبيل الزوال (10 دقائق قبله)",
356
- "note_ar": "مدة عرض احتياطية تنتهي عند حدّ الزوال المحسوب؛ فلا يُعرض نهي بعد زوال الشمس. اختير 10 دقائق (والخيار 15) وليست ادعاءً بأن مدة النهي ثابتة. الحد الفلكي المحسوب يبقى محفوظًا مستقلًا. معرّف الإعداد zawal_20_minutes بقي كما هو للتوافق مع الملفات التي تشير إليه.",
 
357
  "source_id": "zawal_duration_research"
 
 
 
358
  }
359
  },
360
  "madhhab": {
@@ -367,7 +343,7 @@
367
  {
368
  "start": "solar_noon",
369
  "end": "zawal",
370
- "display_estimate_id": "zawal_20_minutes"
371
  },
372
  {
373
  "start": "sunset_approach",
@@ -401,7 +377,7 @@
401
  "exclude_weekdays": [
402
  "friday"
403
  ],
404
- "display_estimate_id": "zawal_20_minutes"
405
  },
406
  {
407
  "start": "sunset_approach",
@@ -419,7 +395,7 @@
419
  {
420
  "start": "solar_noon",
421
  "end": "zawal",
422
- "display_estimate_id": "zawal_20_minutes"
423
  },
424
  {
425
  "start": "sunset_approach",
@@ -428,8 +404,8 @@
428
  ]
429
  }
430
  },
431
- "implementation": "الحدود هندسة شمسية بلا دقائق ثابتة؛ نافذة الزوال التقديرية (قبل الزوال فقط) سياسة عرض احتياطية وليست بديلًا عن الحد الفلكي.",
432
- "note": "اختيار النوافذ نفسها مذهبي. تعرض نافذة الزوال قبيل الزوال فقط بمدة تقديرية احتياطية (10 دقائق افتراضيًا)، مع بيان أن الأبحاث المذكورة تقدر المنطقة الأقرب للزوال عادةً بنحو 5–10 دقائق. أما استثناءات أنواع الصلوات كذوات الأسباب والقضاء والجنازة والطواف فلا تختزل في لون زمني عام، وتعرض في تفاصيل الحكم.",
433
  "sources": [
434
  "prohibition_comparative",
435
  "solar_prohibition",
@@ -553,17 +529,90 @@
553
  "no_completion_tracking": true,
554
  "no_fixed_solar_minute_offsets": true,
555
  "preserve_madhhab_variants": true,
556
- "display_only_estimates": [
557
- "zawal_20_minutes"
558
- ],
559
- "display_only_estimates_note_ar": "دقائق ثابتة مسموحة للعرض فقط ولا تدخل في أي حساب شرعي.",
560
- "cross_registry_validator": "tools/validate_registries.js"
561
  },
562
  "research_note": "هذه طبقة بيانات للتطبيق وليست فتوى شخصية. حيث لم تكف المصادر لإغلاق تفصيل مذهبي دقيق، أبقي التفصيل معلّقًا بدل اختراع قيمة.",
563
  "changelog": [
564
- "1.3.0: madhhab_variants — الأقوال المحفوظة نصًّا في variant صارت قابلة للاختيار (hanafi_sahibayn) دون تغيير المذاهب الأربعة.",
565
- "1.3.0: نافذة الزوال التقديرية صارت قبل الزوال فقط (10 دقائق) وتنتهي عند حدّ الزوال؛ لا يُعرض نهي بعد الزوال. كانت ±10 حول الاستواء.",
566
- "1.3.0: validation.display_only_estimates يعلن الدقائق الثابتة المسموحة للعرض فقط، لإزالة التناقض مع no_fixed_solar_minute_offsets.",
567
- "1.3.0: ملاحظة هندسية: Jumuah لا تُولَّد لها نافذة لأن end_relation وصفية."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
568
  ]
569
  }
 
21
  "shafii": "الشافعي",
22
  "hanbali": "الحنبلي"
23
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  "rules": [
25
  {
26
  "id": "fajr",
 
233
  },
234
  "sources": [
235
  "jumuah"
236
+ ]
 
237
  },
238
  {
239
  "id": "after_fajr_nafl_restriction",
 
316
  "category": "solar_prayer_restriction",
317
  "scope": "absolute_solar_windows",
318
  "window_display_estimates": {
319
+ "zawal_display_window": {
320
+ "boundary": "solar_noon",
321
  "before_minutes": 10,
322
  "after_minutes": 0,
323
+ "user_choices_before_minutes": [
324
  10,
325
  15
326
  ],
327
+ "settings_key": "zawal_before_minutes",
328
+ "label_ar": "نافذة عرض قبيل الزوال",
329
+ "note_ar": "نافذة عرض فقط قبل الزوال: تبدأ قبل الاستواء بالمقدار المختار وتنتهي عند الاستواء. بعد الزوال يدخل وقت الظهر فلا تمتد النافذة بعده. القيمتان 10 و15 خيارا عرض، وليستا حدًّا فلكيًا ولا تحديدًا شرعيًا للمدة؛ الأبحاث المذكورة تقدّر المنطقة القريبة من الزوال عادةً بنحو 5–10 دقائق.",
330
  "source_id": "zawal_duration_research"
331
+ },
332
+ "zawal_20_minutes": {
333
+ "deprecated_alias_of": "zawal_display_window"
334
  }
335
  },
336
  "madhhab": {
 
343
  {
344
  "start": "solar_noon",
345
  "end": "zawal",
346
+ "display_estimate_id": "zawal_display_window"
347
  },
348
  {
349
  "start": "sunset_approach",
 
377
  "exclude_weekdays": [
378
  "friday"
379
  ],
380
+ "display_estimate_id": "zawal_display_window"
381
  },
382
  {
383
  "start": "sunset_approach",
 
395
  {
396
  "start": "solar_noon",
397
  "end": "zawal",
398
+ "display_estimate_id": "zawal_display_window"
399
  },
400
  {
401
  "start": "sunset_approach",
 
404
  ]
405
  }
406
  },
407
+ "implementation": "الحدود هندسة شمسية بلا دقائق ثابتة؛ نافذة قبيل الزوال سياسة عرض قبل الاستواء فقط وليست بديلًا عن الحد الفلكي، ويمكن للمستخدم اختيار 10 أو 15 دقيقة.",
408
+ "note": "اختيار النوافذ نفسها مذهبي. تعرض نافذة الزوال بمدة عرض احتياطية قبل الزوال فقط (10 افتراضيًا و15 خيار المستخدم)، مع بيان أن الأبحاث المذكورة تقدر المنطقة الأقرب للزوال عادةً بنحو 5–10 دقائق. أما استثناءات أنواع الصلوات كذوات الأسباب والقضاء والجنازة والطواف فلا تختزل في لون زمني عام، وتعرض في تفاصيل الحكم.",
409
  "sources": [
410
  "prohibition_comparative",
411
  "solar_prohibition",
 
529
  "no_completion_tracking": true,
530
  "no_fixed_solar_minute_offsets": true,
531
  "preserve_madhhab_variants": true,
532
+ "proposed_rules_not_consumed_by_periods": true
 
 
 
 
533
  },
534
  "research_note": "هذه طبقة بيانات للتطبيق وليست فتوى شخصية. حيث لم تكف المصادر لإغلاق تفصيل مذهبي دقيق، أبقي التفصيل معلّقًا بدل اختراع قيمة.",
535
  "changelog": [
536
+ "1.3.0: تصحيح نافذة الزوال: كانت ±10 دقائق حول الاستواء وتشمل عشر دقائق بعد دخول وقت الظهر؛ أصبحت قبل الزوال فقط (10 افتراضيًا، 15 خيار المستخدم)",
537
+ "1.3.0: معرّف النافذة zawal_display_window وبقاء الاسم القديم كمرادف مهجور",
538
+ "1.3.0: أحكام مقترحة غير مفعّلة في proposed_rules حتى توثيق المصادر وربط التفعيل بسجل الأحداث"
539
+ ],
540
+ "proposed_rules": [
541
+ {
542
+ "id": "eid_prayer",
543
+ "category": "festival_prayer",
544
+ "status": "proposed_not_consumed",
545
+ "activation": {
546
+ "owner": "islamic_events_registry.json",
547
+ "note_ar": "تُفعَّل في يومي العيد فقط من سجل الأحداث، ولا تُعرض يوميًا."
548
+ },
549
+ "common": {
550
+ "start": "sunrise_clear",
551
+ "end": "zawal"
552
+ },
553
+ "madhhab": {
554
+ "hanafi": {
555
+ "ruling": "wajib"
556
+ },
557
+ "maliki": {
558
+ "ruling": "sunnah_muakkadah"
559
+ },
560
+ "shafii": {
561
+ "ruling": "sunnah_muakkadah"
562
+ },
563
+ "hanbali": {
564
+ "ruling": "fard_kifayah"
565
+ }
566
+ },
567
+ "research_status": "needs_sources",
568
+ "needs_visual_state": "festival_prayer",
569
+ "note": "الحد المشترك: من ارتفاع الشمس إلى الزوال. التفاصيل المذهبية تحتاج توثيق مصادر قبل التفعيل."
570
+ },
571
+ {
572
+ "id": "suhoor",
573
+ "category": "recommended_fasting_meal",
574
+ "status": "proposed_not_consumed",
575
+ "activation": {
576
+ "owner": "islamic_events_registry.json",
577
+ "note_ar": "أيام الصيام فقط."
578
+ },
579
+ "common": {
580
+ "preferred": "آخر الليل",
581
+ "end": "true_dawn"
582
+ },
583
+ "sources": [
584
+ "quran_2_187"
585
+ ],
586
+ "research_status": "needs_sources",
587
+ "note": "الأكل والشرب مباحان حتى يتبين الفجر الصادق (البقرة 187). تُوثَّق سنية السحور من مصدر حديثي قبل التفعيل."
588
+ },
589
+ {
590
+ "id": "iftar",
591
+ "category": "recommended_fasting_meal",
592
+ "status": "proposed_not_consumed",
593
+ "activation": {
594
+ "owner": "islamic_events_registry.json",
595
+ "note_ar": "أيام الصيام فقط."
596
+ },
597
+ "common": {
598
+ "start": "sunset"
599
+ },
600
+ "research_status": "needs_sources",
601
+ "note": "يدخل وقت الإفطار بغروب الشمس. حد الغروب الشمسي المحسوب مستقل عن تأخير موعد المغرب في طريقة الأردن."
602
+ },
603
+ {
604
+ "id": "eclipse_prayer",
605
+ "category": "occasional_prayer",
606
+ "status": "proposed_not_consumed",
607
+ "time_source": {
608
+ "owner": "astronomy_events_registry.json",
609
+ "practice_id": "eclipse_prayer",
610
+ "note_ar": "وقتها من محرك الكسوف والخسوف المحلي (الجزء المرئي فقط) ولا يُحسب من هذا الملف."
611
+ },
612
+ "restriction_relation": {
613
+ "status": "pending_scholar_review",
614
+ "note_ar": "علاقتها بأوقات النهي مذهبية؛ لا تُدرج قيمة قبل توثيق المصادر."
615
+ }
616
+ }
617
  ]
618
  }