@conecli/cone-render 0.10.1-shop3.57 → 0.10.1-shop3.59
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
|
if (window?.shopGlobalSwitch?.openAccessibilityLanguage) {
|
|
8
7
|
Taro.nextTick(() => {
|
|
9
8
|
const htmlRoot = document?.documentElement;
|
|
10
9
|
htmlRoot && htmlRoot.setAttribute('lang', isLanguageForEn ? 'en' : 'zh-CN');
|
|
11
10
|
});
|
|
12
11
|
}
|
|
13
12
|
const mainConfig = {
|
|
14
13
|
childList: true,
|
|
15
14
|
subtree: true,
|
|
16
15
|
attributes: true,
|
|
17
16
|
attributeFilter: ['auto-accessible'],
|
|
18
17
|
};
|
|
19
18
|
const mainObserver = new MutationObserver(function (mutations) {
|
|
20
19
|
mutations.forEach(function (mutation) {
|
|
21
20
|
if (mutation.type === 'childList') {
|
|
22
21
|
mutation.addedNodes.forEach(function (node) {
|
|
23
22
|
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
24
23
|
if (node.hasAttribute && node.getAttribute('auto-accessible') === 'true') {
|
|
25
24
|
updateAccessibilityLabel(node);
|
|
26
25
|
}
|
|
27
26
|
const accessibleElements = node.querySelectorAll
|
|
28
27
|
? node.querySelectorAll('[auto-accessible="true"]')
|
|
29
28
|
: [];
|
|
30
29
|
accessibleElements.forEach(function (el) {
|
|
31
30
|
updateAccessibilityLabel(el);
|
|
32
31
|
});
|
|
33
32
|
}
|
|
34
33
|
});
|
|
35
34
|
}
|
|
36
35
|
if (mutation.type === 'attributes' && mutation.attributeName === 'auto-accessible') {
|
|
37
36
|
if (mutation.target.getAttribute('auto-accessible') === 'true') {
|
|
38
37
|
updateAccessibilityLabel(mutation.target);
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
});
|
|
42
41
|
});
|
|
43
42
|
mainObserver.observe(document.body, mainConfig);
|
|
44
43
|
setupGlobalContentObserver();
|
|
45
44
|
const contentConfig = {
|
|
46
45
|
characterData: true,
|
|
47
46
|
childList: true,
|
|
48
47
|
subtree: true,
|
|
49
48
|
};
|
|
50
49
|
const lastUpdateTime = new WeakMap();
|
|
51
50
|
const THROTTLE_DELAY = 2000;
|
|
52
51
|
|
|
53
52
|
function shouldUpdate(element) {
|
|
54
53
|
const now = Date.now();
|
|
55
54
|
const lastTime = lastUpdateTime.get(element);
|
|
56
55
|
if (!lastTime || now - lastTime >= THROTTLE_DELAY) {
|
|
57
56
|
lastUpdateTime.set(element, now);
|
|
58
57
|
return true;
|
|
59
58
|
}
|
|
60
59
|
return false;
|
|
61
60
|
}
|
|
62
61
|
const globalContentObserver = new MutationObserver(function (mutations) {
|
|
63
62
|
const affectedElements = new Set();
|
|
64
63
|
mutations.forEach(function (mutation) {
|
|
65
64
|
let targetElement = null;
|
|
66
65
|
if (mutation.type === 'characterData') {
|
|
67
66
|
targetElement = findClosestAccessibleElement(mutation.target);
|
|
68
67
|
} else if (mutation.type === 'childList') {
|
|
69
68
|
targetElement = findClosestAccessibleElement(mutation.target);
|
|
70
69
|
}
|
|
71
70
|
if (targetElement && targetElement.getAttribute('auto-accessible') === 'true') {
|
|
72
71
|
affectedElements.add(targetElement);
|
|
73
72
|
}
|
|
74
73
|
});
|
|
75
74
|
affectedElements.forEach(function (element) {
|
|
76
75
|
if (shouldUpdate(element)) {
|
|
77
76
|
updateAccessibilityLabel(element);
|
|
78
77
|
} else {
|
|
79
78
|
}
|
|
80
79
|
});
|
|
81
80
|
});
|
|
82
81
|
globalContentObserver.observe(document.body, contentConfig);
|
|
83
82
|
let current = node;
|
|
84
83
|
if (current.nodeType === Node.TEXT_NODE) {
|
|
85
84
|
current = current.parentElement;
|
|
86
85
|
}
|
|
87
86
|
while (current && current !== document.body) {
|
|
88
87
|
if (current.getAttribute && current.getAttribute('auto-accessible') === 'true') {
|
|
89
88
|
return current;
|
|
90
89
|
}
|
|
91
90
|
current = current.parentElement;
|
|
92
91
|
}
|
|
93
92
|
return null;
|
|
94
93
|
if (!element) return;
|
|
95
94
|
if (element.hasAttribute('aria-label')){
|
|
96
95
|
completeA11yAttributes(element);
|
|
97
96
|
if(!element.getAttribute('data-auto-aria-label')) {
|
|
98
97
|
return;
|
|
99
98
|
}
|
|
100
99
|
}
|
|
101
100
|
const text = element.innerText;
|
|
102
101
|
if (text) {
|
|
103
102
|
const processedText = text.replace(/\r|\n/g, ' ').replace(/¥\s(\d+)(\s(\.\d+))?/, '¥$1$3');
|
|
104
103
|
element.setAttribute('aria-label', processedText);
|
|
105
104
|
element.setAttribute('data-auto-aria-label', 'true');
|
|
106
105
|
completeA11yAttributes(element);
|
|
107
106
|
}
|
|
108
107
|
if (!element.hasAttribute('role')) {
|
|
109
108
|
element.setAttribute('role', 'text');
|
|
110
109
|
}
|
|
111
110
|
if (!element.hasAttribute('tabindex')) {
|
|
112
111
|
element.setAttribute('tabindex', 0);
|
|
113
112
|
}
|
|
114
113
|
console.log('🚀 ~~ 页面启用无障碍自动支持方案 ~~ buildType:', buildType);
|
|
115
114
|
setupMainObserver();
|
|
116
115
|
console.log('🚀 ~~ 页面不启用无障碍自动支持方案 !! buildType:', buildType);
|
|
116
|
+
import Taro from '@tarojs/taro';
|
|
117
117
|
'app-activity',
|
|
118
118
|
'app-rank',
|
|
119
119
|
'app-seckill',
|
|
120
120
|
'm-coupon',
|
|
121
121
|
'scene-buy',
|
|
122
122
|
'light-details',
|
|
123
123
|
if (window?.shopGlobalSwitch?.openAccessibilityLanguage) {
|
|
124
124
|
Taro.nextTick(() => {
|
|
125
125
|
const htmlRoot = document?.documentElement;
|
|
126
126
|
htmlRoot && htmlRoot.setAttribute('lang', isLanguageForEn ? 'en' : 'zh-CN');
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
129
|
const mainConfig = {
|
|
130
130
|
childList: true,
|
|
131
131
|
subtree: true,
|
|
132
132
|
attributes: true,
|
|
133
133
|
attributeFilter: ['auto-accessible'],
|
|
134
134
|
};
|
|
135
135
|
const mainObserver = new MutationObserver(function (mutations) {
|
|
136
136
|
mutations.forEach(function (mutation) {
|
|
137
137
|
if (mutation.type === 'childList') {
|
|
138
138
|
mutation.addedNodes.forEach(function (node) {
|
|
139
139
|
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
140
140
|
if (node.hasAttribute && node.getAttribute('auto-accessible') === 'true') {
|
|
141
141
|
updateAccessibilityLabel(node);
|
|
142
142
|
}
|
|
143
143
|
const accessibleElements = node.querySelectorAll
|
|
144
144
|
? node.querySelectorAll('[auto-accessible="true"]')
|
|
145
145
|
: [];
|
|
146
146
|
accessibleElements.forEach(function (el) {
|
|
147
147
|
updateAccessibilityLabel(el);
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
152
|
if (mutation.type === 'attributes' && mutation.attributeName === 'auto-accessible') {
|
|
153
153
|
if (mutation.target.getAttribute('auto-accessible') === 'true') {
|
|
154
154
|
updateAccessibilityLabel(mutation.target);
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
});
|
|
158
158
|
});
|
|
159
159
|
mainObserver.observe(document.body, mainConfig);
|
|
160
160
|
setupGlobalContentObserver();
|
|
161
161
|
const contentConfig = {
|
|
162
162
|
characterData: true,
|
|
163
163
|
childList: true,
|
|
164
164
|
subtree: true,
|
|
165
165
|
};
|
|
166
166
|
const lastUpdateTime = new WeakMap();
|
|
167
167
|
const THROTTLE_DELAY = 2000;
|
|
168
168
|
|
|
169
169
|
function shouldUpdate(element) {
|
|
170
170
|
const now = Date.now();
|
|
171
171
|
const lastTime = lastUpdateTime.get(element);
|
|
172
172
|
if (!lastTime || now - lastTime >= THROTTLE_DELAY) {
|
|
173
173
|
lastUpdateTime.set(element, now);
|
|
174
174
|
return true;
|
|
175
175
|
}
|
|
176
176
|
return false;
|
|
177
177
|
}
|
|
178
178
|
const globalContentObserver = new MutationObserver(function (mutations) {
|
|
179
179
|
const affectedElements = new Set();
|
|
180
180
|
mutations.forEach(function (mutation) {
|
|
181
181
|
let targetElement = null;
|
|
182
182
|
if (mutation.type === 'characterData') {
|
|
183
183
|
targetElement = findClosestAccessibleElement(mutation.target);
|
|
184
184
|
} else if (mutation.type === 'childList') {
|
|
185
185
|
targetElement = findClosestAccessibleElement(mutation.target);
|
|
186
186
|
}
|
|
187
187
|
if (targetElement && targetElement.getAttribute('auto-accessible') === 'true') {
|
|
188
188
|
affectedElements.add(targetElement);
|
|
189
189
|
}
|
|
190
190
|
});
|
|
191
191
|
affectedElements.forEach(function (element) {
|
|
192
192
|
if (shouldUpdate(element)) {
|
|
193
193
|
updateAccessibilityLabel(element);
|
|
194
194
|
} else {
|
|
195
195
|
}
|
|
196
196
|
});
|
|
197
197
|
});
|
|
198
198
|
globalContentObserver.observe(document.body, contentConfig);
|
|
199
199
|
let current = node;
|
|
200
200
|
if (current.nodeType === Node.TEXT_NODE) {
|
|
201
201
|
current = current.parentElement;
|
|
202
202
|
}
|
|
203
203
|
while (current && current !== document.body) {
|
|
204
204
|
if (current.getAttribute && current.getAttribute('auto-accessible') === 'true') {
|
|
205
205
|
return current;
|
|
206
206
|
}
|
|
207
207
|
current = current.parentElement;
|
|
208
208
|
}
|
|
209
209
|
return null;
|
|
210
210
|
if (!element) return;
|
|
211
211
|
if (element.hasAttribute('aria-label')) {
|
|
212
212
|
completeA11yAttributes(element);
|
|
213
213
|
if (!element.getAttribute('data-auto-aria-label')) {
|
|
214
214
|
return;
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
const text = element.innerText;
|
|
218
218
|
if (text) {
|
|
219
219
|
const processedText = text.replace(/\r|\n/g, ' ').replace(/¥\s(\d+)(\s(\.\d+))?/, '¥$1$3');
|
|
220
220
|
element.setAttribute('aria-label', processedText);
|
|
221
221
|
element.setAttribute('data-auto-aria-label', 'true');
|
|
222
222
|
completeA11yAttributes(element);
|
|
223
223
|
}
|
|
224
224
|
if (!element.hasAttribute('role')) {
|
|
225
225
|
element.setAttribute('role', 'text');
|
|
226
226
|
}
|
|
227
227
|
if (!element.hasAttribute('tabindex')) {
|
|
228
228
|
element.setAttribute('tabindex', 0);
|
|
229
229
|
}
|
|
230
230
|
console.log('🚀 ~~ 页面启用无障碍自动支持方案 ~~ buildType:', buildType);
|
|
231
231
|
setupMainObserver();
|
|
232
232
|
console.log('🚀 ~~ 页面不启用无障碍自动支持方案 !! buildType:', buildType);
|