@conecli/cone-render 0.10.1-shop-beta.60 → 0.10.1-shop-beta.61

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.
@@ -1 +1 @@
1
- import Taro from '@tarojs/taro';
2
1
  'app-activity',
3
2
  'app-rank',
4
3
  'app-seckill',
5
4
  'm-coupon',
6
5
  'scene-buy',
7
6
  'light-details',
8
7
  'member-paid-center',
9
8
  'member-paid-card',
10
9
  'member-paid-bind',
11
10
  'app-introduce',
12
11
  'app-search-result',
13
12
  if (window?.shopGlobalSwitch?.openAccessibilityLanguage) {
14
13
  Taro.nextTick(() => {
15
14
  const htmlRoot = document?.documentElement;
16
15
  htmlRoot && htmlRoot.setAttribute('lang', isLanguageForEn ? 'en' : 'zh-CN');
17
16
  });
18
17
  }
19
18
  const mainConfig = {
20
19
  childList: true,
21
20
  subtree: true,
22
21
  attributes: true,
23
22
  attributeFilter: ['auto-accessible'],
24
23
  };
25
24
  const mainObserver = new MutationObserver(function (mutations) {
26
25
  mutations.forEach(function (mutation) {
27
26
  if (mutation.type === 'childList') {
28
27
  mutation.addedNodes.forEach(function (node) {
29
28
  if (node.nodeType === Node.ELEMENT_NODE) {
30
29
  if (node.hasAttribute && node.getAttribute('auto-accessible') === 'true') {
31
30
  updateAccessibilityLabel(node);
32
31
  }
33
32
  const accessibleElements = node.querySelectorAll
34
33
  ? node.querySelectorAll('[auto-accessible="true"]')
35
34
  : [];
36
35
  accessibleElements.forEach(function (el) {
37
36
  updateAccessibilityLabel(el);
38
37
  });
39
38
  }
40
39
  });
41
40
  }
42
41
  if (mutation.type === 'attributes' && mutation.attributeName === 'auto-accessible') {
43
42
  if (mutation.target.getAttribute('auto-accessible') === 'true') {
44
43
  updateAccessibilityLabel(mutation.target);
45
44
  }
46
45
  }
47
46
  });
48
47
  });
49
48
  mainObserver.observe(document.body, mainConfig);
50
49
  setupGlobalContentObserver();
51
50
  const contentConfig = {
52
51
  characterData: true,
53
52
  childList: true,
54
53
  subtree: true,
55
54
  };
56
55
  const lastUpdateTime = new WeakMap();
57
56
  const THROTTLE_DELAY = 2000;
58
57
 
59
58
  function shouldUpdate(element) {
60
59
  const now = Date.now();
61
60
  const lastTime = lastUpdateTime.get(element);
62
61
  if (!lastTime || now - lastTime >= THROTTLE_DELAY) {
63
62
  lastUpdateTime.set(element, now);
64
63
  return true;
65
64
  }
66
65
  return false;
67
66
  }
68
67
  const globalContentObserver = new MutationObserver(function (mutations) {
69
68
  const affectedElements = new Set();
70
69
  mutations.forEach(function (mutation) {
71
70
  let targetElement = null;
72
71
  if (mutation.type === 'characterData') {
73
72
  targetElement = findClosestAccessibleElement(mutation.target);
74
73
  } else if (mutation.type === 'childList') {
75
74
  targetElement = findClosestAccessibleElement(mutation.target);
76
75
  }
77
76
  if (targetElement && targetElement.getAttribute('auto-accessible') === 'true') {
78
77
  affectedElements.add(targetElement);
79
78
  }
80
79
  });
81
80
  affectedElements.forEach(function (element) {
82
81
  if (shouldUpdate(element)) {
83
82
  updateAccessibilityLabel(element);
84
83
  } else {
85
84
  }
86
85
  });
87
86
  });
88
87
  globalContentObserver.observe(document.body, contentConfig);
89
88
  let current = node;
90
89
  if (current.nodeType === Node.TEXT_NODE) {
91
90
  current = current.parentElement;
92
91
  }
93
92
  while (current && current !== document.body) {
94
93
  if (current.getAttribute && current.getAttribute('auto-accessible') === 'true') {
95
94
  return current;
96
95
  }
97
96
  current = current.parentElement;
98
97
  }
99
98
  return null;
100
99
  if (!element) return;
101
100
  if (element.hasAttribute('aria-label')) {
102
101
  completeA11yAttributes(element);
103
102
  if (!element.getAttribute('data-auto-aria-label')) {
104
103
  return;
105
104
  }
106
105
  }
107
106
  const text = element.innerText;
