@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/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
- document.addEventListener(
89
- 'dblclick',
90
- (ev) => {
91
- ev.preventDefault()
92
- ev.stopPropagation()
93
- ev.stopImmediatePropagation()
94
- },
95
- { capture: true },
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: true })
123
+ document.addEventListener('touchstart', start, { passive: false })
124
124
 
125
125
  teardownDblTap = () => {
126
- document.removeEventListener('touchstart', start, { passive: true })
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
- * @param {Event|{originalEvent?: Event}} ev
23
- * @returns {Event}
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
- }): Event;
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|NodeList|Element[]|string} els
221
+ * @param {...(Element|NodeListOf<Element>|Iterable<Element>|string)} els
222
222
  * @returns {void}
223
223
  */
224
- export function remove(...els: Element | NodeList | Element[] | string): void;
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;
@@ -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;