@conecli/cone-render 0.10.1-shop-beta.35 → 0.10.1-shop-beta.36

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
  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
  if (window?.shopGlobalSwitch?.openAccessibilityLanguage) {
134
134
  Taro.nextTick(() => {
135
135
  const htmlRoot = document?.documentElement;
136
136
  htmlRoot && htmlRoot.setAttribute('lang', isLanguageForEn ? 'en' : 'zh-CN');
137
137
  });
138
138
  }
139
139
  const mainConfig = {
140
140
  childList: true,
141
141
  subtree: true,
142
142
  attributes: true,
143
143
  attributeFilter: ['auto-accessible'],
144
144
  };
145
145
  const mainObserver = new MutationObserver(function (mutations) {
146
146
  mutations.forEach(function (mutation) {
147
147
  if (mutation.type === 'childList') {
148
148
  mutation.addedNodes.forEach(function (node) {
149
149
  if (node.nodeType === Node.ELEMENT_NODE) {
150
150
  if (node.hasAttribute && node.getAttribute('auto-accessible') === 'true') {
151
151
  updateAccessibilityLabel(node);
152
152
  }
153
153
  const accessibleElements = node.querySelectorAll
154
154
  ? node.querySelectorAll('[auto-accessible="true"]')
155
155
  : [];
156
156
  accessibleElements.forEach(function (el) {
157
157
  updateAccessibilityLabel(el);
158
158
  });
159
159
  }
160
160
  });
161
161
  }
162
162
  if (mutation.type === 'attributes' && mutation.attributeName === 'auto-accessible') {
163
163
  if (mutation.target.getAttribute('auto-accessible') === 'true') {
164
164
  updateAccessibilityLabel(mutation.target);
165
165
  }
166
166
  }
167
167
  });
168
168
  });
169
169
  mainObserver.observe(document.body, mainConfig);
170
170
  setupGlobalContentObserver();
171
171
  const contentConfig = {
172
172
  characterData: true,
173
173
  childList: true,
174
174
  subtree: true,
175
175
  };
176
176
  const lastUpdateTime = new WeakMap();
177
177
  const THROTTLE_DELAY = 2000;
178
178
 
179
179
  function shouldUpdate(element) {
180
180
  const now = Date.now();
181
181
  const lastTime = lastUpdateTime.get(element);
182
182
  if (!lastTime || now - lastTime >= THROTTLE_DELAY) {
183
183
  lastUpdateTime.set(element, now);
184
184
  return true;
185
185
  }
186
186
  return false;
187
187
  }
188
188
  const globalContentObserver = new MutationObserver(function (mutations) {
189
189
  const affectedElements = new Set();
190
190
  mutations.forEach(function (mutation) {
191
191
  let targetElement = null;
192
192
  if (mutation.type === 'characterData') {
193
193
  targetElement = findClosestAccessibleElement(mutation.target);
194
194
  } else if (mutation.type === 'childList') {
195
195
  targetElement = findClosestAccessibleElement(mutation.target);
196
196
  }
197
197
  if (targetElement && targetElement.getAttribute('auto-accessible') === 'true') {
198
198
  affectedElements.add(targetElement);
199
199
  }
200
200
  });
201
201
  affectedElements.forEach(function (element) {
202
202
  if (shouldUpdate(element)) {
203
203
  updateAccessibilityLabel(element);
204
204
  } else {
205
205
  }
206
206
  });
207
207
  });
208
208
  globalContentObserver.observe(document.body, contentConfig);
209
209
  let current = node;
210
210
  if (current.nodeType === Node.TEXT_NODE) {
211
211
  current = current.parentElement;
212
212
  }
213
213
  while (current && current !== document.body) {
214
214
  if (current.getAttribute && current.getAttribute('auto-accessible') === 'true') {
215
215
  return current;
216
216
  }
217
217
  current = current.parentElement;
218
218
  }
219
219
  return null;
220
220
  if (!element) return;
221
221
  if (element.hasAttribute('aria-label')) {
222
222
  completeA11yAttributes(element);
223
223
  if (!element.getAttribute('data-auto-aria-label')) {
224
224
  return;
225
225
  }
226
226
  }
227
227
  const text = element.innerText;
228
228
  if (text) {
229
229
  const processedText = text.replace(/\r|\n/g, ' ').replace(/¥\s(\d+)(\s(\.\d+))?/, '¥$1$3');
230
230
  element.setAttribute('aria-label', processedText);
231
231
  element.setAttribute('data-auto-aria-label', 'true');
232
232
  completeA11yAttributes(element);
233
233
  }
234
234
  if (!element.hasAttribute('role')) {
235
235
  element.setAttribute('role', 'text');
236
236
  }
237
237
  if (!element.hasAttribute('tabindex')) {
238
238
  element.setAttribute('tabindex', 0);
239
239
  }
240
240
  console.log('🚀 ~~ 页面启用无障碍自动支持方案 ~~ buildType:', buildType);
241
241
  setupMainObserver();
242
242
  console.log('🚀 ~~ 页面不启用无障碍自动支持方案 !! buildType:', buildType);