22 * ملف بدائل (polyfills) للمشروع
33 * يساعد في توفير بعض الدوال المطلوبة للتشغيل على الويب
44 *
5- * v1.0.1 - بناء محسن للويب
5+ * v1.0.1 - 2024 - بناء محسن للويب
66 */
77
88// استيراد polyfill لـ URL
@@ -22,66 +22,104 @@ function createSimpleId(size = 21): string {
2222 return id ;
2323}
2424
25- // إصلاح مشكلة nanoid
26- if ( typeof global !== 'undefined' ) {
27- const g = global as any ;
25+ // إصلاح مشكلة nanoid عالمياً
26+ try {
27+ // بيئة node/global
28+ if ( typeof global !== 'undefined' ) {
29+ const g = global as any ;
30+
31+ // تأكد من وجود nanoid في النطاق العالمي
32+ if ( ! g . nanoid ) {
33+ g . nanoid = createSimpleId ;
34+ }
35+
36+ // دعم كائن r مع nanoid
37+ if ( ! g . r ) {
38+ g . r = { } ;
39+ }
40+ if ( ! g . r . nanoid ) {
41+ g . r . nanoid = createSimpleId ;
42+ }
43+ }
2844
29- // تأكد من وجود nanoid في النطاق العالمي
30- if ( ! g . nanoid ) {
31- g . nanoid = createSimpleId ;
45+ // بيئة المتصفح/window
46+ if ( typeof window !== 'undefined' ) {
47+ const w = window as any ;
48+
49+ // إضافة nanoid للويب
50+ if ( ! w . nanoid ) {
51+ w . nanoid = createSimpleId ;
52+ }
53+
54+ // إضافة كائن r.nanoid - هذا تحديداً يصلح الخطأ من useRegisterNavigator.tsx
55+ if ( ! w . r ) {
56+ w . r = { } ;
57+ }
58+
59+ if ( ! w . r . nanoid ) {
60+ w . r . nanoid = createSimpleId ;
61+ }
62+
63+ // إضافة لمودولات ES
64+ if ( ! w . module ) {
65+ w . module = { } ;
66+ }
67+
68+ if ( ! w . module . exports ) {
69+ w . module . exports = { } ;
70+ }
71+
72+ w . module . exports . nanoid = createSimpleId ;
73+
74+ // إصلاح لـ ToastAndroid
75+ if ( ! w . ToastAndroid ) {
76+ w . ToastAndroid = {
77+ show : function ( message : string , duration : number ) {
78+ console . log ( '[Toast]' , message ) ;
79+ setTimeout ( ( ) => {
80+ if ( typeof alert === 'function' ) {
81+ alert ( message ) ;
82+ }
83+ } , 0 ) ;
84+ } ,
85+ SHORT : 0 ,
86+ LONG : 1
87+ } ;
88+ }
3289 }
90+
91+ // إصلاح لمشكلة document.currentScript.src - يستخدم في expo-router
92+ if ( typeof document !== 'undefined' && ! document . currentScript ) {
93+ Object . defineProperty ( document , 'currentScript' , {
94+ get : function ( ) {
95+ return { src : '/index.js' } ;
96+ }
97+ } ) ;
98+ }
99+ } catch ( error ) {
100+ console . error ( 'فشل في تطبيق البدائل:' , error ) ;
33101}
34102
35103// بديل لـ nanoid للتصدير
36104export const nanoid = createSimpleId ;
37105
38- // إصلاح للويب
39- if ( typeof window !== 'undefined' ) {
40- const w = window as any ;
41-
42- // إضافة nanoid للويب
43- if ( ! w . nanoid ) {
44- w . nanoid = createSimpleId ;
45- }
46-
47- // إضافة كائن r.nanoid - هذا تحديداً يصلح الخطأ من useRegisterNavigator.tsx
48- if ( ! w . r ) {
49- w . r = { } ;
50- }
106+ // للفحص والتأكد من أن الكود يعمل
107+ try {
108+ // تأكد من أن nanoid متاح ويمكن تنفيذه
109+ const testId = typeof nanoid === 'function' ? nanoid ( ) : createSimpleId ( ) ;
51110
52- if ( ! w . r . nanoid ) {
53- w . r . nanoid = createSimpleId ;
54- }
111+ // إضافة تعليق لإظهار أن الملف تم تحميله
112+ console . log ( '[polyfills] تم تحميل البدائل لدعم التشغيل على الويب | v1.0.1' ) ;
113+ console . log ( '[polyfills] اختبار nanoid:' , testId ) ;
55114
56- // إصلاح لـ ToastAndroid
57- if ( ! w . ToastAndroid ) {
58- w . ToastAndroid = {
59- show : function ( message : string , duration : number ) {
60- console . log ( '[Toast]' , message ) ;
61- setTimeout ( ( ) => {
62- if ( typeof alert === 'function' ) {
63- alert ( message ) ;
64- }
65- } , 0 ) ;
66- } ,
67- SHORT : 0 ,
68- LONG : 1
69- } ;
115+ // اختبار r.nanoid إذا كان متاحاً
116+ if ( typeof window !== 'undefined' && ( window as any ) . r && typeof ( window as any ) . r . nanoid === 'function' ) {
117+ console . log ( '[polyfills] اختبار r.nanoid:' , ( window as any ) . r . nanoid ( ) ) ;
70118 }
119+ } catch ( error ) {
120+ console . error ( '[polyfills] خطأ في الاختبار:' , error ) ;
71121}
72122
73- // إصلاح لمشكلة document.currentScript.src - يستخدم في expo-router
74- if ( typeof document !== 'undefined' && ! document . currentScript ) {
75- Object . defineProperty ( document , 'currentScript' , {
76- get : function ( ) {
77- return { src : '/index.js' } ;
78- }
79- } ) ;
80- }
81-
82- // إضافة تعليق لإظهار أن الملف تم تحميله
83- console . log ( '[polyfills] تم تحميل البدائل لدعم التشغيل على الويب | v1.0.1' ) ;
84-
85123// export للتوافق كـ module
86124export default {
87125 nanoid : createSimpleId ,
0 commit comments