@webalternatif/js-core 1.6.4 → 1.6.6
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/cjs/Mouse.js +20 -14
- package/dist/cjs/dom.js +4 -2
- package/dist/cjs/onOff.js +16 -15
- package/dist/cjs/traversal.js +1 -1
- package/dist/cjs/utils.js +23 -2
- package/dist/esm/Mouse.js +19 -14
- package/dist/esm/dom.js +4 -2
- package/dist/esm/onOff.js +16 -15
- package/dist/esm/traversal.js +1 -1
- package/dist/esm/utils.js +22 -1
- package/dist/umd/dom.umd.js +1 -1
- package/dist/umd/mouse.umd.js +1 -1
- package/dist/umd/webf.umd.js +1 -1
- package/package.json +1 -1
- package/src/Mouse.js +20 -12
- package/src/dom.js +2 -2
- package/src/onOff.js +15 -15
- package/src/traversal.js +1 -1
- package/src/utils.js +33 -0
- package/types/Mouse.d.ts +14 -3
- package/types/dom.d.ts +2 -2
- package/types/index.d.ts +1 -0
- package/types/traversal.d.ts +1 -1
- package/types/utils.d.ts +1 -0
package/src/onOff.js
CHANGED
|
@@ -49,8 +49,6 @@ const enableLongTap = function () {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
const move = (ev) => {
|
|
52
|
-
// if (!timer) return;
|
|
53
|
-
|
|
54
52
|
const pos = Mouse.getViewportPosition(ev)
|
|
55
53
|
|
|
56
54
|
if (Math.hypot(pos.x - startX, pos.y - startY) > MOVE_TOLERANCE) {
|
|
@@ -84,17 +82,17 @@ const enableDblTap = function () {
|
|
|
84
82
|
let lastTapTime = 0
|
|
85
83
|
let lastPos = null
|
|
86
84
|
|
|
87
|
-
if (isTouchDevice()) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
85
|
+
// if (isTouchDevice()) {
|
|
86
|
+
// document.addEventListener(
|
|
87
|
+
// 'dblclick',
|
|
88
|
+
// (ev) => {
|
|
89
|
+
// ev.preventDefault()
|
|
90
|
+
// ev.stopPropagation()
|
|
91
|
+
// ev.stopImmediatePropagation()
|
|
92
|
+
// },
|
|
93
|
+
// { capture: true },
|
|
94
|
+
// )
|
|
95
|
+
// }
|
|
98
96
|
|
|
99
97
|
const start = (ev) => {
|
|
100
98
|
const target = ev.target
|
|
@@ -106,6 +104,8 @@ const enableDblTap = function () {
|
|
|
106
104
|
const pos = Mouse.getViewportPosition(ev)
|
|
107
105
|
|
|
108
106
|
if (Math.hypot(pos.x - lastPos.x, pos.y - lastPos.y) <= MOVE_TOLERANCE) {
|
|
107
|
+
ev.preventDefault()
|
|
108
|
+
|
|
109
109
|
target.dispatchEvent(
|
|
110
110
|
new CustomEvent('dbltap', {
|
|
111
111
|
bubbles: true,
|
|
@@ -120,10 +120,10 @@ const enableDblTap = function () {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
document.addEventListener('touchstart', start, { passive:
|
|
123
|
+
document.addEventListener('touchstart', start, { passive: false })
|
|
124
124
|
|
|
125
125
|
teardownDblTap = () => {
|
|
126
|
-
document.removeEventListener('touchstart', start
|
|
126
|
+
document.removeEventListener('touchstart', start)
|
|
127
127
|
teardownDblTap = null
|
|
128
128
|
}
|
|
129
129
|
}
|
package/src/traversal.js
CHANGED
|
@@ -12,7 +12,7 @@ import { sizeOf } from './utils.js'
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* @template T
|
|
15
|
-
* @typedef {Array<T> | Set<T> | Map<any, T> | Object<string, T> | string | string[]} Collection
|
|
15
|
+
* @typedef {Array<T> | readonly T[] | Set<T> | Map<any, T> | Object<string, T> | string | string[]} Collection
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
/**
|
package/src/utils.js
CHANGED
|
@@ -240,3 +240,36 @@ export const debounce = function (func, wait, immediate = false, context = null)
|
|
|
240
240
|
}, wait)
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
|
+
|
|
244
|
+
export const getScrollbarWidth = (() => {
|
|
245
|
+
let scrollbarWidth = null
|
|
246
|
+
|
|
247
|
+
return function () {
|
|
248
|
+
if (scrollbarWidth === null) {
|
|
249
|
+
const outer = document.createElement('div')
|
|
250
|
+
|
|
251
|
+
outer.style.visibility = 'hidden'
|
|
252
|
+
outer.style.width = '100px'
|
|
253
|
+
outer.style.msOverflowStyle = 'scrollbar'
|
|
254
|
+
|
|
255
|
+
document.body.appendChild(outer)
|
|
256
|
+
|
|
257
|
+
const widthNoScroll = outer.offsetWidth
|
|
258
|
+
|
|
259
|
+
outer.style.overflow = 'scroll'
|
|
260
|
+
|
|
261
|
+
const inner = document.createElement('div')
|
|
262
|
+
inner.style.width = '100%'
|
|
263
|
+
|
|
264
|
+
outer.appendChild(inner)
|
|
265
|
+
|
|
266
|
+
const widthWithScroll = inner.offsetWidth
|
|
267
|
+
|
|
268
|
+
outer.remove()
|
|
269
|
+
|
|
270
|
+
scrollbarWidth = widthNoScroll - widthWithScroll
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return scrollbarWidth
|
|
274
|
+
}
|
|
275
|
+
})()
|
package/types/Mouse.d.ts
CHANGED
|
@@ -19,10 +19,21 @@ declare class Mouse {
|
|
|
19
19
|
};
|
|
20
20
|
static getElement(ev: any): Element | null;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* Normalize an event
|
|
23
|
+
*
|
|
24
|
+
* @param {Event|{originalEvent?: Event}|{detail?: {originalEvent?: Event}}} ev
|
|
25
|
+
* @returns {{clientX:number, clientY:number, pageX:number, pageY:number}|null}
|
|
24
26
|
*/
|
|
25
27
|
static "__#1@#getEvent"(ev: Event | {
|
|
26
28
|
originalEvent?: Event;
|
|
27
|
-
}
|
|
29
|
+
} | {
|
|
30
|
+
detail?: {
|
|
31
|
+
originalEvent?: Event;
|
|
32
|
+
};
|
|
33
|
+
}): {
|
|
34
|
+
clientX: number;
|
|
35
|
+
clientY: number;
|
|
36
|
+
pageX: number;
|
|
37
|
+
pageY: number;
|
|
38
|
+
} | null;
|
|
28
39
|
}
|
package/types/dom.d.ts
CHANGED
|
@@ -218,10 +218,10 @@ declare namespace dom {
|
|
|
218
218
|
*/
|
|
219
219
|
export function prepend(node: Node, ...children: (Node | string)[]): Node;
|
|
220
220
|
/**
|
|
221
|
-
* @param {Element|
|
|
221
|
+
* @param {...(Element|NodeListOf<Element>|Iterable<Element>|string)} els
|
|
222
222
|
* @returns {void}
|
|
223
223
|
*/
|
|
224
|
-
export function remove(...els: Element |
|
|
224
|
+
export function remove(...els: (Element | NodeListOf<Element> | Iterable<Element> | string)[]): void;
|
|
225
225
|
/**
|
|
226
226
|
* Returns the closest ancestor of an element matching a selector or a specific element.
|
|
227
227
|
*
|
package/types/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ declare const webf: {
|
|
|
19
19
|
strParseFloat: (val: any) => number;
|
|
20
20
|
throttle: (func: Function, wait: number, leading?: boolean, trailing?: boolean, context?: any) => Function;
|
|
21
21
|
debounce: (func: Function, wait: number, immediate?: boolean, context?: any) => Function;
|
|
22
|
+
getScrollbarWidth: () => any;
|
|
22
23
|
round: (val: number, precision?: number) => number;
|
|
23
24
|
floorTo: (val: number, precision: number) => number;
|
|
24
25
|
plancher: (val: number, precision: number) => number;
|
package/types/traversal.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ export function reduce<T, R>(o: Collection<T>, callback: (accumulator: R | T, va
|
|
|
5
5
|
export function extend<T>(...args: (boolean | T)[]): T;
|
|
6
6
|
export function clone<T>(o: T): T;
|
|
7
7
|
export function merge<T>(first: Collection<T>, second?: Collection<T>, ...args: Collection<T>[]): Array<T>;
|
|
8
|
-
export type Collection<T> = Array<T> | Set<T> | Map<any, T> | {
|
|
8
|
+
export type Collection<T> = Array<T> | readonly T[] | Set<T> | Map<any, T> | {
|
|
9
9
|
[x: string]: T;
|
|
10
10
|
} | string | string[];
|
package/types/utils.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export function flatten(o: Object | any[]): any[];
|
|
|
5
5
|
export function strParseFloat(val: any): number;
|
|
6
6
|
export function throttle(func: Function, wait: number, leading?: boolean, trailing?: boolean, context?: any): Function;
|
|
7
7
|
export function debounce(func: Function, wait: number, immediate?: boolean, context?: any): Function;
|
|
8
|
+
export function getScrollbarWidth(): any;
|