108
107
  if (text) {
109
108
  const processedText = text.replace(/\r|\n/g, ' ').replace(/¥\s(\d+)(\s(\.\d+))?/, '¥$1$3');
110
109
  element.setAttribute('aria-label', processedText);
111
110
  element.setAttribute('data-auto-aria-label', 'true');
112
111
  completeA11yAttributes(element);
113
112
  }
114
113
  if (!element.hasAttribute('role')) {
115
114
  element.setAttribute('role', 'text');
116
115
  }
117
116
  if (!element.hasAttribute('tabindex')) {
118
117
  element.setAttribute('tabindex', 0);
119
118
  }
120
119
  const routerURL = 'router://JDShopModule/isAccessibilityIsRunning';
121
120
  const callBackName = `nativeGetAccessibilityIsRunning${Date.now()}`;
122
121
  let params: any = {
123
122
  routerURL,
124
123
  routerParam: null,
125
124
  callBackName,
126
125
  };
127
126
  return new Promise((resolve) => {
128
127
  window[callBackName] = (res) => {
129
128
  let data;
130
129
  try {
131
130
  data = typeof res === 'string' ? JSON.parse(res) : res;
132
131
  } catch (e) {
133
132
  console.error('JSON parse error:', e);
134
133
  data = {};
135
134
  }
136
135
  console.log('无障碍router回调成功:', res);
137
136
  const isRunning = data?.data?.isAccessibilityIsRunning || false;
138
137
  resolve(isRunning);
139
138
  };
140
139
  if (isJdAndIosDevice) {
141
140
  callRouterIOS(params);
142
141
  } else if (isJdAndAndroidDevice) {
143
142
  callRouterAndroid(params);
144
143
  }
145
144
  });
146
145
  setPageLanguage();
147
146
  let isRunning;
148
147
  try {
149
148
  isRunning = await getAccessibilityIsRunning();
150
149
  } catch (e) {
151
150
  console.error('getAccessibilityIsRunning() ~~ error:', e);
152
151
  }
153
152
  if (isRunning || autoAccessiblePagesWhitelist.includes(buildType)) {
154
153
  console.log('🚀 ~~ 页面启用无障碍自动支持方案 ~~ buildType:', buildType);
155
154
  setupMainObserver();
156
155
  } else {
157
156
  console.log('🚀 ~~ 页面不启用无障碍自动支持方案 !! buildType:', buildType);
158
157
  }
158
+ import Taro from '@tarojs/taro';
159
159
  'app-activity',
160
160
  'app-rank',
161
161
  'app-seckill',
162
162
  'm-coupon',
163
163
  'scene-buy',
164
164
  'light-details',
165
165
  'member-paid-center',
166
166
  'member-paid-card',
167
167
  'member-paid-bind',
168
168
  'app-introduce',
169
169
  'app-search-result',
170
170
  if (window?.shopGlobalSwitch?.openAccessibilityLanguage) {
171
171
  Taro.nextTick(() => {
172
172
  const htmlRoot = document?.documentElement;
173
173
  htmlRoot && htmlRoot.setAttribute('lang', isLanguageForEn ? 'en' : 'zh-CN');
174
174
  });
175
175
  }
176
176
  const mainConfig = {
177
177
  childList: true,
178
178
  subtree: true,
179
179
  attributes: true,
180
180
  attributeFilter: ['auto-accessible'],
181
181
  };
182
182
  const mainObserver = new MutationObserver(function (mutations) {
183
183
  mutations.forEach(function (mutation) {
184
184
  if (mutation.type === 'childList') {
185
185
  mutation.addedNodes.forEach(function (node) {
186
186
  if (node.nodeType === Node.ELEMENT_NODE) {
187
187
  if (node.hasAttribute && node.getAttribute('auto-accessible') === 'true') {
188
188
  updateAccessibilityLabel(node);
189
189
  }
190
190
  const accessibleElements = node.querySelectorAll
191
191
  ? node.querySelectorAll('[auto-accessible="true"]')
192
192
  : [];
193
193
  accessibleElements.forEach(function (el) {
194
194
  updateAccessibilityLabel(el);
195
195
  });
196
196
  }
197
197
  });
198
198
  }
199
199
  if (mutation.type === 'attributes' && mutation.attributeName === 'auto-accessible') {
200
200
  if (mutation.target.getAttribute('auto-accessible') === 'true') {
201
201
  updateAccessibilityLabel(mutation.target);
202
202
  }
203
203
  }
204
204
  });
205
205
  });
206
206
  mainObserver.observe(document.body, mainConfig);
207
207
  setupGlobalContentObserver();
208
208
  const contentConfig = {
209
209
  characterData: true,
210
210
  childList: true,
211
211
  subtree: true,
212
212
  };
