@yr-lang/yr 0.1.0
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/BUGS.md +35 -0
- package/CNAME +1 -0
- package/LICENSE +42 -0
- package/README.md +21 -0
- package/lib/%build.yr +3 -0
- package/lib/%deploy.yr +7 -0
- package/lib/%gh-pages.yr +60 -0
- package/lib/%nvm.yr +18 -0
- package/lib/%serve.yr +7 -0
- package/lib/.yrrc +2 -0
- package/lib/Ciyr/A1.yr +25 -0
- package/lib/Ciyr/B1.yr +11 -0
- package/lib/Ciyr/B2.yr +0 -0
- package/lib/Ciyr/C1.yr +14 -0
- package/lib/Ciyr/C2.yr +5 -0
- package/lib/Ciyr/C2_2.yr +5 -0
- package/lib/Ciyr/a1.yr +23 -0
- package/lib/Ciyr/b1.yr +21 -0
- package/lib/Ciyr/c1.yr +18 -0
- package/lib/Yrci/&app.yr +1 -0
- package/lib/Yrci/&app2.yr +1 -0
- package/lib/Yrci/@m1.yr +7 -0
- package/lib/Yrci/@m2.yr +11 -0
- package/lib/Yrci/A1.yr +8 -0
- package/lib/Yrci/A2.yr +26 -0
- package/lib/Yrci/A3.yr +51 -0
- package/lib/Yrci/B1.yr +8 -0
- package/lib/Yrci/C1.yr +58 -0
- package/lib/Yrci/C1.yrr +14 -0
- package/lib/Yrci/C2.yr +17 -0
- package/lib/Yrci/C3.yr +28 -0
- package/lib/Yrci/C4.yr +4 -0
- package/lib/Yrci/C5.yr +3 -0
- package/lib/Yrci/C6.yr +7 -0
- package/lib/Yrci/C7.yr +3 -0
- package/lib/Yrci/C8.yr +3 -0
- package/lib/Yrci/C9.yr +11 -0
- package/lib/Yrci/Index_.yr +4 -0
- package/lib/Yrci/Login.yr +3 -0
- package/lib/Yrci/M1.yr +7 -0
- package/lib/Yrci/Sp.yr +5 -0
- package/lib/Yrci/T1.yr +4 -0
- package/lib/Yrci/T2.yr +4 -0
- package/lib/Yrci/Ta1.yr +4 -0
- package/lib/Yrci/Ta2.yr +4 -0
- package/lib/Yrci/Tg.yr +5 -0
- package/lib/Yrci/Wr.yr +7 -0
- package/lib/Yrci/Wrapper.yr +14 -0
- package/lib/Yrci/Wrapper1.yr +5 -0
- package/lib/Yrci/Wrapper2.yr +24 -0
- package/lib/Yrci/Wrapper3.yr +5 -0
- package/lib/Yrci/Wrapperext.yr +4 -0
- package/lib/Yrci/Wrt.yr +3 -0
- package/lib/Yrci/Yrwm.yr +32 -0
- package/lib/Yrci/a1.yr +18 -0
- package/lib/Yrci/a2.yr +10 -0
- package/lib/Yrci/app.yr +3 -0
- package/lib/Yrci/b2.yr +10 -0
- package/lib/Yrci/j1.yr +5 -0
- package/lib/Yrci/j2.yr +5 -0
- package/lib/Yrci/j3.yr +3 -0
- package/lib/Yrci/modal.yr +5 -0
- package/lib/bodyblock.yr +13 -0
- package/lib/ci.yr +21 -0
- package/lib/crypto.yr +13 -0
- package/lib/element.yr +358 -0
- package/lib/hidden.yr +9 -0
- package/lib/utils.yr +13 -0
- package/node.js +807 -0
- package/package.json +14 -0
- package/src/common.js +7 -0
- package/yr.js +1308 -0
package/lib/Yrci/Ta2.yr
ADDED
package/lib/Yrci/Wr.yr
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[[ test_tag="''"
|
|
2
|
+
|
|
3
|
+
><
|
|
4
|
+
|
|
5
|
+
_yrci/wrapper .upper-wrapper att={{ oi: boi }}
|
|
6
|
+
_ .inner-wrapper type=""
|
|
7
|
+
_ .inner-inner-wrapper
|
|
8
|
+
_ .inner-wrapper2
|
|
9
|
+
|
|
10
|
+
_yrci/wrapperext .upper-wrapper2
|
|
11
|
+
_ .inner-wrapper-ext
|
|
12
|
+
_ .inner-wrapper-ext2
|
|
13
|
+
|
|
14
|
+
_ .teste4
|
|
15
|
+
|
|
16
|
+
||
|
|
17
|
+
|
|
18
|
+
<div class="upper-wrapper">
|
|
19
|
+
<div class="wrapper">
|
|
20
|
+
<div class="wrapper-container">
|
|
21
|
+
<div class="inner-wrapper"></div>
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
package/lib/Yrci/Wrt.yr
ADDED
package/lib/Yrci/Yrwm.yr
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
!! Yrwm/app
|
|
2
|
+
|
|
3
|
+
><
|
|
4
|
+
|
|
5
|
+
_
|
|
6
|
+
_ .yrwm-grid
|
|
7
|
+
_ .yrwm-container
|
|
8
|
+
_ .dashboard-wrapper.grafou-wrapper
|
|
9
|
+
_grafou/app
|
|
10
|
+
_ .dashboard-wrapper.gitya-wrapper.hidden
|
|
11
|
+
_gitya/app
|
|
12
|
+
_ .dashboard-wrapper.sumdow-wrapper.hidden
|
|
13
|
+
_sumdow/app
|
|
14
|
+
|
|
15
|
+
_ .yrwm-tabs
|
|
16
|
+
_
|
|
17
|
+
_span
|
|
18
|
+
_handles/dashboard .fit att={{ target: '.grafou-wrapper', container: '.yrwm-container', start-active: 1 }}
|
|
19
|
+
Grafou
|
|
20
|
+
_handles/dashboard .fit att={{ target: '.gitya-wrapper', container: '.yrwm-container' }}
|
|
21
|
+
Gitya
|
|
22
|
+
_handles/dashboard .fit att={{ target: '.sumdow-wrapper', container: '.yrwm-container' }}
|
|
23
|
+
Sumdow
|
|
24
|
+
|
|
25
|
+
_span
|
|
26
|
+
_button .dashboard-handle
|
|
27
|
+
_span .bi.bi-plus-lg
|
|
28
|
+
_
|
|
29
|
+
_button .dashboard-handle
|
|
30
|
+
_span .bi.bi-arrow-clockwise
|
|
31
|
+
_button .dashboard-handle
|
|
32
|
+
_span .bi.bi-shop
|
package/lib/Yrci/a1.yr
ADDED
package/lib/Yrci/a2.yr
ADDED
package/lib/Yrci/app.yr
ADDED
package/lib/Yrci/b2.yr
ADDED
package/lib/Yrci/j3.yr
ADDED
package/lib/bodyblock.yr
ADDED
package/lib/ci.yr
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
""
|
|
2
|
+
|
|
3
|
+
## calculateTime()
|
|
4
|
+
|
|
5
|
+
type: closure
|
|
6
|
+
returns: function
|
|
7
|
+
|
|
8
|
+
Upon calling it's return value, gets the time passed, in seconds, since it was
|
|
9
|
+
called, upon calling again. Keeps the start value for new calls to use for many
|
|
10
|
+
calls at the same time.
|
|
11
|
+
|
|
12
|
+
@&
|
|
13
|
+
|
|
14
|
+
function calculateExecutionTime() {
|
|
15
|
+
const start = Date.now();
|
|
16
|
+
|
|
17
|
+
return function() {
|
|
18
|
+
const end = Date.now();
|
|
19
|
+
return (end - start) / 1000;
|
|
20
|
+
};
|
|
21
|
+
}
|
package/lib/crypto.yr
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
@&
|
|
2
|
+
|
|
3
|
+
function generateToken(size=15, startWithNumber=false, complex=false) {
|
|
4
|
+
const chars =
|
|
5
|
+
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
6
|
+
|
|
7
|
+
let token = '';
|
|
8
|
+
for (let i = 0; i < size; i++)
|
|
9
|
+
token += chars[Math.floor(Math.random() * chars.length)];
|
|
10
|
+
|
|
11
|
+
return (!isNaN(parseInt(token[0])) && !startWithNumber)
|
|
12
|
+
? this.generateToken(size, startWithNumber, complex) : token;
|
|
13
|
+
}
|
package/lib/element.yr
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
!! hidden
|
|
2
|
+
!! crypto
|
|
3
|
+
|
|
4
|
+
%%
|
|
5
|
+
|
|
6
|
+
_@setElement(#name, #query, #parent=document) {
|
|
7
|
+
const #name = #parent.querySelector(#query);
|
|
8
|
+
@}
|
|
9
|
+
|
|
10
|
+
_@elementListener(#query, #parent=document, #listener='click') {
|
|
11
|
+
#parent.querySelector(#query).addEventListener(#listener, async (e) => {
|
|
12
|
+
const _target = #parent.querySelector(#query);
|
|
13
|
+
___
|
|
14
|
+
});
|
|
15
|
+
@}
|
|
16
|
+
|
|
17
|
+
_@eqs(#name, #container, #query, #type='') {
|
|
18
|
+
const #name = #container.querySelector(#query);
|
|
19
|
+
@}
|
|
20
|
+
|
|
21
|
+
@>
|
|
22
|
+
|
|
23
|
+
function eventListener(element, action, callback) {
|
|
24
|
+
element.addEventListener(action, (e) => {
|
|
25
|
+
try {
|
|
26
|
+
e.preventDefault();
|
|
27
|
+
} catch(error) {/* pass */}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
e.stopPropagation();
|
|
31
|
+
} catch(error) {/* pass */}
|
|
32
|
+
|
|
33
|
+
callback(e);
|
|
34
|
+
return false;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function createElement(options={}, listener=false) {
|
|
39
|
+
if (!options.parent) options.parent = document.body;
|
|
40
|
+
if (!options.selector) options.selector = 'div';
|
|
41
|
+
|
|
42
|
+
const element = document.createElement(options.selector);
|
|
43
|
+
if (options.id) element.id = options.id;
|
|
44
|
+
if (options.classes) element.className = options.classes;
|
|
45
|
+
|
|
46
|
+
if (options.content || options.content === 0)
|
|
47
|
+
element.innerHTML = options.content;
|
|
48
|
+
|
|
49
|
+
if (options.checked) element.checked = options.checked;
|
|
50
|
+
if (options.selected) element.selected = options.selected;
|
|
51
|
+
|
|
52
|
+
if (!options.attributes) options.attributes = {};
|
|
53
|
+
for (let key of Object.keys(options.attributes)) {
|
|
54
|
+
element.setAttribute(key, options.attributes[key]);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!options.style) options.style = {};
|
|
58
|
+
for (let key of Object.keys(options.style)) {
|
|
59
|
+
element.style[key] = options.style[key];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (listener) eventListener(element,
|
|
63
|
+
(options.selector === 'form') ? 'submit'
|
|
64
|
+
: ((options.selector === 'input' || options.selector === 'select')
|
|
65
|
+
? 'change' : 'click'),
|
|
66
|
+
listener
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
if (options.firstChild) {
|
|
70
|
+
options.parent.insertBefore(element, options.parent.firstChild);
|
|
71
|
+
} else {
|
|
72
|
+
options.parent.appendChild(element);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return element;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function removeElement(id) {
|
|
79
|
+
try {
|
|
80
|
+
document.getElementById(id).remove();
|
|
81
|
+
} catch(error) {/* pass */}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function removeElements__Id(root, wrappers={}) {
|
|
85
|
+
function clean(el) {
|
|
86
|
+
[...el.classList].forEach(cls => {
|
|
87
|
+
if (cls.startsWith('__') && !(cls in wrappers)) {
|
|
88
|
+
el.classList.remove(cls);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// clean root + all descendants
|
|
94
|
+
clean(root);
|
|
95
|
+
root.querySelectorAll('*').forEach(clean);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function copyElement(element, remove=false) {
|
|
99
|
+
const elementData = {
|
|
100
|
+
selector: element.tagName.toLowerCase(),
|
|
101
|
+
classes: element.className,
|
|
102
|
+
content: element.innerHTML,
|
|
103
|
+
attributes: {}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const wrappers = {};
|
|
107
|
+
for (let item of [element, ...element.querySelectorAll('div')])
|
|
108
|
+
if (item._config) wrappers[item._config.id] = item._config;
|
|
109
|
+
|
|
110
|
+
if (element.href) elementData.attributes.href = element.href;
|
|
111
|
+
if (element.src) elementData.attributes.src = element.src;
|
|
112
|
+
if (remove) element.remove();
|
|
113
|
+
|
|
114
|
+
return function (parentElement, data={}, options={ firstChild: false, id: false }) {
|
|
115
|
+
const newElement = createElement({
|
|
116
|
+
...elementData, ...options,
|
|
117
|
+
parent: parentElement
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
removeElements__Id(newElement, wrappers);
|
|
121
|
+
|
|
122
|
+
for (let item in wrappers) {
|
|
123
|
+
const wrapper = newElement.className.includes(item) ?
|
|
124
|
+
newElement : newElement.querySelector(`.${item}`);
|
|
125
|
+
|
|
126
|
+
wrappers[item].id = '_CE_' + generateToken(8);
|
|
127
|
+
|
|
128
|
+
wrapper.classList.remove(item);
|
|
129
|
+
wrapper.classList.add(wrappers[item].id);
|
|
130
|
+
wrapper._config = wrappers[item];
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
window[`__${wrapper._config.category}_${wrapper._config.option}`](wrapper._config);
|
|
134
|
+
} catch(error) { console.log(error); }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
for (let item in data) {
|
|
138
|
+
const auxElement = newElement.querySelector(`.${item}`);
|
|
139
|
+
|
|
140
|
+
if (data[item].content || data[item].content === '')
|
|
141
|
+
auxElement.textContent = data[item].content;
|
|
142
|
+
|
|
143
|
+
if (data[item].id) auxElement.id = data[item].id;
|
|
144
|
+
if (data[item].src) auxElement.src = data[item].src;
|
|
145
|
+
if (data[item].srcdoc) auxElement.srcdoc = data[item].srcdoc;
|
|
146
|
+
if (data[item].href) auxElement.href = data[item].href;
|
|
147
|
+
if (data[item].value) auxElement.value = data[item].value;
|
|
148
|
+
if (data[item].name) auxElement.name = data[item].name;
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
data[item].callback(auxElement, newElement);
|
|
152
|
+
} catch(error) {/* pass */}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return newElement;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function cloneElement(element) {
|
|
160
|
+
const newElement = element.cloneNode(true);
|
|
161
|
+
element.parentNode.replaceChild(newElement, element);
|
|
162
|
+
element.remove();
|
|
163
|
+
return newElement;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// https://www.w3schools.com/howto/howto_js_draggable.asp
|
|
167
|
+
function dragElement(
|
|
168
|
+
element,
|
|
169
|
+
options={ headerSelector: ".draggable-header", clone: false },
|
|
170
|
+
touchmoveCallback=false, touchstartCallback=false, touchendCallback=false
|
|
171
|
+
) {
|
|
172
|
+
let headerElement = element.querySelector(options.headerSelector) || element;
|
|
173
|
+
let isDragging = false, dragTimer;
|
|
174
|
+
let offsetX = 0, offsetY = 0, X = 0, Y = 0;
|
|
175
|
+
let activeEl = element;
|
|
176
|
+
|
|
177
|
+
const createClone = () => {
|
|
178
|
+
const rect = element.getBoundingClientRect();
|
|
179
|
+
const clone = element.cloneNode(true);
|
|
180
|
+
clone.classList.add("drag-clone"); // ✅ mark as clone
|
|
181
|
+
clone.style.position = "fixed";
|
|
182
|
+
clone.style.zIndex = 999;
|
|
183
|
+
clone.style.top = rect.top + "px";
|
|
184
|
+
clone.style.left = rect.left + "px";
|
|
185
|
+
clone.style.width = rect.width + "px";
|
|
186
|
+
clone.style.pointerEvents = "none"; // ✅ ignore pointer events
|
|
187
|
+
document.body.appendChild(clone);
|
|
188
|
+
return clone;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const start = (x, y, e) => {
|
|
192
|
+
X = x; Y = y;
|
|
193
|
+
activeEl = (!options.clone) ? element : createClone();
|
|
194
|
+
|
|
195
|
+
const rect = activeEl.getBoundingClientRect();
|
|
196
|
+
offsetX = x - rect.left;
|
|
197
|
+
offsetY = y - rect.top;
|
|
198
|
+
isDragging = true;
|
|
199
|
+
|
|
200
|
+
activeEl.style.cursor = "grabbing";
|
|
201
|
+
if (touchstartCallback) touchstartCallback(e, offsetX, offsetY, X, Y);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const move = (x, y, e) => {
|
|
205
|
+
if (!isDragging) return;
|
|
206
|
+
X = x; Y = y;
|
|
207
|
+
activeEl.style.left = x - offsetX + "px";
|
|
208
|
+
activeEl.style.top = y - offsetY + "px";
|
|
209
|
+
if (touchmoveCallback) touchmoveCallback(e, offsetX, offsetY, X, Y);
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const stop = (e) => {
|
|
213
|
+
if (options.clone && activeEl !== element)
|
|
214
|
+
activeEl.remove();
|
|
215
|
+
activeEl.style.cursor = "grab";
|
|
216
|
+
isDragging = false;
|
|
217
|
+
if (touchendCallback) touchendCallback(e, offsetX, offsetY, X, Y);
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
// Mouse
|
|
221
|
+
headerElement.addEventListener("mousedown", (e) => {
|
|
222
|
+
start(e.clientX, e.clientY, e);
|
|
223
|
+
document.addEventListener("mousemove", onMouseMove);
|
|
224
|
+
document.addEventListener("mouseup", onMouseUp);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
function onMouseMove(e) {
|
|
228
|
+
move(e.clientX, e.clientY, e);
|
|
229
|
+
}
|
|
230
|
+
function onMouseUp(e) {
|
|
231
|
+
stop(e);
|
|
232
|
+
document.removeEventListener("mousemove", onMouseMove);
|
|
233
|
+
document.removeEventListener("mouseup", onMouseUp);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Touch
|
|
237
|
+
headerElement.addEventListener("touchstart", (e) => {
|
|
238
|
+
dragTimer = setTimeout(() => {
|
|
239
|
+
const touch = e.touches[0];
|
|
240
|
+
start(touch.clientX, touch.clientY, e);
|
|
241
|
+
}, 500);
|
|
242
|
+
}, { passive: false });
|
|
243
|
+
|
|
244
|
+
headerElement.addEventListener("touchmove", (e) => {
|
|
245
|
+
if (!isDragging) return;
|
|
246
|
+
e.preventDefault();
|
|
247
|
+
const touch = e.touches[0];
|
|
248
|
+
move(touch.clientX, touch.clientY, e);
|
|
249
|
+
}, { passive: false });
|
|
250
|
+
|
|
251
|
+
headerElement.addEventListener("touchend", (e) => {
|
|
252
|
+
clearTimeout(dragTimer);
|
|
253
|
+
stop(e);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function setClassOnElements(parent, query, type, classes) {
|
|
258
|
+
for (let item of parent.querySelectorAll(query)) item.classList[type](classes);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function getElementPosition(element, offset=false) {
|
|
262
|
+
const rect = element.getBoundingClientRect();
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
top: rect.top + window.scrollY,
|
|
266
|
+
right: rect.right, bottom: rect.bottom,
|
|
267
|
+
left: rect.left + window.scrollX
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function getElementsWithScroll(parent=document, query='*') {
|
|
272
|
+
// https://stackoverflow.com/a/79303339
|
|
273
|
+
function hasScroller(element) {
|
|
274
|
+
const xOverflowing = element.offsetWidth < element.scrollWidth;
|
|
275
|
+
const yOverflowing = element.offsetHeight < element.scrollHeight;
|
|
276
|
+
|
|
277
|
+
if (!xOverflowing && !yOverflowing) return false;
|
|
278
|
+
|
|
279
|
+
const css = document.defaultView.getComputedStyle(element, null);
|
|
280
|
+
|
|
281
|
+
return (
|
|
282
|
+
(xOverflowing && (css['overflow-x'] == 'scroll' || css['overflow-x'] == 'auto')) ||
|
|
283
|
+
(yOverflowing && (css['overflow-y'] == 'scroll' || css['overflow-y'] == 'auto'))
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return Array.from([...parent.querySelectorAll(query)].filter(hasScroller));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async function waitElement(query, interval=1000, tries=50, i=0) {
|
|
291
|
+
if (document.querySelector(query)) return true;
|
|
292
|
+
if (i >= tries) return false;
|
|
293
|
+
|
|
294
|
+
await new Promise(resolve => setTimeout(resolve, interval));
|
|
295
|
+
return waitElement(query, interval, tries, i+1);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function touchmoveDelay(touchmoveCallback) {
|
|
299
|
+
let runTime = Date.now();
|
|
300
|
+
|
|
301
|
+
return (deltaX, deltaY, direction, scale=false) => {
|
|
302
|
+
let currentTime = Date.now();
|
|
303
|
+
if (currentTime - runTime < 100) return;
|
|
304
|
+
|
|
305
|
+
runTime = currentTime;
|
|
306
|
+
touchmoveCallback(deltaX, deltaY, direction, scale);
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async function pinchElement(element, touchmoveCallback=false) {
|
|
311
|
+
// https://stackoverflow.com/questions/74010960/how-to-implement-pinch-zoom-in-zoom-out-using-javascript
|
|
312
|
+
let start = {}, lastScale;
|
|
313
|
+
|
|
314
|
+
const distance = (event) => {
|
|
315
|
+
return Math.hypot(event.touches[0].pageX - event.touches[1].pageX,
|
|
316
|
+
event.touches[0].pageY - event.touches[1].pageY);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
element.addEventListener('touchstart', (event) => {
|
|
320
|
+
if (event.touches.length === 2) {
|
|
321
|
+
event.preventDefault();
|
|
322
|
+
start.x = (event.touches[0].pageX + event.touches[1].pageX) / 2;
|
|
323
|
+
start.y = (event.touches[0].pageY + event.touches[1].pageY) / 2;
|
|
324
|
+
start.distance = distance(event);
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
element.addEventListener('touchmove', (event) => {
|
|
329
|
+
if (event.touches.length === 2 && touchmoveCallback) {
|
|
330
|
+
event.preventDefault();
|
|
331
|
+
|
|
332
|
+
let scale = event.scale;
|
|
333
|
+
if (!scale) {
|
|
334
|
+
const deltaDistance = distance(event);
|
|
335
|
+
scale = deltaDistance / start.distance;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Calculate how much the fingers have moved on the X and Y axis
|
|
339
|
+
const deltaX = (((event.touches[0].pageX + event.touches[1].pageX) / 2) - start.x) * 2; // x2 for accelerated movement
|
|
340
|
+
const deltaY = (((event.touches[0].pageY + event.touches[1].pageY) / 2) - start.y) * 2; // x2 for accelerated movement
|
|
341
|
+
|
|
342
|
+
touchmoveCallback(deltaX, deltaY, ((scale - lastScale > 0) ? 'Up' : 'Down'), scale);
|
|
343
|
+
lastScale = scale;
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
//element.addEventListener('touchend', (event) => {});
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
async function wheelElement(element, touchmoveCallback=false, useCtrl=false) {
|
|
351
|
+
element.addEventListener('wheel', (event) => {
|
|
352
|
+
if (!touchmoveCallback || (useCtrl && !event.ctrlKey)
|
|
353
|
+
|| Number.isInteger(event.deltaY)) return;
|
|
354
|
+
|
|
355
|
+
event.preventDefault();
|
|
356
|
+
touchmoveCallback(event.deltaX, event.deltaY, ((event.deltaY < 0) ? 'Up' : 'Down'));
|
|
357
|
+
}, { passive: false });
|
|
358
|
+
}
|
package/lib/hidden.yr
ADDED
package/lib/utils.yr
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
@&
|
|
2
|
+
|
|
3
|
+
async function wait(ms) {
|
|
4
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
function capitalize(string) {
|
|
8
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
function uncapitalize(string) {
|
|
12
|
+
return string.charAt(0).toLowerCase() + string.slice(1);
|
|
13
|
+
};
|