@knowark/componarkjs 1.13.3 → 1.14.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/lib/base/component/component.js +17 -1
- package/lib/base/component/component.test.js +475 -389
- package/lib/base/utils/define.js +28 -6
- package/lib/base/utils/define.test.js +129 -42
- package/lib/base/utils/format.test.js +16 -16
- package/lib/base/utils/helpers.js +11 -4
- package/lib/base/utils/helpers.test.js +134 -115
- package/lib/base/utils/slots.test.js +38 -38
- package/lib/base/utils/uuid.test.js +13 -13
- package/lib/components/audio/components/audio.js +22 -3
- package/lib/components/audio/components/audio.test.js +120 -90
- package/lib/components/camera/components/camera.js +8 -3
- package/lib/components/camera/components/camera.test.js +96 -91
- package/lib/components/capture/components/capture.js +33 -5
- package/lib/components/capture/components/capture.test.js +165 -97
- package/lib/components/droparea/components/droparea-preview.js +66 -15
- package/lib/components/droparea/components/droparea-preview.test.js +262 -78
- package/lib/components/droparea/components/droparea.js +47 -8
- package/lib/components/droparea/components/droparea.test.js +309 -298
- package/lib/components/emit/components/emit.js +24 -4
- package/lib/components/emit/components/emit.test.js +192 -134
- package/lib/components/index.js +1 -1
- package/lib/components/list/components/{list.item.js → item.js} +1 -1
- package/lib/components/list/components/item.test.js +70 -69
- package/lib/components/list/components/list.js +35 -5
- package/lib/components/list/components/list.test.js +358 -227
- package/lib/components/list/index.js +1 -1
- package/lib/components/paginator/components/paginator.js +3 -2
- package/lib/components/paginator/components/paginator.test.js +146 -143
- package/lib/components/spinner/components/spinner.js +1 -1
- package/lib/components/spinner/components/spinner.test.js +36 -41
- package/lib/components/splitview/components/splitview.detail.js +1 -1
- package/lib/components/splitview/components/splitview.detail.test.js +78 -74
- package/lib/components/splitview/components/splitview.js +40 -10
- package/lib/components/splitview/components/splitview.master.js +29 -3
- package/lib/components/splitview/components/splitview.master.test.js +52 -52
- package/lib/components/splitview/components/splitview.test.js +136 -32
- package/lib/components/translate/components/translate.js +32 -10
- package/lib/components/translate/components/translate.test.js +492 -133
- package/package.json +7 -27
- package/scripts/node-test-setup.js +94 -0
- package/showcase/components/index.html +1 -1
- package/{jsconfig.json → tsconfig.json} +6 -4
- package/types/base/component/component.d.ts +48 -0
- package/types/base/component/component.d.ts.map +1 -0
- package/types/base/component/component.test.d.ts +2 -0
- package/types/base/component/component.test.d.ts.map +1 -0
- package/types/base/component/index.d.ts +8 -0
- package/types/base/component/index.d.ts.map +1 -0
- package/types/base/index.d.ts +2 -0
- package/types/base/index.d.ts.map +1 -0
- package/types/base/styles/index.d.ts +3 -0
- package/types/base/styles/index.d.ts.map +1 -0
- package/types/base/styles/styles.d.ts +3 -0
- package/types/base/styles/styles.d.ts.map +1 -0
- package/types/base/utils/define.d.ts +5 -0
- package/types/base/utils/define.d.ts.map +1 -0
- package/types/base/utils/define.test.d.ts +2 -0
- package/types/base/utils/define.test.d.ts.map +1 -0
- package/types/base/utils/format.d.ts +13 -0
- package/types/base/utils/format.d.ts.map +1 -0
- package/types/base/utils/format.test.d.ts +2 -0
- package/types/base/utils/format.test.d.ts.map +1 -0
- package/types/base/utils/helpers.d.ts +11 -0
- package/types/base/utils/helpers.d.ts.map +1 -0
- package/types/base/utils/helpers.test.d.ts +2 -0
- package/types/base/utils/helpers.test.d.ts.map +1 -0
- package/types/base/utils/index.d.ts +6 -0
- package/types/base/utils/index.d.ts.map +1 -0
- package/types/base/utils/slots.d.ts +15 -0
- package/types/base/utils/slots.d.ts.map +1 -0
- package/types/base/utils/slots.test.d.ts +2 -0
- package/types/base/utils/slots.test.d.ts.map +1 -0
- package/types/base/utils/uuid.d.ts +3 -0
- package/types/base/utils/uuid.d.ts.map +1 -0
- package/types/base/utils/uuid.test.d.ts +2 -0
- package/types/base/utils/uuid.test.d.ts.map +1 -0
- package/types/components/audio/components/audio.d.ts +18 -0
- package/types/components/audio/components/audio.d.ts.map +1 -0
- package/types/components/audio/components/audio.test.d.ts +2 -0
- package/types/components/audio/components/audio.test.d.ts.map +1 -0
- package/types/components/audio/index.d.ts +2 -0
- package/types/components/audio/index.d.ts.map +1 -0
- package/types/components/audio/styles/ark.css.d.ts +3 -0
- package/types/components/audio/styles/ark.css.d.ts.map +1 -0
- package/types/components/audio/styles/index.d.ts +3 -0
- package/types/components/audio/styles/index.d.ts.map +1 -0
- package/types/components/camera/components/camera.d.ts +18 -0
- package/types/components/camera/components/camera.d.ts.map +1 -0
- package/types/components/camera/components/camera.test.d.ts +2 -0
- package/types/components/camera/components/camera.test.d.ts.map +1 -0
- package/types/components/camera/index.d.ts +2 -0
- package/types/components/camera/index.d.ts.map +1 -0
- package/types/components/camera/styles/ark.css.d.ts +3 -0
- package/types/components/camera/styles/ark.css.d.ts.map +1 -0
- package/types/components/camera/styles/index.d.ts +3 -0
- package/types/components/camera/styles/index.d.ts.map +1 -0
- package/types/components/capture/components/capture.d.ts +10 -0
- package/types/components/capture/components/capture.d.ts.map +1 -0
- package/types/components/capture/components/capture.test.d.ts +2 -0
- package/types/components/capture/components/capture.test.d.ts.map +1 -0
- package/types/components/capture/index.d.ts +2 -0
- package/types/components/capture/index.d.ts.map +1 -0
- package/types/components/droparea/components/droparea-preview.d.ts +21 -0
- package/types/components/droparea/components/droparea-preview.d.ts.map +1 -0
- package/types/components/droparea/components/droparea-preview.test.d.ts +2 -0
- package/types/components/droparea/components/droparea-preview.test.d.ts.map +1 -0
- package/types/components/droparea/components/droparea.d.ts +32 -0
- package/types/components/droparea/components/droparea.d.ts.map +1 -0
- package/types/components/droparea/components/droparea.test.d.ts +2 -0
- package/types/components/droparea/components/droparea.test.d.ts.map +1 -0
- package/types/components/droparea/index.d.ts +2 -0
- package/types/components/droparea/index.d.ts.map +1 -0
- package/types/components/droparea/styles/ark.css.d.ts +3 -0
- package/types/components/droparea/styles/ark.css.d.ts.map +1 -0
- package/types/components/droparea/styles/index.d.ts +3 -0
- package/types/components/droparea/styles/index.d.ts.map +1 -0
- package/types/components/emit/components/emit.d.ts +10 -0
- package/types/components/emit/components/emit.d.ts.map +1 -0
- package/types/components/emit/components/emit.test.d.ts +2 -0
- package/types/components/emit/components/emit.test.d.ts.map +1 -0
- package/types/components/emit/index.d.ts +2 -0
- package/types/components/emit/index.d.ts.map +1 -0
- package/types/components/index.d.ts +10 -0
- package/types/components/index.d.ts.map +1 -0
- package/types/components/list/components/item.d.ts +8 -0
- package/types/components/list/components/item.d.ts.map +1 -0
- package/types/components/list/components/item.test.d.ts +2 -0
- package/types/components/list/components/item.test.d.ts.map +1 -0
- package/types/components/list/components/list.d.ts +13 -0
- package/types/components/list/components/list.d.ts.map +1 -0
- package/types/components/list/components/list.test.d.ts +2 -0
- package/types/components/list/components/list.test.d.ts.map +1 -0
- package/types/components/list/index.d.ts +3 -0
- package/types/components/list/index.d.ts.map +1 -0
- package/types/components/paginator/components/paginator.d.ts +32 -0
- package/types/components/paginator/components/paginator.d.ts.map +1 -0
- package/types/components/paginator/components/paginator.test.d.ts +2 -0
- package/types/components/paginator/components/paginator.test.d.ts.map +1 -0
- package/types/components/paginator/index.d.ts +2 -0
- package/types/components/paginator/index.d.ts.map +1 -0
- package/types/components/paginator/styles/ark.css.d.ts +3 -0
- package/types/components/paginator/styles/ark.css.d.ts.map +1 -0
- package/types/components/paginator/styles/index.d.ts +3 -0
- package/types/components/paginator/styles/index.d.ts.map +1 -0
- package/types/components/spinner/components/spinner.d.ts +11 -0
- package/types/components/spinner/components/spinner.d.ts.map +1 -0
- package/types/components/spinner/components/spinner.test.d.ts +2 -0
- package/types/components/spinner/components/spinner.test.d.ts.map +1 -0
- package/types/components/spinner/index.d.ts +2 -0
- package/types/components/spinner/index.d.ts.map +1 -0
- package/types/components/spinner/styles/ark.css.d.ts +3 -0
- package/types/components/spinner/styles/ark.css.d.ts.map +1 -0
- package/types/components/spinner/styles/index.d.ts +3 -0
- package/types/components/spinner/styles/index.d.ts.map +1 -0
- package/types/components/splitview/components/splitview.d.ts +12 -0
- package/types/components/splitview/components/splitview.d.ts.map +1 -0
- package/types/components/splitview/components/splitview.detail.d.ts +10 -0
- package/types/components/splitview/components/splitview.detail.d.ts.map +1 -0
- package/types/components/splitview/components/splitview.detail.test.d.ts +2 -0
- package/types/components/splitview/components/splitview.detail.test.d.ts.map +1 -0
- package/types/components/splitview/components/splitview.master.d.ts +8 -0
- package/types/components/splitview/components/splitview.master.d.ts.map +1 -0
- package/types/components/splitview/components/splitview.master.test.d.ts +2 -0
- package/types/components/splitview/components/splitview.master.test.d.ts.map +1 -0
- package/types/components/splitview/components/splitview.test.d.ts +2 -0
- package/types/components/splitview/components/splitview.test.d.ts.map +1 -0
- package/types/components/splitview/index.d.ts +4 -0
- package/types/components/splitview/index.d.ts.map +1 -0
- package/types/components/translate/components/translate.d.ts +18 -0
- package/types/components/translate/components/translate.d.ts.map +1 -0
- package/types/components/translate/components/translate.test.d.ts +2 -0
- package/types/components/translate/components/translate.test.d.ts.map +1 -0
- package/types/components/translate/index.d.ts +2 -0
- package/types/components/translate/index.d.ts.map +1 -0
- package/types/index.d.ts +3 -0
- package/types/index.d.ts.map +1 -0
|
@@ -1,52 +1,52 @@
|
|
|
1
|
+
import { it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
1
3
|
import { getSlots } from './slots.js'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
})
|
|
5
|
+
it('can be rendered without content', () => {
|
|
6
|
+
const item = document.createElement('div')
|
|
7
|
+
const slots = getSlots(item)
|
|
8
|
+
assert.ok(!slots.general.length)
|
|
9
|
+
})
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
it('can be rendered with content', () => {
|
|
12
|
+
const item = document.createElement('div')
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
const obj = document.createElement('div')
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
item.appendChild(obj)
|
|
17
|
+
const slots = getSlots(item)
|
|
18
|
+
assert.ok(slots.general.length)
|
|
19
|
+
})
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
it('can be rendered with value slot', () => {
|
|
22
|
+
const item = document.createElement('div')
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const obj = document.createElement('div')
|
|
25
|
+
const att = document.createAttribute('slot')
|
|
26
|
+
att.value = 'mySlot'
|
|
27
|
+
obj.setAttributeNode(att)
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
item.appendChild(obj)
|
|
30
|
+
const slots = getSlots(item)
|
|
31
|
+
assert.ok(slots.mySlot.length)
|
|
32
|
+
})
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
it('can be rendered with multiple values slot', () => {
|
|
35
|
+
const item = document.createElement('div')
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const obj = document.createElement('div')
|
|
38
|
+
const att = document.createAttribute('slot')
|
|
39
|
+
att.value = 'mySlot'
|
|
40
|
+
obj.setAttributeNode(att)
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
item.appendChild(obj)
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
const obj2 = document.createElement('div')
|
|
45
|
+
const att2 = document.createAttribute('slot')
|
|
46
|
+
att2.value = 'mySlot'
|
|
47
|
+
obj2.setAttributeNode(att2)
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
})
|
|
49
|
+
item.appendChild(obj2)
|
|
50
|
+
const slots = getSlots(item)
|
|
51
|
+
assert.ok(slots.mySlot.length)
|
|
52
52
|
})
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
+
import { it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
1
3
|
import { uuid } from './uuid.js'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
it('total digits == 32', () => {
|
|
10
|
-
const id = uuid()
|
|
5
|
+
it('groups separated by dashes', () => {
|
|
6
|
+
const id = uuid()
|
|
7
|
+
assert.ok(id.split('-').length === 5)
|
|
8
|
+
})
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
digits += element
|
|
15
|
-
})
|
|
10
|
+
it('total digits == 32', () => {
|
|
11
|
+
const id = uuid()
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
let digits = ''
|
|
14
|
+
id.split('-').forEach(element => {
|
|
15
|
+
digits += element
|
|
18
16
|
})
|
|
17
|
+
|
|
18
|
+
assert.ok(digits.length === 32)
|
|
19
19
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component } from '
|
|
1
|
+
import { Component } from '#base/index.js'
|
|
2
2
|
import styles from '../styles/index.js'
|
|
3
3
|
|
|
4
4
|
const tag = 'ark-audio'
|
|
@@ -8,6 +8,7 @@ export class Audio extends Component {
|
|
|
8
8
|
this.dataURL = null
|
|
9
9
|
this.timerId = null
|
|
10
10
|
this.recorder = null
|
|
11
|
+
this.objectURL = null
|
|
11
12
|
this.global = context.global || window
|
|
12
13
|
|
|
13
14
|
return super.init()
|
|
@@ -70,6 +71,8 @@ export class Audio extends Component {
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
reset () {
|
|
74
|
+
clearInterval(this.timerId)
|
|
75
|
+
this._revokeObjectURL()
|
|
73
76
|
this.status = 'idle'
|
|
74
77
|
this.render()
|
|
75
78
|
this.dataURL = null
|
|
@@ -77,6 +80,13 @@ export class Audio extends Component {
|
|
|
77
80
|
this.recorder = null
|
|
78
81
|
}
|
|
79
82
|
|
|
83
|
+
disconnectedCallback () {
|
|
84
|
+
clearInterval(this.timerId)
|
|
85
|
+
this.recorder?.stream?.getTracks?.().forEach(track => track.stop())
|
|
86
|
+
this._revokeObjectURL()
|
|
87
|
+
super.disconnectedCallback()
|
|
88
|
+
}
|
|
89
|
+
|
|
80
90
|
_time () {
|
|
81
91
|
let count = 0
|
|
82
92
|
return setInterval(() => {
|
|
@@ -93,11 +103,20 @@ export class Audio extends Component {
|
|
|
93
103
|
|
|
94
104
|
/** @param {any} event */
|
|
95
105
|
_onData (event) {
|
|
96
|
-
const audio =
|
|
97
|
-
|
|
106
|
+
const audio = /** @type {HTMLAudioElement} */ (
|
|
107
|
+
this.querySelector('.ark-audio__audio'))
|
|
108
|
+
this._revokeObjectURL()
|
|
109
|
+
this.objectURL = this.global.URL.createObjectURL(event.data)
|
|
110
|
+
audio.src = this.objectURL
|
|
98
111
|
const reader = new this.global.FileReader()
|
|
99
112
|
reader.readAsDataURL(event.data)
|
|
100
113
|
reader.onloadend = () => { this.dataURL = reader.result }
|
|
101
114
|
}
|
|
115
|
+
|
|
116
|
+
_revokeObjectURL () {
|
|
117
|
+
if (!this.objectURL) return
|
|
118
|
+
this.global.URL.revokeObjectURL?.(this.objectURL)
|
|
119
|
+
this.objectURL = null
|
|
120
|
+
}
|
|
102
121
|
}
|
|
103
122
|
Component.define(tag, Audio, styles)
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { it, mock } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
import './audio.js'
|
|
3
4
|
|
|
4
|
-
jest.useFakeTimers()
|
|
5
|
-
|
|
6
5
|
const mockGlobal = {
|
|
7
6
|
navigator: {
|
|
8
7
|
mediaDevices: {
|
|
@@ -25,104 +24,135 @@ const mockGlobal = {
|
|
|
25
24
|
URL: { createObjectURL: (data) => 'mock://data/url' }
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
27
|
+
const mockGlobalWithRevoke = {
|
|
28
|
+
...mockGlobal,
|
|
29
|
+
URL: {
|
|
30
|
+
createObjectURL: (data) => 'mock://data/url',
|
|
31
|
+
revokeObjectURL: mock.fn()
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
container.remove()
|
|
37
|
-
container = null
|
|
38
|
-
})
|
|
35
|
+
let container = null
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
audio.init()
|
|
46
|
-
expect(audio).toBeTruthy()
|
|
37
|
+
const setup = () => {
|
|
38
|
+
document.body.innerHTML = ''
|
|
39
|
+
mock.timers.reset()
|
|
40
|
+
mock.timers.enable({
|
|
41
|
+
apis: ['setInterval', 'setTimeout']
|
|
47
42
|
})
|
|
43
|
+
container = document.createElement('div')
|
|
44
|
+
document.body.appendChild(container)
|
|
45
|
+
}
|
|
48
46
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
expect(audio.status).toEqual('recording')
|
|
59
|
-
expect(audio.recorder).toBeTruthy()
|
|
60
|
-
})
|
|
47
|
+
it('can be instantiated', () => {
|
|
48
|
+
setup()
|
|
49
|
+
container.innerHTML = `
|
|
50
|
+
<ark-audio></ark-audio>
|
|
51
|
+
`
|
|
52
|
+
const audio = container.querySelector('ark-audio')
|
|
53
|
+
audio.init()
|
|
54
|
+
assert.ok(audio)
|
|
55
|
+
})
|
|
61
56
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
57
|
+
it('can start recording', async () => {
|
|
58
|
+
setup()
|
|
59
|
+
container.innerHTML = `
|
|
60
|
+
<ark-audio></ark-audio>
|
|
61
|
+
`
|
|
62
|
+
const audio = container.querySelector('ark-audio')
|
|
63
|
+
audio.init({ global: mockGlobal })
|
|
64
|
+
|
|
65
|
+
assert.deepStrictEqual(audio.status, 'idle')
|
|
66
|
+
await audio.start(new Event('click'))
|
|
67
|
+
assert.deepStrictEqual(audio.status, 'recording')
|
|
68
|
+
assert.ok(audio.recorder)
|
|
69
|
+
})
|
|
75
70
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
expect(audio.recorder).toBeNull()
|
|
91
|
-
})
|
|
71
|
+
it('can stop recording', async () => {
|
|
72
|
+
setup()
|
|
73
|
+
container.innerHTML = `
|
|
74
|
+
<ark-audio></ark-audio>
|
|
75
|
+
`
|
|
76
|
+
const audio = container.querySelector('ark-audio')
|
|
77
|
+
audio.init({ global: mockGlobal })
|
|
78
|
+
|
|
79
|
+
assert.deepStrictEqual(audio.status, 'idle')
|
|
80
|
+
await audio.start(new Event('click'))
|
|
81
|
+
assert.deepStrictEqual(audio.status, 'recording')
|
|
82
|
+
audio.stop(new Event('click'))
|
|
83
|
+
assert.deepStrictEqual(audio.status, 'done')
|
|
84
|
+
})
|
|
92
85
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
86
|
+
it('can reset recording', async () => {
|
|
87
|
+
setup()
|
|
88
|
+
container.innerHTML = `
|
|
89
|
+
<ark-audio></ark-audio>
|
|
90
|
+
`
|
|
91
|
+
const audio = container.querySelector('ark-audio')
|
|
92
|
+
audio.init({ global: mockGlobal })
|
|
93
|
+
|
|
94
|
+
assert.deepStrictEqual(audio.status, 'idle')
|
|
95
|
+
await audio.start(new Event('click'))
|
|
96
|
+
assert.deepStrictEqual(audio.status, 'recording')
|
|
97
|
+
audio.stop(new Event('click'))
|
|
98
|
+
assert.deepStrictEqual(audio.status, 'done')
|
|
99
|
+
audio.reset(new Event('click'))
|
|
100
|
+
assert.deepStrictEqual(audio.status, 'idle')
|
|
101
|
+
assert.strictEqual(audio.recorder, null)
|
|
102
|
+
})
|
|
99
103
|
|
|
100
|
-
|
|
101
|
-
|
|
104
|
+
it('counts the ellapsed time of the recording', async () => {
|
|
105
|
+
setup()
|
|
106
|
+
container.innerHTML = `
|
|
107
|
+
<ark-audio></ark-audio>
|
|
108
|
+
`
|
|
109
|
+
const audio = container.querySelector('ark-audio')
|
|
110
|
+
audio.init({ global: mockGlobal })
|
|
111
|
+
|
|
112
|
+
await audio.start(new Event('click'))
|
|
113
|
+
mock.timers.tick(1000)
|
|
114
|
+
|
|
115
|
+
const timer = audio.select('.ark-audio__timer')
|
|
116
|
+
assert.deepStrictEqual(timer.textContent, '00:01')
|
|
117
|
+
mock.timers.tick(623000)
|
|
118
|
+
assert.deepStrictEqual(timer.textContent, '10:24')
|
|
119
|
+
})
|
|
102
120
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
121
|
+
it('sets the dataURL (base64) property when stopped', async () => {
|
|
122
|
+
setup()
|
|
123
|
+
container.innerHTML = `
|
|
124
|
+
<ark-audio></ark-audio>
|
|
125
|
+
`
|
|
126
|
+
const audio = container.querySelector('ark-audio')
|
|
127
|
+
audio.init({ global: mockGlobal })
|
|
108
128
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
<ark-audio></ark-audio>
|
|
112
|
-
`
|
|
113
|
-
const audio = container.querySelector('ark-audio')
|
|
114
|
-
audio.init({ global: mockGlobal })
|
|
129
|
+
await audio.start(new Event('click'))
|
|
130
|
+
audio.stop(new Event('click'))
|
|
115
131
|
|
|
116
|
-
|
|
117
|
-
|
|
132
|
+
audio._onData({
|
|
133
|
+
data: new globalThis.Blob(['Hello'], { type: 'text/plain' })
|
|
134
|
+
})
|
|
135
|
+
mock.timers.tick(1000)
|
|
118
136
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
jest.runOnlyPendingTimers()
|
|
137
|
+
assert.deepStrictEqual(audio.dataURL, 'base64::data::result')
|
|
138
|
+
assert.deepStrictEqual(audio.querySelector('.ark-audio__audio').src, 'mock://data/url')
|
|
139
|
+
})
|
|
123
140
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
141
|
+
it('revokes the previously created object URL', () => {
|
|
142
|
+
setup()
|
|
143
|
+
container.innerHTML = `
|
|
144
|
+
<ark-audio></ark-audio>
|
|
145
|
+
`
|
|
146
|
+
const audio = container.querySelector('ark-audio')
|
|
147
|
+
mockGlobalWithRevoke.URL.revokeObjectURL.mock.resetCalls()
|
|
148
|
+
audio.init({ global: mockGlobalWithRevoke })
|
|
149
|
+
audio.objectURL = 'mock://data/url'
|
|
150
|
+
|
|
151
|
+
audio._revokeObjectURL()
|
|
152
|
+
|
|
153
|
+
assert.deepStrictEqual(
|
|
154
|
+
mockGlobalWithRevoke.URL.revokeObjectURL.mock.calls[0].arguments[0],
|
|
155
|
+
'mock://data/url'
|
|
156
|
+
)
|
|
157
|
+
assert.strictEqual(audio.objectURL, null)
|
|
128
158
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component } from '
|
|
1
|
+
import { Component } from '#base/index.js'
|
|
2
2
|
import styles from '../styles/index.js'
|
|
3
3
|
|
|
4
4
|
const tag = 'ark-camera'
|
|
@@ -34,8 +34,8 @@ export class Camera extends Component {
|
|
|
34
34
|
|
|
35
35
|
/** @returns {string} */
|
|
36
36
|
dataURL (width = null, height = null) {
|
|
37
|
-
/** @type {HTMLCanvasElement} */
|
|
38
|
-
|
|
37
|
+
const canvas = /** @type {HTMLCanvasElement} */ (
|
|
38
|
+
this.canvas.cloneNode(true))
|
|
39
39
|
|
|
40
40
|
canvas.width = width || this.width
|
|
41
41
|
canvas.height = height || this.height
|
|
@@ -72,6 +72,11 @@ export class Camera extends Component {
|
|
|
72
72
|
await this.start()
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
disconnectedCallback () {
|
|
76
|
+
this.stop()
|
|
77
|
+
super.disconnectedCallback()
|
|
78
|
+
}
|
|
79
|
+
|
|
75
80
|
/** @returns {HTMLVideoElement} */
|
|
76
81
|
get video () {
|
|
77
82
|
return this.querySelector('.ark-camera__video')
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { it } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
1
3
|
import './camera.js'
|
|
2
4
|
|
|
3
5
|
const mockGlobal = () => ({
|
|
@@ -5,100 +7,103 @@ const mockGlobal = () => ({
|
|
|
5
7
|
mediaDevices: {
|
|
6
8
|
__stops: 0,
|
|
7
9
|
async getUserMedia (_options) {
|
|
8
|
-
|
|
10
|
+
const stream = {}
|
|
11
|
+
stream.getTracks = () => [{ stop: () => { this.__stops += 1 } }]
|
|
12
|
+
return stream
|
|
9
13
|
}
|
|
10
14
|
}
|
|
11
15
|
}
|
|
12
16
|
})
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
18
|
+
let container = null
|
|
19
|
+
|
|
20
|
+
const setup = () => {
|
|
21
|
+
document.body.innerHTML = ''
|
|
22
|
+
container = document.createElement('div')
|
|
23
|
+
document.body.appendChild(container)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
it('can be instantiated', () => {
|
|
27
|
+
setup()
|
|
28
|
+
container.innerHTML = `
|
|
29
|
+
<ark-camera></ark-camera>
|
|
30
|
+
`
|
|
31
|
+
const camera = container.querySelector('ark-camera')
|
|
32
|
+
assert.ok(camera)
|
|
33
|
+
|
|
34
|
+
assert.strictEqual(camera, camera.init())
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('sets its dimensions on canplay event', async () => {
|
|
38
|
+
setup()
|
|
39
|
+
container.innerHTML = `
|
|
40
|
+
<ark-camera width="50" height="80"></ark-camera>
|
|
41
|
+
`
|
|
42
|
+
const camera = container.querySelector('ark-camera')
|
|
43
|
+
const video = camera.select('video')
|
|
44
|
+
const canvas = camera.select('canvas')
|
|
45
|
+
|
|
46
|
+
video.dispatchEvent(new Event('canplay'))
|
|
47
|
+
|
|
48
|
+
assert.deepStrictEqual(video.getAttribute('width'), '50px')
|
|
49
|
+
assert.deepStrictEqual(video.getAttribute('height'), '80px')
|
|
50
|
+
|
|
51
|
+
assert.deepStrictEqual(canvas.getAttribute('width'), '50px')
|
|
52
|
+
assert.deepStrictEqual(canvas.getAttribute('height'), '80px')
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('can start video recording', async () => {
|
|
56
|
+
setup()
|
|
57
|
+
container.innerHTML = `
|
|
58
|
+
<ark-camera></ark-camera>
|
|
59
|
+
`
|
|
60
|
+
const camera = container.querySelector('ark-camera')
|
|
61
|
+
camera.init({ global: mockGlobal() })
|
|
62
|
+
|
|
63
|
+
await camera.start()
|
|
64
|
+
|
|
65
|
+
assert.ok(camera.video.srcObject.getTracks())
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('can stop video recording', async () => {
|
|
69
|
+
setup()
|
|
70
|
+
container.innerHTML = `
|
|
71
|
+
<ark-camera></ark-camera>
|
|
72
|
+
`
|
|
73
|
+
const camera = container.querySelector('ark-camera')
|
|
74
|
+
const global = mockGlobal()
|
|
75
|
+
camera.init({ global })
|
|
76
|
+
|
|
77
|
+
await camera.start()
|
|
78
|
+
|
|
79
|
+
camera.stop()
|
|
80
|
+
|
|
81
|
+
assert.deepStrictEqual(global.navigator.mediaDevices.__stops, 1)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('can set the camera orientation', async () => {
|
|
85
|
+
setup()
|
|
86
|
+
container.innerHTML = `
|
|
87
|
+
<ark-camera></ark-camera>
|
|
88
|
+
`
|
|
89
|
+
const camera = container.querySelector('ark-camera')
|
|
90
|
+
const global = mockGlobal()
|
|
91
|
+
camera.init({ global })
|
|
92
|
+
|
|
93
|
+
await camera.setCameraOrientation('environment')
|
|
94
|
+
|
|
95
|
+
assert.deepStrictEqual(camera.facingMode, 'environment')
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('gets the dataURL (base64) of its containing canvas', async () => {
|
|
99
|
+
setup()
|
|
100
|
+
container.innerHTML = `
|
|
101
|
+
<ark-camera></ark-camera>
|
|
102
|
+
`
|
|
103
|
+
const camera = container.querySelector('ark-camera')
|
|
104
|
+
camera.init({ global: mockGlobal() })
|
|
105
|
+
|
|
106
|
+
const data = camera.dataURL()
|
|
107
|
+
|
|
108
|
+
assert.ok(data)
|
|
104
109
|
})
|