@conecli/cone-render 0.10.1-shop3.107 → 0.10.1-shop3.109

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 Promise.race([
285
285
  new Promise((resolve) => { setTimeout(() => resolve(false), 1000) }),
286
286
  new Promise((resolve) => {
287
287
  window[callBackName] = (res) => {
288
288
  let data;
289
289
  try {
290
290
  data = typeof res === 'string' ? JSON.parse(res) : res;
291
291
  } catch (e) {
292
292
  console.error('JSON parse error:', e);
293
293
  data = {};
294
294
  }
295
295
  console.log('无障碍router回调成功:', res);
296
296
  const isRunning = data?.data?.isAccessibilityIsRunning || false;
297
297
  resolve(isRunning);
298
298
  };
299
299
  if (isJdAndIosDevice) {
300
300
  callRouterIOS(params);
301
301
  } else if (isJdAndAndroidDevice) {
302
302
  callRouterAndroid(params);
303
303
  } else if (isJdAndHarmonyDevice) {
304
304
  const plugin = 'JdShopPlugin';
305
305
  const action = Message_Type.GET_ACCESSIBILITY_IS_RUNNING;
306
306
  params = {
307
307
  ...params,
308
308
  routerURL: '',
309
309
  routerParam: {
310
310
  type: action,
311
311
  callBackName,
312
312
  },
313
313
  };
314
314
  window.XWebView &&
315
315
  window.XWebView.callNative(
316
316
  plugin,
317
317
  action,
318
318
  JSON.stringify(params),
319
319
  callBackName,
320
320
  `${callBackName}HarmonyOS`,
321
321
  );
322
322
  } else {
323
323
  resolve(false);
324
324
  }
325
325
  })
326
326
  ])
327
327
  setPageLanguage();
328
328
  let isRunning;
329
329
  try {
330
330
  isRunning = await getAccessibilityIsRunning();
331
331
  } catch (e) {
332
332
  console.error('getAccessibilityIsRunning() ~~ error:', e);
333
333
  }
334
334
  if (isRunning || autoAccessiblePagesWhitelist.includes(buildType)) {
335
335
  console.log('🚀 ~~ 页面启用无障碍自动支持方案 ~~ buildType:', buildType);
336
336
  setupMainObserver();
337
337
  } else {
338
338
  console.log('🚀 ~~ 页面不启用无障碍自动支持方案 !! buildType:', buildType);
339
339
  }