@operato/utils 8.0.0-alpha.37 → 8.0.0-beta.1
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/CHANGELOG.md +17 -0
- package/dist/src/mixins/gesture-mixin.d.ts +4 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/.editorconfig +0 -29
- package/.storybook/main.js +0 -3
- package/.storybook/preview.js +0 -52
- package/.storybook/server.mjs +0 -8
- package/src/adjust-list-param.ts +0 -79
- package/src/async-lock.ts +0 -27
- package/src/clipboard.ts +0 -41
- package/src/closest-element.ts +0 -24
- package/src/context-path.ts +0 -42
- package/src/cookie.ts +0 -44
- package/src/decode-html.ts +0 -5
- package/src/detect-overflow.ts +0 -18
- package/src/encode-form-params.ts +0 -24
- package/src/file-drop-helper.ts +0 -62
- package/src/format.ts +0 -123
- package/src/fullscreen.ts +0 -82
- package/src/gesture-helper.ts +0 -147
- package/src/has-overflow.ts +0 -22
- package/src/index.ts +0 -25
- package/src/is-unvalued.ts +0 -10
- package/src/logger.ts +0 -32
- package/src/longpressable.ts +0 -101
- package/src/mixins/gesture-mixin.ts +0 -157
- package/src/mixins/index.ts +0 -2
- package/src/mixins/infinite-scrollable.ts +0 -67
- package/src/number-parser.ts +0 -24
- package/src/os.ts +0 -48
- package/src/parse-jwt.ts +0 -21
- package/src/password-pattern.ts +0 -63
- package/src/reactive-controllers/index.ts +0 -1
- package/src/reactive-controllers/tooltip-reactive-controller.ts +0 -88
- package/src/sleep.ts +0 -10
- package/src/stringify-bignum.ts +0 -35
- package/src/swipe-listener.ts +0 -290
- package/src/timecapsule/index.ts +0 -2
- package/src/timecapsule/snapshot-taker.ts +0 -105
- package/src/timecapsule/timecapsule.ts +0 -139
- package/tsconfig.json +0 -24
- package/web-dev-server.config.mjs +0 -27
- package/web-test-runner.config.mjs +0 -41
package/src/cookie.ts
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Sets a cookie with the given name, value, and expiration days.
|
3
|
-
*
|
4
|
-
* @param {string} cname - The name of the cookie.
|
5
|
-
* @param {string} cvalue - The value to be stored in the cookie.
|
6
|
-
* @param {number} exdays - The number of days until the cookie expires.
|
7
|
-
*/
|
8
|
-
export function setCookie(cname: string, cvalue: string, exdays: number) {
|
9
|
-
var d = new Date()
|
10
|
-
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000)
|
11
|
-
var expires = 'expires=' + d.toUTCString()
|
12
|
-
document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/'
|
13
|
-
}
|
14
|
-
|
15
|
-
/**
|
16
|
-
* Retrieves the value of a cookie with the given name.
|
17
|
-
*
|
18
|
-
* @param {string} cname - The name of the cookie to retrieve.
|
19
|
-
* @returns {string} - The value of the cookie, or an empty string if the cookie is not found.
|
20
|
-
*/
|
21
|
-
export function getCookie(cname: string) {
|
22
|
-
var name = cname + '='
|
23
|
-
var decodedCookie = decodeURIComponent(document.cookie)
|
24
|
-
var ca = decodedCookie.split(';')
|
25
|
-
for (var i = 0; i < ca.length; i++) {
|
26
|
-
var c = ca[i]
|
27
|
-
while (c.charAt(0) == ' ') {
|
28
|
-
c = c.substring(1)
|
29
|
-
}
|
30
|
-
if (c.indexOf(name) == 0) {
|
31
|
-
return c.substring(name.length, c.length)
|
32
|
-
}
|
33
|
-
}
|
34
|
-
return ''
|
35
|
-
}
|
36
|
-
|
37
|
-
/**
|
38
|
-
* Deletes a cookie with the given name.
|
39
|
-
*
|
40
|
-
* @param {string} name - The name of the cookie to delete.
|
41
|
-
*/
|
42
|
-
export function deleteCookie(name: string) {
|
43
|
-
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'
|
44
|
-
}
|
package/src/decode-html.ts
DELETED
package/src/detect-overflow.ts
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Detects if the content of an HTMLElement overflows its boundaries.
|
3
|
-
*
|
4
|
-
* @param {HTMLElement} el - The HTMLElement to check for overflow.
|
5
|
-
* @returns {boolean} - `true` if overflow is detected, `false` otherwise.
|
6
|
-
* @deprecated This function is no longer recommended for use and has been replaced by 'hasOverflow'.
|
7
|
-
*/
|
8
|
-
export function detectOverflow(el: HTMLElement) {
|
9
|
-
var styleOverflow = el.style.overflow
|
10
|
-
|
11
|
-
if (!styleOverflow || styleOverflow === 'visible') el.style.overflow = 'hidden'
|
12
|
-
|
13
|
-
var overflowed = el.clientWidth < el.scrollWidth || el.clientHeight < el.scrollHeight
|
14
|
-
|
15
|
-
el.style.overflow = styleOverflow
|
16
|
-
|
17
|
-
return overflowed
|
18
|
-
}
|
@@ -1,24 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* encode form parameter string from object
|
3
|
-
* @param {Object} obj target object
|
4
|
-
*/
|
5
|
-
export function encodeFormParams(obj: { [key: string]: any }) {
|
6
|
-
return Object.keys(obj)
|
7
|
-
.map(k => `${encodeURIComponent(k)}=${encodeURIComponent(obj[k])}`)
|
8
|
-
.join('&')
|
9
|
-
}
|
10
|
-
|
11
|
-
/**
|
12
|
-
* encode url parameter string from object
|
13
|
-
* replace null value to ''
|
14
|
-
* @param {Object} obj target object
|
15
|
-
*/
|
16
|
-
export function encodeUrlParams(urlParams: { [key: string]: any }) {
|
17
|
-
return Object.keys(urlParams)
|
18
|
-
.filter((key: string) => {
|
19
|
-
// ignore empty
|
20
|
-
return !!urlParams[key]
|
21
|
-
})
|
22
|
-
.map(key => `${key}=${encodeURIComponent(urlParams[key] || '')}`)
|
23
|
-
.join('&')
|
24
|
-
}
|
package/src/file-drop-helper.ts
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* judge callback function for FileDropHelper.set
|
3
|
-
*/
|
4
|
-
type JudgeCallback = () => boolean
|
5
|
-
|
6
|
-
/**
|
7
|
-
* file drop assist class
|
8
|
-
*/
|
9
|
-
export class FileDropHelper {
|
10
|
-
/**
|
11
|
-
* 파일 드롭 영역에서의 file drag&drop과 관련된 이벤트에 대한 처리를 설정한다.
|
12
|
-
* @param dropArea file drag&drop target area
|
13
|
-
* @param [judge] file drag&drop과 관련된 이벤트에 대한 judge callback function
|
14
|
-
*/
|
15
|
-
static set(dropArea: HTMLElement, judge?: JudgeCallback) {
|
16
|
-
var preventDefaults = (e: Event) => {
|
17
|
-
if (!judge || judge()) {
|
18
|
-
e.preventDefault()
|
19
|
-
e.stopPropagation()
|
20
|
-
}
|
21
|
-
}
|
22
|
-
|
23
|
-
var highlight = (e: Event) => {
|
24
|
-
if (!judge || judge()) {
|
25
|
-
dropArea.classList.add('candrop')
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
var unhighlight = (e: Event) => {
|
30
|
-
if (!judge || judge()) {
|
31
|
-
dropArea.classList.remove('candrop')
|
32
|
-
}
|
33
|
-
}
|
34
|
-
|
35
|
-
;['dragenter', 'dragover', 'dragleave', 'drop'].forEach(event => {
|
36
|
-
dropArea.addEventListener(event, preventDefaults, false)
|
37
|
-
})
|
38
|
-
;['dragenter', 'dragover'].forEach(event => {
|
39
|
-
dropArea.addEventListener(event, highlight, false)
|
40
|
-
})
|
41
|
-
;['dragleave', 'drop'].forEach(event => {
|
42
|
-
dropArea.addEventListener(event, unhighlight, false)
|
43
|
-
})
|
44
|
-
|
45
|
-
dropArea.addEventListener(
|
46
|
-
'drop',
|
47
|
-
e => {
|
48
|
-
if (!judge || judge()) {
|
49
|
-
let dt = e.dataTransfer!
|
50
|
-
let files = dt.files
|
51
|
-
|
52
|
-
dropArea.dispatchEvent(
|
53
|
-
new CustomEvent('file-drop', {
|
54
|
-
detail: [...Array.from(files)]
|
55
|
-
})
|
56
|
-
)
|
57
|
-
}
|
58
|
-
},
|
59
|
-
false
|
60
|
-
)
|
61
|
-
}
|
62
|
-
}
|
package/src/format.ts
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Source Code from https://github.com/Mottie/javascript-number-formatter
|
3
|
-
* 소스코드 출처 : https://github.com/Mottie/javascript-number-formatter
|
4
|
-
*/
|
5
|
-
|
6
|
-
/**
|
7
|
-
* Formats a number according to the given mask.
|
8
|
-
*
|
9
|
-
* ```example
|
10
|
-
* var formattedValue = format('+$#,##0.00', 12345.67);
|
11
|
-
* console.log(formattedValue); // Output: +$12,345.67
|
12
|
-
* ```
|
13
|
-
*
|
14
|
-
* @param {any} mask - The formatting mask to apply.
|
15
|
-
* @param {any} value - The value to format.
|
16
|
-
* @returns {string} - The formatted string.
|
17
|
-
*/
|
18
|
-
export function format(mask: string, value: number): string {
|
19
|
-
if (!mask || isNaN(+value)) {
|
20
|
-
return value.toString() // return as it is.
|
21
|
-
}
|
22
|
-
|
23
|
-
let isNegative: boolean,
|
24
|
-
result: string | RegExpMatchArray | null,
|
25
|
-
decimal: string,
|
26
|
-
group: string,
|
27
|
-
posLeadZero: number,
|
28
|
-
posTrailZero: number,
|
29
|
-
posSeparator: number,
|
30
|
-
part: string[],
|
31
|
-
szSep: string[],
|
32
|
-
integer: string,
|
33
|
-
// find prefix/suffix
|
34
|
-
len = mask.length,
|
35
|
-
start = mask.search(/[0-9\-\+#]/),
|
36
|
-
prefix = start > 0 ? mask.substring(0, start) : '',
|
37
|
-
// reverse string: not an ideal method if there are surrogate pairs
|
38
|
-
str = mask.split('').reverse().join(''),
|
39
|
-
end = str.search(/[0-9\-\+#]/),
|
40
|
-
offset = len - end,
|
41
|
-
substr = mask.substring(offset, offset + 1),
|
42
|
-
indx = offset + (substr === '.' || substr === ',' ? 1 : 0),
|
43
|
-
suffix = end > 0 ? mask.substring(indx, len) : '',
|
44
|
-
splittedMask: string[],
|
45
|
-
splittedValue: string[],
|
46
|
-
stringValue: string
|
47
|
-
|
48
|
-
// mask with prefix & suffix removed
|
49
|
-
mask = mask.substring(start, indx)
|
50
|
-
|
51
|
-
// convert any string to number according to formation sign.
|
52
|
-
value = mask.charAt(0) === '-' ? -value : +value
|
53
|
-
isNegative = value < 0 ? ((value = -value), true) : false // process only abs(), and turn on flag.
|
54
|
-
|
55
|
-
// search for separator for grp & decimal, anything not digit, not +/- sign, not #.
|
56
|
-
result = mask.match(/[^\d\-\+#]/g)
|
57
|
-
decimal = '.' // ( result && result[ result.length - 1 ] ) || '.'; // ','는 소수점이 되지 않게 함
|
58
|
-
group = (result && result[1] && result[0]) || ',' // treat the left most symbol as group separator
|
59
|
-
|
60
|
-
// split the decimal for the format string if any.
|
61
|
-
splittedMask = mask.split(decimal)
|
62
|
-
// Fix the decimal first, toFixed will auto fill trailing zero.
|
63
|
-
value = parseFloat(value.toFixed((splittedMask[1] && splittedMask[1].length) || 0))
|
64
|
-
stringValue = +value + '' // convert number to string to trim off *all* trailing decimal zero(es)
|
65
|
-
|
66
|
-
// fill back any trailing zero according to format
|
67
|
-
posTrailZero = (splittedMask[1] && splittedMask[1].lastIndexOf('0')) || 0 // look for last zero in format
|
68
|
-
part = stringValue.split('.')
|
69
|
-
// integer will get !part[1]
|
70
|
-
if (!part[1] || (part[1] && part[1].length <= posTrailZero)) {
|
71
|
-
stringValue = (+value).toFixed(posTrailZero + 1)
|
72
|
-
}
|
73
|
-
szSep = splittedMask[0].split(group) // look for separator
|
74
|
-
splittedMask[0] = szSep.join('') // join back without separator for counting the pos of any leading 0.
|
75
|
-
|
76
|
-
posLeadZero = (splittedMask[0] && splittedMask[0].indexOf('0')) || 0
|
77
|
-
if (posLeadZero > -1) {
|
78
|
-
while (part[0].length < splittedMask[0].length - posLeadZero) {
|
79
|
-
part[0] = '0' + part[0]
|
80
|
-
}
|
81
|
-
} else if (+part[0] === 0) {
|
82
|
-
part[0] = ''
|
83
|
-
}
|
84
|
-
|
85
|
-
splittedValue = stringValue.split('.')
|
86
|
-
splittedValue[0] = part[0]
|
87
|
-
|
88
|
-
// process the first group separator from decimal (.) only, the rest ignore.
|
89
|
-
// get the length of the last slice of split result.
|
90
|
-
posSeparator = (szSep[1] && szSep[szSep.length - 1].length) || 0
|
91
|
-
if (posSeparator) {
|
92
|
-
integer = splittedValue[0]
|
93
|
-
str = ''
|
94
|
-
offset = integer.length % posSeparator
|
95
|
-
len = integer.length
|
96
|
-
for (indx = 0; indx < len; indx++) {
|
97
|
-
str += integer.charAt(indx) // ie6 only support charAt for sz.
|
98
|
-
// -posSeparator so that won't trail separator on full length
|
99
|
-
/* jshint -W018 */
|
100
|
-
if (!((indx - offset + 1) % posSeparator) && indx < len - posSeparator) {
|
101
|
-
str += group
|
102
|
-
}
|
103
|
-
}
|
104
|
-
splittedValue[0] = str
|
105
|
-
}
|
106
|
-
splittedValue[1] = splittedMask[1] && splittedValue[1] ? decimal + splittedValue[1] : ''
|
107
|
-
|
108
|
-
// remove negative sign if result is zero
|
109
|
-
result = splittedValue.join('')
|
110
|
-
if (result === '0' || result === '') {
|
111
|
-
// remove negative sign if result is zero
|
112
|
-
isNegative = false
|
113
|
-
}
|
114
|
-
|
115
|
-
// 앞에 +가 붙는다면 양수일 경우에도 +를 표기해줌
|
116
|
-
let fixedPlusSign: string
|
117
|
-
|
118
|
-
if (splittedMask[0].substring(0, 1) === '+') fixedPlusSign = isNegative ? '-' : '+'
|
119
|
-
else fixedPlusSign = isNegative ? '-' : ''
|
120
|
-
|
121
|
-
// put back any negation, combine integer and fraction, and add back prefix & suffix
|
122
|
-
return prefix + (fixedPlusSign + result) + suffix
|
123
|
-
}
|
package/src/fullscreen.ts
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* 풀스크린 전환 이후와 풀스크린 해제 이후에 호출되는 콜백함수
|
3
|
-
* @callback FullscreenCallback
|
4
|
-
*/
|
5
|
-
export type FullscreenCallback = () => void
|
6
|
-
|
7
|
-
/**
|
8
|
-
* 엘리먼트를 풀스크린으로 표시되도록 한다.
|
9
|
-
* @param {HTMLElement} element 대상 엘리먼트
|
10
|
-
* @param {FullscreenCallback} afterfull 풀스크린이 된 이후에 호출되는 콜백함수
|
11
|
-
* @param {FullscreenCallback} afterfinish 풀스크린이 해제된 이후에 호출되는 콜백함수
|
12
|
-
*/
|
13
|
-
export function fullscreen(element: HTMLElement, afterfull?: FullscreenCallback, afterfinish?: FullscreenCallback) {
|
14
|
-
var org_width = element.style.width
|
15
|
-
var org_height = element.style.height
|
16
|
-
|
17
|
-
function _fullscreen_callback(e: Event) {
|
18
|
-
if (
|
19
|
-
!document.fullscreenElement &&
|
20
|
-
//@ts-ignore
|
21
|
-
!document.mozFullScreen &&
|
22
|
-
//@ts-ignore
|
23
|
-
!document.webkitIsFullScreen &&
|
24
|
-
//@ts-ignore
|
25
|
-
!document.msFullscreenElement
|
26
|
-
) {
|
27
|
-
;['fullscreenchange', 'webkitfullscreenchange', 'MSFullscreenChange'].forEach(event =>
|
28
|
-
document.removeEventListener(event, _fullscreen_callback)
|
29
|
-
)
|
30
|
-
|
31
|
-
element.style.width = org_width
|
32
|
-
element.style.height = org_height
|
33
|
-
|
34
|
-
afterfinish && afterfinish()
|
35
|
-
} else {
|
36
|
-
element.style.width = '100%'
|
37
|
-
element.style.height = '100%'
|
38
|
-
|
39
|
-
afterfull && afterfull()
|
40
|
-
}
|
41
|
-
}
|
42
|
-
|
43
|
-
;['fullscreenchange', 'webkitfullscreenchange', 'MSFullscreenChange'].forEach(event =>
|
44
|
-
document.addEventListener(event, _fullscreen_callback)
|
45
|
-
)
|
46
|
-
|
47
|
-
if (element.requestFullscreen) element.requestFullscreen()
|
48
|
-
//@ts-ignore
|
49
|
-
else if (element.webkitRequestFullScreen) element.webkitRequestFullScreen()
|
50
|
-
//@ts-ignore
|
51
|
-
else if (element.mozRequestFullScreen) element.mozRequestFullScreen()
|
52
|
-
//@ts-ignore
|
53
|
-
else if (element.msRequestFullscreen) element.msRequestFullscreen()
|
54
|
-
}
|
55
|
-
|
56
|
-
export function exitfullscreen() {
|
57
|
-
if (document.exitFullscreen) document.exitFullscreen()
|
58
|
-
//@ts-ignore
|
59
|
-
else if (document.mozCancelFullScreen) document.mozCancelFullScreen()
|
60
|
-
//@ts-ignore
|
61
|
-
else if (document.webkitCancelFullScreen) document.webkitCancelFullScreen()
|
62
|
-
//@ts-ignore
|
63
|
-
else if (document.msExitFullscreen) document.msExitFullscreen()
|
64
|
-
}
|
65
|
-
|
66
|
-
export function togglefullscreen(
|
67
|
-
element: HTMLElement,
|
68
|
-
afterfull?: FullscreenCallback,
|
69
|
-
afterfinish?: FullscreenCallback
|
70
|
-
) {
|
71
|
-
if (
|
72
|
-
!document.fullscreenElement &&
|
73
|
-
//@ts-ignore
|
74
|
-
!document.mozFullScreen &&
|
75
|
-
//@ts-ignore
|
76
|
-
!document.webkitIsFullScreen &&
|
77
|
-
//@ts-ignore
|
78
|
-
!document.msFullscreenElement
|
79
|
-
)
|
80
|
-
fullscreen(element, afterfull, afterfinish)
|
81
|
-
else exitfullscreen()
|
82
|
-
}
|
package/src/gesture-helper.ts
DELETED
@@ -1,147 +0,0 @@
|
|
1
|
-
export type GestureEventPinch = CustomEvent<{ scale: number; centerX: number; centerY: number }>
|
2
|
-
export type GestureEventDrag = CustomEvent<{
|
3
|
-
deltaX: number
|
4
|
-
deltaY: number
|
5
|
-
clientX: number
|
6
|
-
clientY: number
|
7
|
-
end: boolean
|
8
|
-
}>
|
9
|
-
export type GestureEventDoubleTap = CustomEvent<{ x: number; y: number }>
|
10
|
-
|
11
|
-
export class GestureHelper {
|
12
|
-
private __pointers = new Map<number, { x: number; y: number }>()
|
13
|
-
private __lastTapTime = 0
|
14
|
-
private __lastPinchDistance = 0
|
15
|
-
private __dragStart: { x: number; y: number } | null = null
|
16
|
-
private element: Element
|
17
|
-
|
18
|
-
constructor(element: Element) {
|
19
|
-
this.element = element
|
20
|
-
this.init()
|
21
|
-
}
|
22
|
-
|
23
|
-
private init() {
|
24
|
-
this.element.addEventListener('pointerdown', this.handlePointerDown as EventListener)
|
25
|
-
}
|
26
|
-
|
27
|
-
dispose() {
|
28
|
-
this.element.removeEventListener('pointerdown', this.handlePointerDown as EventListener)
|
29
|
-
this.removeGlobalListeners()
|
30
|
-
}
|
31
|
-
|
32
|
-
private handlePointerDown = (e: PointerEvent) => {
|
33
|
-
e.preventDefault()
|
34
|
-
const point = { x: e.clientX, y: e.clientY }
|
35
|
-
this.__pointers.set(e.pointerId, point)
|
36
|
-
|
37
|
-
this.addGlobalListeners()
|
38
|
-
}
|
39
|
-
|
40
|
-
private handlePointerMove = (e: PointerEvent) => {
|
41
|
-
e.preventDefault()
|
42
|
-
const point = { x: e.clientX, y: e.clientY }
|
43
|
-
this.__pointers.set(e.pointerId, point)
|
44
|
-
|
45
|
-
if (this.__pointers.size === 2) {
|
46
|
-
this.handlePinch()
|
47
|
-
} else if (this.__pointers.size === 1) {
|
48
|
-
this.handleDrag(point, false)
|
49
|
-
}
|
50
|
-
}
|
51
|
-
|
52
|
-
private handlePointerUp = (e: PointerEvent) => {
|
53
|
-
const point = { x: e.clientX, y: e.clientY }
|
54
|
-
this.__pointers.delete(e.pointerId)
|
55
|
-
|
56
|
-
if (this.__dragStart) {
|
57
|
-
this.handleDrag(point, true)
|
58
|
-
}
|
59
|
-
|
60
|
-
if (this.__pointers.size === 0) {
|
61
|
-
this.removeGlobalListeners()
|
62
|
-
this.__dragStart = null
|
63
|
-
this.__lastPinchDistance = 0
|
64
|
-
this.handleTap(point)
|
65
|
-
}
|
66
|
-
}
|
67
|
-
|
68
|
-
private handlePinch() {
|
69
|
-
const pointers = Array.from(this.__pointers.values()) as { x: number; y: number }[]
|
70
|
-
const currentDistance = this.getDistance(pointers[0], pointers[1])
|
71
|
-
|
72
|
-
if (this.__lastPinchDistance) {
|
73
|
-
const scale = currentDistance / this.__lastPinchDistance
|
74
|
-
const center = {
|
75
|
-
x: (pointers[0].x + pointers[1].x) / 2,
|
76
|
-
y: (pointers[0].y + pointers[1].y) / 2
|
77
|
-
}
|
78
|
-
|
79
|
-
this.element.dispatchEvent(
|
80
|
-
new CustomEvent('pinch', {
|
81
|
-
detail: { scale, centerX: center.x, centerY: center.y }
|
82
|
-
})
|
83
|
-
)
|
84
|
-
}
|
85
|
-
|
86
|
-
this.__lastPinchDistance = currentDistance
|
87
|
-
}
|
88
|
-
|
89
|
-
private handleDrag(point: { x: number; y: number }, end: boolean) {
|
90
|
-
if (this.__dragStart) {
|
91
|
-
const deltaX = point.x - this.__dragStart.x
|
92
|
-
const deltaY = point.y - this.__dragStart.y
|
93
|
-
|
94
|
-
this.element.dispatchEvent(
|
95
|
-
new CustomEvent('drag', {
|
96
|
-
detail: { deltaX, deltaY, clientX: point.x, clientY: point.y, end }
|
97
|
-
})
|
98
|
-
)
|
99
|
-
|
100
|
-
if (end) {
|
101
|
-
this.__dragStart = null
|
102
|
-
} else {
|
103
|
-
this.__dragStart = point
|
104
|
-
}
|
105
|
-
} else if (!end && this.__pointers.size === 1) {
|
106
|
-
/* dragging을 시작하려면, pointer 개수가 1개인 것을 (지연)확인해야한다. */
|
107
|
-
setTimeout(() => {
|
108
|
-
if (this.__pointers.size === 1 && !this.__dragStart) {
|
109
|
-
this.__dragStart = point
|
110
|
-
}
|
111
|
-
}, 30)
|
112
|
-
}
|
113
|
-
}
|
114
|
-
|
115
|
-
private handleTap(point: { x: number; y: number }) {
|
116
|
-
const currentTime = performance.now()
|
117
|
-
const timeSinceLastTap = currentTime - this.__lastTapTime
|
118
|
-
|
119
|
-
if (timeSinceLastTap < 300) {
|
120
|
-
this.element.dispatchEvent(
|
121
|
-
new CustomEvent('doubletap', {
|
122
|
-
detail: { x: point.x, y: point.y }
|
123
|
-
})
|
124
|
-
)
|
125
|
-
}
|
126
|
-
|
127
|
-
this.__lastTapTime = currentTime
|
128
|
-
}
|
129
|
-
|
130
|
-
private getDistance(p1: { x: number; y: number }, p2: { x: number; y: number }): number {
|
131
|
-
const dx = p1.x - p2.x
|
132
|
-
const dy = p1.y - p2.y
|
133
|
-
return Math.sqrt(dx * dx + dy * dy)
|
134
|
-
}
|
135
|
-
|
136
|
-
private addGlobalListeners() {
|
137
|
-
document.addEventListener('pointermove', this.handlePointerMove as EventListener)
|
138
|
-
document.addEventListener('pointerup', this.handlePointerUp as EventListener)
|
139
|
-
document.addEventListener('pointercancel', this.handlePointerUp as EventListener)
|
140
|
-
}
|
141
|
-
|
142
|
-
private removeGlobalListeners() {
|
143
|
-
document.removeEventListener('pointermove', this.handlePointerMove as EventListener)
|
144
|
-
document.removeEventListener('pointerup', this.handlePointerUp as EventListener)
|
145
|
-
document.removeEventListener('pointercancel', this.handlePointerUp as EventListener)
|
146
|
-
}
|
147
|
-
}
|
package/src/has-overflow.ts
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Detects if the content of an HTMLElement overflows its boundaries.
|
3
|
-
*
|
4
|
-
* @param {HTMLElement} el - The HTMLElement to check for overflow.
|
5
|
-
* @returns {boolean} - `true` if overflow is detected, `false` otherwise.
|
6
|
-
*/
|
7
|
-
export function hasOverflow(el: HTMLElement): boolean {
|
8
|
-
const computedStyle = getComputedStyle(el)
|
9
|
-
const originalOverflow = computedStyle.overflow
|
10
|
-
|
11
|
-
if (originalOverflow === 'visible') {
|
12
|
-
el.style.overflow = 'hidden'
|
13
|
-
}
|
14
|
-
|
15
|
-
const isOverflowing = el.clientWidth < el.scrollWidth || el.clientHeight < el.scrollHeight
|
16
|
-
|
17
|
-
if (originalOverflow === 'visible') {
|
18
|
-
el.style.overflow = ''
|
19
|
-
}
|
20
|
-
|
21
|
-
return isOverflowing
|
22
|
-
}
|
package/src/index.ts
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
export * from './sleep.js'
|
2
|
-
export * from './async-lock.js'
|
3
|
-
export * from './file-drop-helper.js'
|
4
|
-
export * from './context-path.js'
|
5
|
-
export * from './os.js'
|
6
|
-
export * from './swipe-listener.js'
|
7
|
-
export * from './fullscreen.js'
|
8
|
-
export * from './parse-jwt.js'
|
9
|
-
export * from './password-pattern.js'
|
10
|
-
export * from './closest-element.js'
|
11
|
-
export * from './detect-overflow.js' /* deprecated by 'has-overflow' */
|
12
|
-
export * from './has-overflow.js'
|
13
|
-
export * from './timecapsule/index.js'
|
14
|
-
export * from './clipboard.js'
|
15
|
-
export * from './format.js'
|
16
|
-
export * from './adjust-list-param.js'
|
17
|
-
export * from './is-unvalued.js'
|
18
|
-
export * from './stringify-bignum.js'
|
19
|
-
export * from './encode-form-params.js'
|
20
|
-
export * from './cookie.js'
|
21
|
-
export * from './number-parser.js'
|
22
|
-
export * from './longpressable.js'
|
23
|
-
export * from './decode-html.js'
|
24
|
-
|
25
|
-
export * from './reactive-controllers'
|
package/src/is-unvalued.ts
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* It judges whether it is false except 0, false. Returns true in case of undefined, null, NaN, '', {}, [].
|
3
|
-
*
|
4
|
-
* @param value
|
5
|
-
* @returns boolean
|
6
|
-
*/
|
7
|
-
export function isUnvalued(value: any) {
|
8
|
-
/* value == null same as (value === undefined || value === null) */
|
9
|
-
return value == null || value !== 0 || value !== false || value.length === 0 || Object.keys(value).length === 0
|
10
|
-
}
|
package/src/logger.ts
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
const ERROR = '[ERROR]'
|
2
|
-
const WARN = '[WARN]'
|
3
|
-
const DEBUG = '[DEBUG]'
|
4
|
-
|
5
|
-
/**
|
6
|
-
* Logs an error message with optional stack trace.
|
7
|
-
*
|
8
|
-
* @param {...any} args - The error message and optional additional data.
|
9
|
-
*/
|
10
|
-
export var error = (...args: any[]) => {
|
11
|
-
var trace = [] as string[]
|
12
|
-
args.forEach(arg => arg && arg.stack && trace.push(arg.stack))
|
13
|
-
console.error(ERROR, ...args, trace.join(' '))
|
14
|
-
}
|
15
|
-
|
16
|
-
/**
|
17
|
-
* Logs a warning message with optional stack trace.
|
18
|
-
*
|
19
|
-
* @param {...any} args - The warning message and optional additional data.
|
20
|
-
*/
|
21
|
-
export var warn = (...args: any[]) => {
|
22
|
-
var trace = [] as string[]
|
23
|
-
args.forEach(arg => arg && arg.stack && trace.push(arg.stack))
|
24
|
-
console.warn(WARN, ...args, trace.join(' '))
|
25
|
-
}
|
26
|
-
|
27
|
-
/**
|
28
|
-
* Logs a debug message.
|
29
|
-
*
|
30
|
-
* @param {...any} args - The debug message and optional additional data.
|
31
|
-
*/
|
32
|
-
export var debug = (...args: any[]) => console.log(DEBUG, ...args)
|