1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | const componentOnReady = (el, callback) => {
|
16 | if (el.componentOnReady) {
|
17 | el.componentOnReady().then((resolvedEl) => callback(resolvedEl));
|
18 | }
|
19 | else {
|
20 | raf(() => callback(el));
|
21 | }
|
22 | };
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | const inheritAttributes = (el, attributes = []) => {
|
34 | const attributeObject = {};
|
35 | attributes.forEach(attr => {
|
36 | if (el.hasAttribute(attr)) {
|
37 | const value = el.getAttribute(attr);
|
38 | if (value !== null) {
|
39 | attributeObject[attr] = el.getAttribute(attr);
|
40 | }
|
41 | el.removeAttribute(attr);
|
42 | }
|
43 | });
|
44 | return attributeObject;
|
45 | };
|
46 | const addEventListener = (el, eventName, callback, opts) => {
|
47 | if (typeof window !== 'undefined') {
|
48 | const win = window;
|
49 | const config = win && win.Ionic && win.Ionic.config;
|
50 | if (config) {
|
51 | const ael = config.get('_ael');
|
52 | if (ael) {
|
53 | return ael(el, eventName, callback, opts);
|
54 | }
|
55 | else if (config._ael) {
|
56 | return config._ael(el, eventName, callback, opts);
|
57 | }
|
58 | }
|
59 | }
|
60 | return el.addEventListener(eventName, callback, opts);
|
61 | };
|
62 | const removeEventListener = (el, eventName, callback, opts) => {
|
63 | if (typeof window !== 'undefined') {
|
64 | const win = window;
|
65 | const config = win && win.Ionic && win.Ionic.config;
|
66 | if (config) {
|
67 | const rel = config.get('_rel');
|
68 | if (rel) {
|
69 | return rel(el, eventName, callback, opts);
|
70 | }
|
71 | else if (config._rel) {
|
72 | return config._rel(el, eventName, callback, opts);
|
73 | }
|
74 | }
|
75 | }
|
76 | return el.removeEventListener(eventName, callback, opts);
|
77 | };
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | const getElementRoot = (el, fallback = el) => {
|
88 | return el.shadowRoot || fallback;
|
89 | };
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | const raf = (h) => {
|
95 | if (typeof __zone_symbol__requestAnimationFrame === 'function') {
|
96 | return __zone_symbol__requestAnimationFrame(h);
|
97 | }
|
98 | if (typeof requestAnimationFrame === 'function') {
|
99 | return requestAnimationFrame(h);
|
100 | }
|
101 | return setTimeout(h);
|
102 | };
|
103 | const hasShadowDom = (el) => {
|
104 | return !!el.shadowRoot && !!el.attachShadow;
|
105 | };
|
106 | const findItemLabel = (componentEl) => {
|
107 | const itemEl = componentEl.closest('ion-item');
|
108 | if (itemEl) {
|
109 | return itemEl.querySelector('ion-label');
|
110 | }
|
111 | return null;
|
112 | };
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | const getAriaLabel = (componentEl, inputId) => {
|
127 | let labelText;
|
128 |
|
129 |
|
130 | const labelledBy = componentEl.getAttribute('aria-labelledby');
|
131 |
|
132 |
|
133 | const componentId = componentEl.id;
|
134 | let labelId = labelledBy !== null && labelledBy.trim() !== ''
|
135 | ? labelledBy
|
136 | : inputId + '-lbl';
|
137 | let label = labelledBy !== null && labelledBy.trim() !== ''
|
138 | ? document.getElementById(labelledBy)
|
139 | : findItemLabel(componentEl);
|
140 | if (label) {
|
141 | if (labelledBy === null) {
|
142 | label.id = labelId;
|
143 | }
|
144 | labelText = label.textContent;
|
145 | label.setAttribute('aria-hidden', 'true');
|
146 |
|
147 |
|
148 | }
|
149 | else if (componentId.trim() !== '') {
|
150 | label = document.querySelector(`label[for="${componentId}"]`);
|
151 | if (label) {
|
152 | if (label.id !== '') {
|
153 | labelId = label.id;
|
154 | }
|
155 | else {
|
156 | label.id = labelId = `${componentId}-lbl`;
|
157 | }
|
158 | labelText = label.textContent;
|
159 | }
|
160 | }
|
161 | return { label, labelId, labelText };
|
162 | };
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 | const renderHiddenInput = (always, container, name, value, disabled) => {
|
176 | if (always || hasShadowDom(container)) {
|
177 | let input = container.querySelector('input.aux-input');
|
178 | if (!input) {
|
179 | input = container.ownerDocument.createElement('input');
|
180 | input.type = 'hidden';
|
181 | input.classList.add('aux-input');
|
182 | container.appendChild(input);
|
183 | }
|
184 | input.disabled = disabled;
|
185 | input.name = name;
|
186 | input.value = value || '';
|
187 | }
|
188 | };
|
189 | const clamp = (min, n, max) => {
|
190 | return Math.max(min, Math.min(n, max));
|
191 | };
|
192 | const assert = (actual, reason) => {
|
193 | if (!actual) {
|
194 | const message = 'ASSERT: ' + reason;
|
195 | console.error(message);
|
196 | debugger;
|
197 | throw new Error(message);
|
198 | }
|
199 | };
|
200 | const now = (ev) => {
|
201 | return ev.timeStamp || Date.now();
|
202 | };
|
203 | const pointerCoord = (ev) => {
|
204 |
|
205 |
|
206 | if (ev) {
|
207 | const changedTouches = ev.changedTouches;
|
208 | if (changedTouches && changedTouches.length > 0) {
|
209 | const touch = changedTouches[0];
|
210 | return { x: touch.clientX, y: touch.clientY };
|
211 | }
|
212 | if (ev.pageX !== undefined) {
|
213 | return { x: ev.pageX, y: ev.pageY };
|
214 | }
|
215 | }
|
216 | return { x: 0, y: 0 };
|
217 | };
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 | const isEndSide = (side) => {
|
226 | const isRTL = document.dir === 'rtl';
|
227 | switch (side) {
|
228 | case 'start': return isRTL;
|
229 | case 'end': return !isRTL;
|
230 | default:
|
231 | throw new Error(`"${side}" is not a valid value for [side]. Use "start" or "end" instead.`);
|
232 | }
|
233 | };
|
234 | const debounceEvent = (event, wait) => {
|
235 | const original = event._original || event;
|
236 | return {
|
237 | _original: event,
|
238 | emit: debounce(original.emit.bind(original), wait)
|
239 | };
|
240 | };
|
241 | const debounce = (func, wait = 0) => {
|
242 | let timer;
|
243 | return (...args) => {
|
244 | clearTimeout(timer);
|
245 | timer = setTimeout(func, wait, ...args);
|
246 | };
|
247 | };
|
248 |
|
249 | exports.addEventListener = addEventListener;
|
250 | exports.assert = assert;
|
251 | exports.clamp = clamp;
|
252 | exports.componentOnReady = componentOnReady;
|
253 | exports.debounce = debounce;
|
254 | exports.debounceEvent = debounceEvent;
|
255 | exports.findItemLabel = findItemLabel;
|
256 | exports.getAriaLabel = getAriaLabel;
|
257 | exports.getElementRoot = getElementRoot;
|
258 | exports.hasShadowDom = hasShadowDom;
|
259 | exports.inheritAttributes = inheritAttributes;
|
260 | exports.isEndSide = isEndSide;
|
261 | exports.now = now;
|
262 | exports.pointerCoord = pointerCoord;
|
263 | exports.raf = raf;
|
264 | exports.removeEventListener = removeEventListener;
|
265 | exports.renderHiddenInput = renderHiddenInput;
|