213
213
  const lastUpdateTime = new WeakMap();
214
214
  const THROTTLE_DELAY = 2000;
215
215
 
216
216
  function shouldUpdate(element) {
217
217
  const now = Date.now();
218
218
  const lastTime = lastUpdateTime.get(element);
219
219
  if (!lastTime || now - lastTime >= THROTTLE_DELAY) {
220
220
  lastUpdateTime.set(element, now);
221
221
  return true;
222
222
  }
223
223
  return false;
224
224
  }
225
225
  const globalContentObserver = new MutationObserver(function (mutations) {
226
226
  const affectedElements = new Set();
227
227
  mutations.forEach(function (mutation) {
228
228
  let targetElement = null;
229
229
  if (mutation.type === 'characterData') {
230
230
  targetElement = findClosestAccessibleElement(mutation.target);
231
231
  } else if (mutation.type === 'childList') {
232
232
  targetElement = findClosestAccessibleElement(mutation.target);
233
233
  }
234
234
  if (targetElement && targetElement.getAttribute('auto-accessible') === 'true') {
235
235
  affectedElements.add(targetElement);
236
236
  }
237
237
  });
238
238
  affectedElements.forEach(function (element) {
239
239
  if (shouldUpdate(element)) {
240
240
  updateAccessibilityLabel(element);
241
241
  } else {
242
242
  }
243
243
  });
244
244
  });
245
245
  globalContentObserver.observe(document.body, contentConfig);
246
246
  let current = node;
247
247
  if (current.nodeType === Node.TEXT_NODE) {
248
248
  current = current.parentElement;
249
249
  }
250
250
  while (current && current !== document.body) {
251
251
  if (current.getAttribute && current.getAttribute('auto-accessible') === 'true') {
252
252
  return current;
253
253
  }
254
254
  current = current.parentElement;
255
255
  }
256
256
  return null;
257
257
  if (!element) return;
258
258
  if (element.hasAttribute('aria-label')) {
259
259
  completeA11yAttributes(element);
260
260
  if (!element.getAttribute('data-auto-aria-label')) {
261
261
  return;
262
262
  }
263
263
  }
264
264
  const text = element.innerText;
265
265
  if (text) {
266
266
  const processedText = text.replace(/\r|\n/g, ' ').replace(/¥\s(\d+)(\s(\.\d+))?/, '¥$1$3');
267
267
  element.setAttribute('aria-label', processedText);
268
268
  element.setAttribute('data-auto-aria-label', 'true');
269
269
  completeA11yAttributes(element);
270
270
  }
271
271
  if (!element.hasAttribute('role')) {
272
272
  element.setAttribute('role', 'text');
273
273
  }
274
274
  if (!element.hasAttribute('tabindex')) {
275
275
  element.setAttribute('tabindex', 0);
276
276
  }
277
277
  const routerURL = 'router://JDShopModule/isAccessibilityIsRunning';
278
278
  const callBackName = `nativeGetAccessibilityIsRunning${Date.now()}`;
279
279
  let params: any = {
280
280
  routerURL,
281
281
  routerParam: null,
282
282
  callBackName,
283
283
  };
284
284
  return new Promise((resolve) => {
285
285
  window[callBackName] = (res) => {
286
286
  let data;
287
287
  try {
288
288
  data = typeof res === 'string' ? JSON.parse(res) : res;
289
289
  } catch (e) {
290
290
  console.error('JSON parse error:', e);
291
291
  data = {};
292
292
  }
293
293
  console.log('无障碍router回调成功:', res);
294
294
  const isRunning = data?.data?.isAccessibilityIsRunning || false;
295
295
  resolve(isRunning);
296
296
  };
297
297
  if (isJdAndIosDevice) {
298
298
  callRouterIOS(params);
299
299
  } else if (isJdAndAndroidDevice) {
300
300
  callRouterAndroid(params);
301
301
  } else {
302
302
  resolve(false);
303
303
  }
304
304
  });
305
305
  setPageLanguage();
306
306
  let isRunning;
307
307
  try {
308
308
  isRunning = await getAccessibilityIsRunning();
309
309
  } catch (e) {
310
310
  console.error('getAccessibilityIsRunning() ~~ error:', e);
311
311
  }
312
312
  if (isRunning || autoAccessiblePagesWhitelist.includes(buildType)) {
313
313
  console.log('🚀 ~~ 页面启用无障碍自动支持方案 ~~ buildType:', buildType);
314
314
  setupMainObserver();
315
315
  global.info.sysInfo.autoAccsessible = true;
316
316
  } else {
317
317
  console.log('🚀 ~~ 页面不启用无障碍自动支持方案 !! buildType:', buildType);
318
318
  }