@operato/board 0.3.7 → 0.3.14

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.
@@ -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/utils/os.ts DELETED
@@ -1,41 +0,0 @@
1
- var os = 'Unknown OS'
2
-
3
- if (navigator.userAgent.indexOf('Win') != -1) os = 'Windows'
4
- else if (navigator.userAgent.indexOf('Mac') != -1) os = 'Mac'
5
- else if (navigator.userAgent.indexOf('Linux') != -1) os = 'Linux'
6
- else if (navigator.userAgent.indexOf('Android') != -1) os = 'Android'
7
- else if (navigator.userAgent.indexOf('like Mac') != -1) os = 'iOS'
8
-
9
- var mobile = os === 'iOS' || os === 'Android'
10
-
11
- /**
12
- * method to get operating system of running browser
13
- * @returns {string} name of OS : 'Windows | 'Mac' | 'Android' | 'iOS'
14
- */
15
- export function getOS() {
16
- return os
17
- }
18
-
19
- /**
20
- * method to tell if platform of running browser is kind of mobile device
21
- * @returns {boolean}
22
- */
23
- export function isMobileDevice() {
24
- return mobile
25
- }
26
-
27
- /**
28
- * method to tell if operating system of running browser is iOS
29
- * @returns {boolean}
30
- */
31
- export function isIOS() {
32
- return os === 'iOS'
33
- }
34
-
35
- /**
36
- * method to tell if operating system of running browser is MacOS
37
- * @returns {boolean}
38
- */
39
- export function isMacOS() {
40
- return os === 'Mac'
41
- }
@@ -1,290 +0,0 @@
1
- /**
2
- * Starts monitoring swipes on the given element and
3
- * emits `swipe` event when a swipe gesture is performed.
4
- * @param {DOMElement} element Element on which to listen for swipe gestures.
5
- * @param {Object} options Optional: Options.
6
- * @return {Object}
7
- */
8
- export function SwipeListener(element: HTMLElement, options?: any) {
9
- if (!element) return
10
-
11
- // CustomEvent polyfill
12
- if (typeof window !== 'undefined') {
13
- ;(function () {
14
- if (typeof window.CustomEvent === 'function') return false
15
- function CustomEvent(event: string, params: any) {
16
- params = params || { bubbles: false, cancelable: false, detail: undefined }
17
- var evt = document.createEvent('CustomEvent')
18
- evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail)
19
- return evt
20
- }
21
- CustomEvent.prototype = window.Event.prototype
22
- ;(window as any).CustomEvent = CustomEvent
23
- })()
24
- }
25
-
26
- let defaultOpts = {
27
- minHorizontal: 10, // Minimum number of pixels traveled to count as a horizontal swipe.
28
- minVertical: 10, // Minimum number of pixels traveled to count as a vertical swipe.
29
- deltaHorizontal: 3, // Delta for horizontal swipe
30
- deltaVertical: 5, // Delta for vertical swipe
31
- preventScroll: false, // Prevents scrolling when swiping.
32
- lockAxis: true, // Select only one axis to be true instead of multiple.
33
- touch: true, // Listen for touch events
34
- mouse: true // Listen for mouse events
35
- }
36
-
37
- // Set options
38
- if (!options) {
39
- options = {}
40
- }
41
- options = {
42
- ...defaultOpts,
43
- ...options
44
- }
45
-
46
- // Store the touches
47
- let touches: Array<{ x: number; y: number }> = []
48
-
49
- // Not dragging by default.
50
- let dragging = false
51
-
52
- // When mouse-click is started, make dragging true.
53
- const _mousedown = function (e: MouseEvent) {
54
- dragging = true
55
- }
56
-
57
- // When mouse-click is released, make dragging false and signify end by imitating `touchend`.
58
- const _mouseup = function (e: MouseEvent) {
59
- dragging = false
60
- _touchend(e as any)
61
- }
62
-
63
- // When mouse is moved while being clicked, imitate a `touchmove`.
64
- const _mousemove = function (e: MouseEvent) {
65
- if (dragging) {
66
- ;(e as any).changedTouches = [
67
- {
68
- clientX: e.clientX,
69
- clientY: e.clientY
70
- }
71
- ]
72
- _touchmove(e as any)
73
- }
74
- }
75
-
76
- if (options.mouse) {
77
- element.addEventListener('mousedown', _mousedown)
78
- element.addEventListener('mouseup', _mouseup)
79
- element.addEventListener('mousemove', _mousemove)
80
- }
81
-
82
- // When the swipe is completed, calculate the direction.
83
- const _touchend = function (e: TouchEvent) {
84
- if (!touches.length) return
85
-
86
- const touch = typeof TouchEvent === 'function' && e instanceof TouchEvent
87
-
88
- let x = [],
89
- y = []
90
-
91
- let directions = {
92
- top: false,
93
- right: false,
94
- bottom: false,
95
- left: false
96
- }
97
-
98
- for (let i = 0; i < touches.length; i++) {
99
- x.push(touches[i].x)
100
- y.push(touches[i].y)
101
- }
102
-
103
- const xs = x[0],
104
- xe = x[x.length - 1], // Start and end x-coords
105
- ys = y[0],
106
- ye = y[y.length - 1] // Start and end y-coords
107
-
108
- const eventCoords = {
109
- x: [xs, xe],
110
- y: [ys, ye]
111
- }
112
-
113
- if (touches.length > 1) {
114
- const swipeReleaseEventData = {
115
- detail: {
116
- touch,
117
- target: e.target,
118
- ...eventCoords
119
- }
120
- }
121
-
122
- let swipeReleaseEvent = new CustomEvent('swiperelease', swipeReleaseEventData)
123
- element.dispatchEvent(swipeReleaseEvent)
124
- }
125
-
126
- // Determine left or right
127
- let diff = x[0] - x[x.length - 1]
128
- let swipe = 'none'
129
- if (diff > 0) {
130
- swipe = 'left'
131
- } else {
132
- swipe = 'right'
133
- }
134
-
135
- let min = Math.min(...x),
136
- max = Math.max(...x),
137
- _diff
138
-
139
- // If minimum horizontal distance was travelled
140
- if (Math.abs(diff) >= options.minHorizontal) {
141
- switch (swipe) {
142
- case 'left':
143
- _diff = Math.abs(min - x[x.length - 1])
144
- if (_diff <= options.deltaHorizontal) {
145
- directions.left = true
146
- }
147
- break
148
- case 'right':
149
- _diff = Math.abs(max - x[x.length - 1])
150
- if (_diff <= options.deltaHorizontal) {
151
- directions.right = true
152
- }
153
- break
154
- }
155
- }
156
-
157
- // Determine top or bottom
158
- diff = y[0] - y[y.length - 1]
159
- swipe = 'none'
160
- if (diff > 0) {
161
- swipe = 'top'
162
- } else {
163
- swipe = 'bottom'
164
- }
165
-
166
- min = Math.min(...y)
167
- max = Math.max(...y)
168
-
169
- // If minimum vertical distance was travelled
170
- if (Math.abs(diff) >= options.minVertical) {
171
- switch (swipe) {
172
- case 'top':
173
- _diff = Math.abs(min - y[y.length - 1])
174
- if (_diff <= options.deltaVertical) {
175
- directions.top = true
176
- }
177
- break
178
- case 'bottom':
179
- _diff = Math.abs(max - y[y.length - 1])
180
- if (_diff <= options.deltaVertical) {
181
- directions.bottom = true
182
- }
183
- break
184
- }
185
- }
186
-
187
- // Clear touches array.
188
- touches = []
189
-
190
- // If there is a swipe direction, emit an event.
191
- if (directions.top || directions.right || directions.bottom || directions.left) {
192
- /**
193
- * If lockAxis is true, determine which axis to select.
194
- * The axis with the most travel is selected.
195
- * TODO: Factor in for the orientation of the device
196
- * and use it as a weight to determine the travel along an axis.
197
- */
198
- if (options.lockAxis) {
199
- if ((directions.left || directions.right) && Math.abs(xs - xe) > Math.abs(ys - ye)) {
200
- directions.top = directions.bottom = false
201
- } else if ((directions.top || directions.bottom) && Math.abs(xs - xe) < Math.abs(ys - ye)) {
202
- directions.left = directions.right = false
203
- }
204
- }
205
-
206
- const eventData = {
207
- detail: {
208
- directions,
209
- touch,
210
- target: e.target,
211
- ...eventCoords
212
- }
213
- }
214
-
215
- let event = new CustomEvent('swipe', eventData)
216
- element.dispatchEvent(event)
217
- } else {
218
- let cancelEvent = new CustomEvent('swipecancel', {
219
- detail: {
220
- touch,
221
- target: e.target,
222
- ...eventCoords
223
- }
224
- })
225
- element.dispatchEvent(cancelEvent)
226
- }
227
- }
228
-
229
- // When a swipe is performed, store the coords.
230
- const _touchmove = function (e: TouchEvent) {
231
- let touch = e.changedTouches[0]
232
- touches.push({
233
- x: touch.clientX,
234
- y: touch.clientY
235
- })
236
-
237
- // Emit a `swiping` event if there are more than one touch-points.
238
- if (touches.length > 1) {
239
- const xs = touches[0].x, // Start and end x-coords
240
- xe = touches[touches.length - 1].x,
241
- ys = touches[0].y, // Start and end y-coords
242
- ye = touches[touches.length - 1].y,
243
- eventData = {
244
- detail: {
245
- x: [xs, xe],
246
- y: [ys, ye],
247
- touch: typeof TouchEvent === 'function' && e instanceof TouchEvent,
248
- target: e.target
249
- }
250
- }
251
- let event = new CustomEvent('swiping', eventData)
252
-
253
- const shouldPrevent =
254
- options.preventScroll === true || (typeof options.preventScroll === 'function' && options.preventScroll(event))
255
-
256
- if (shouldPrevent) {
257
- e.preventDefault()
258
- }
259
-
260
- element.dispatchEvent(event)
261
- }
262
- }
263
-
264
- // Test via a getter in the options object to see if the passive property is accessed
265
- let passiveOptions: any = false
266
- try {
267
- const testOptions = Object.defineProperty({}, 'passive', {
268
- get: function () {
269
- passiveOptions = { passive: !options.preventScroll }
270
- }
271
- })
272
- window.addEventListener('testPassive', null as any, testOptions)
273
- window.removeEventListener('testPassive', null as any, testOptions)
274
- } catch (e) {}
275
-
276
- if (options.touch) {
277
- element.addEventListener('touchmove', _touchmove, passiveOptions)
278
- element.addEventListener('touchend', _touchend)
279
- }
280
-
281
- return {
282
- off: function () {
283
- element.removeEventListener('touchmove', _touchmove, passiveOptions)
284
- element.removeEventListener('touchend', _touchend)
285
- element.removeEventListener('mousedown', _mousedown)
286
- element.removeEventListener('mouseup', _mouseup)
287
- element.removeEventListener('mousemove', _mousemove)
288
- }
289
- }
290
- }