@conecli/cone-render 0.10.1-shop3.98 → 0.10.1-shop3.99
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.
- package/dist/common/accessibility.h5.ts +1 -1
- package/dist/common/accessibility.ts +1 -0
- package/dist/common/index.h5.ts +1 -1
- package/dist/components/base/CustomScrollView/index.tsx +1 -1
- package/dist/components/base/NetworkDataError/index.tsx +1 -1
- package/dist/utils/connectNativeJsBridge.ts +1 -1
- package/package.json +1 -1
|
@@ -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
|
console.log('🚀 ~~ 页面启用无障碍自动支持方案 ~~ buildType:', buildType);
|
|
121
120
|
setupMainObserver();
|
|
122
121
|
console.log('🚀 ~~ 页面不启用无障碍自动支持方案 !! buildType:', buildType);
|
|
122
|
+
import Taro from '@tarojs/taro';
|
|
123
123
|
'app-activity',
|
|
124
124
|
'app-rank',
|
|
125
125
|
'app-seckill',
|
|
126
126
|
'm-coupon',
|
|
127
127
|
'scene-buy',
|
|
128
128
|
'light-details',
|
|
129
129
|
'member-paid-center',
|
|
130
130
|
'member-paid-card',
|
|
131
131
|
'member-paid-bind',
|
|
132
132
|
'app-introduce',
|
|
133
133
|
'app-search-result',
|
|
134
134
|
if (window?.shopGlobalSwitch?.openAccessibilityLanguage) {
|
|
135
135
|
Taro.nextTick(() => {
|
|
136
136
|
const htmlRoot = document?.documentElement;
|
|
137
137
|
htmlRoot && htmlRoot.setAttribute('lang', isLanguageForEn ? 'en' : 'zh-CN');
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
140
|
const mainConfig = {
|
|
141
141
|
childList: true,
|
|
142
142
|
subtree: true,
|
|
143
143
|
attributes: true,
|
|
144
144
|
attributeFilter: ['auto-accessible'],
|
|
145
145
|
};
|
|
146
146
|
const mainObserver = new MutationObserver(function (mutations) {
|
|
147
147
|
mutations.forEach(function (mutation) {
|
|
148
148
|
if (mutation.type === 'childList') {
|
|
149
149
|
mutation.addedNodes.forEach(function (node) {
|
|
150
150
|
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
151
151
|
if (node.hasAttribute && node.getAttribute('auto-accessible') === 'true') {
|
|
152
152
|
updateAccessibilityLabel(node);
|
|
153
153
|
}
|
|
154
154
|
const accessibleElements = node.querySelectorAll
|
|
155
155
|
? node.querySelectorAll('[auto-accessible="true"]')
|
|
156
156
|
: [];
|
|
157
157
|
accessibleElements.forEach(function (el) {
|
|
158
158
|
updateAccessibilityLabel(el);
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
if (mutation.type === 'attributes' && mutation.attributeName === 'auto-accessible') {
|
|
164
164
|
if (mutation.target.getAttribute('auto-accessible') === 'true') {
|
|
165
165
|
updateAccessibilityLabel(mutation.target);
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
});
|
|
169
169
|
});
|
|
170
170
|
mainObserver.observe(document.body, mainConfig);
|
|
171
171
|
setupGlobalContentObserver();
|
|
172
172
|
const contentConfig = {
|
|
173
173
|
characterData: true,
|
|
174
174
|
childList: true,
|
|
175
175
|
subtree: true,
|
|
176
176
|
};
|
|
177
177
|
const lastUpdateTime = new WeakMap();
|
|
178
178
|
const THROTTLE_DELAY = 2000;
|
|
179
179
|
|
|
180
180
|
function shouldUpdate(element) {
|
|
181
181
|
const now = Date.now();
|
|
182
182
|
const lastTime = lastUpdateTime.get(element);
|
|
183
183
|
if (!lastTime || now - lastTime >= THROTTLE_DELAY) {
|
|
184
184
|
lastUpdateTime.set(element, now);
|
|
185
185
|
return true;
|
|
186
186
|
}
|
|
187
187
|
return false;
|
|
188
188
|
}
|
|
189
189
|
const globalContentObserver = new MutationObserver(function (mutations) {
|
|
190
190
|
const affectedElements = new Set();
|
|
191
191
|
mutations.forEach(function (mutation) {
|
|
192
192
|
let targetElement = null;
|
|
193
193
|
if (mutation.type === 'characterData') {
|
|
194
194
|
targetElement = findClosestAccessibleElement(mutation.target);
|
|
195
195
|
} else if (mutation.type === 'childList') {
|
|
196
196
|
targetElement = findClosestAccessibleElement(mutation.target);
|
|
197
197
|
}
|
|
198
198
|
if (targetElement && targetElement.getAttribute('auto-accessible') === 'true') {
|
|
199
199
|
affectedElements.add(targetElement);
|
|
200
200
|
}
|
|
201
201
|
});
|
|
202
202
|
affectedElements.forEach(function (element) {
|
|
203
203
|
if (shouldUpdate(element)) {
|
|
204
204
|
updateAccessibilityLabel(element);
|
|
205
205
|
} else {
|
|
206
206
|
}
|
|
207
207
|
});
|
|
208
208
|
});
|
|
209
209
|
globalContentObserver.observe(document.body, contentConfig);
|
|
210
210
|
let current = node;
|
|
211
211
|
if (current.nodeType === Node.TEXT_NODE) {
|
|
212
212
|
current = current.parentElement;
|
|
213
213
|
}
|
|
214
214
|
while (current && current !== document.body) {
|
|
215
215
|
if (current.getAttribute && current.getAttribute('auto-accessible') === 'true') {
|
|
216
216
|
return current;
|
|
217
217
|
}
|
|
218
218
|
current = current.parentElement;
|
|
219
219
|
}
|
|
220
220
|
return null;
|
|
221
221
|
if (!element) return;
|
|
222
222
|
if (element.hasAttribute('aria-label')) {
|
|
223
223
|
completeA11yAttributes(element);
|
|
224
224
|
if (!element.getAttribute('data-auto-aria-label')) {
|
|
225
225
|
return;
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
const text = element.innerText;
|
|
229
229
|
if (text) {
|
|
230
230
|
const processedText = text.replace(/\r|\n/g, ' ').replace(/¥\s(\d+)(\s(\.\d+))?/, '¥$1$3');
|
|
231
231
|
element.setAttribute('aria-label', processedText);
|
|
232
232
|
element.setAttribute('data-auto-aria-label', 'true');
|
|
233
233
|
completeA11yAttributes(element);
|
|
234
234
|
}
|
|
235
235
|
if (!element.hasAttribute('role')) {
|
|
236
236
|
element.setAttribute('role', 'text');
|
|
237
237
|
}
|
|
238
238
|
if (!element.hasAttribute('tabindex')) {
|
|
239
239
|
element.setAttribute('tabindex', 0);
|
|
240
240
|
}
|
|
241
241
|
const routerURL = 'router://JDShopModule/isAccessibilityIsRunning';
|
|
242
242
|
const callBackName = `nativeGetAccessibilityIsRunning${Date.now()}`;
|
|
243
243
|
let params: any = {
|
|
244
244
|
routerURL,
|
|
245
245
|
routerParam: null,
|
|
246
246
|
callBackName,
|
|
247
247
|
};
|
|
248
248
|
return new Promise((resolve) => {
|
|
249
249
|
window[callBackName] = (res) => {
|
|
250
250
|
const data = typeof res === 'string' ? JSON.parse(res) : res;
|
|
251
251
|
console.log('无障碍router回调成功:', res);
|
|
252
252
|
const isRunning = data?.data?.isAccessibilityIsRunning || false;
|
|
253
253
|
resolve(isRunning);
|
|
254
254
|
};
|
|
255
255
|
if (isJdAndIosDevice) {
|
|
256
256
|
callRouterIOS(params);
|
|
257
257
|
} else if (isJdAndAndroidDevice) {
|
|
258
258
|
callRouterAndroid(params);
|
|
259
259
|
}
|
|
260
260
|
});
|
|
261
261
|
setPageLanguage();
|
|
262
262
|
let isRunning;
|
|
263
263
|
try {
|
|
264
264
|
isRunning = await getAccessibilityIsRunning();
|
|
265
265
|
} catch (e) {
|
|
266
266
|
console.error('getAccessibilityIsRunning() ~~ error:', e);
|
|
267
267
|
}
|
|
268
268
|
if (isRunning || autoAccessiblePagesWhitelist.includes(buildType)) {
|
|
269
269
|
console.log('🚀 ~~ 页面启用无障碍自动支持方案 ~~ buildType:', buildType);
|
|
270
270
|
setupMainObserver();
|
|
271
271
|
} else {
|
|
272
272
|
console.log('🚀 ~~ 页面不启用无障碍自动支持方案 !! buildType:', buildType);
|
|
273
273
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default () => {};
|