@knowark/componarkjs 1.13.4 → 1.14.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/README.md +57 -45
- package/lib/base/component/component.js +142 -20
- package/lib/base/component/component.test.js +753 -374
- package/lib/base/component/index.js +3 -0
- package/lib/base/styles/index.js +4 -1
- package/lib/base/utils/define.js +30 -7
- package/lib/base/utils/define.test.js +129 -42
- package/lib/base/utils/format.js +12 -6
- package/lib/base/utils/format.test.js +16 -16
- package/lib/base/utils/helpers.js +42 -9
- package/lib/base/utils/helpers.test.js +134 -115
- package/lib/base/utils/index.js +1 -0
- package/lib/base/utils/slots.js +3 -2
- package/lib/base/utils/slots.test.js +38 -38
- package/lib/base/utils/uuid.js +1 -1
- package/lib/base/utils/uuid.test.js +13 -13
- package/lib/components/audio/components/audio.js +36 -3
- package/lib/components/audio/components/audio.test.js +120 -90
- package/lib/components/audio/index.js +1 -0
- package/lib/components/audio/styles/index.js +5 -1
- package/lib/components/camera/components/camera.js +15 -0
- package/lib/components/camera/components/camera.test.js +96 -91
- package/lib/components/camera/index.js +1 -0
- package/lib/components/camera/styles/index.js +5 -1
- package/lib/components/capture/components/capture.js +48 -4
- package/lib/components/capture/components/capture.test.js +165 -97
- package/lib/components/capture/index.js +1 -0
- package/lib/components/droparea/components/droparea-preview.js +114 -19
- package/lib/components/droparea/components/droparea-preview.test.js +344 -80
- package/lib/components/droparea/components/droparea.js +82 -6
- package/lib/components/droparea/components/droparea.test.js +309 -299
- package/lib/components/droparea/index.js +1 -0
- package/lib/components/droparea/styles/index.js +5 -1
- package/lib/components/emit/components/emit.js +34 -4
- package/lib/components/emit/components/emit.test.js +192 -134
- package/lib/components/emit/index.js +1 -0
- package/lib/components/index.js +2 -1
- package/lib/components/list/components/item.js +6 -0
- package/lib/components/list/components/item.test.js +69 -68
- package/lib/components/list/components/list.js +51 -7
- package/lib/components/list/components/list.test.js +358 -227
- package/lib/components/list/index.js +1 -0
- package/lib/components/paginator/components/paginator.js +34 -8
- package/lib/components/paginator/components/paginator.test.js +146 -143
- package/lib/components/paginator/index.js +1 -0
- package/lib/components/paginator/styles/index.js +5 -1
- package/lib/components/spinner/components/spinner.js +10 -0
- package/lib/components/spinner/components/spinner.test.js +36 -41
- package/lib/components/spinner/index.js +1 -0
- package/lib/components/spinner/styles/index.js +5 -1
- package/lib/components/splitview/components/splitview.detail.js +10 -1
- package/lib/components/splitview/components/splitview.detail.test.js +75 -73
- package/lib/components/splitview/components/splitview.js +54 -11
- package/lib/components/splitview/components/splitview.master.js +37 -2
- package/lib/components/splitview/components/splitview.master.test.js +52 -52
- package/lib/components/splitview/components/splitview.test.js +135 -31
- package/lib/components/splitview/index.js +1 -0
- package/lib/components/translate/components/translate.js +65 -14
- package/lib/components/translate/components/translate.test.js +658 -131
- package/lib/components/translate/index.js +1 -0
- package/lib/index.js +3 -0
- package/package.json +4 -27
- package/scripts/node-test-setup.js +94 -0
- package/tsconfig.json +1 -1
- package/types/base/component/component.d.ts +43 -8
- package/types/base/component/component.d.ts.map +1 -1
- package/types/base/component/index.d.ts +4 -6
- package/types/base/component/index.d.ts.map +1 -1
- package/types/base/styles/index.d.ts +3 -2
- package/types/base/styles/index.d.ts.map +1 -1
- package/types/base/utils/define.d.ts +3 -2
- package/types/base/utils/define.d.ts.map +1 -1
- package/types/base/utils/format.d.ts +12 -6
- package/types/base/utils/format.d.ts.map +1 -1
- package/types/base/utils/helpers.d.ts +27 -7
- package/types/base/utils/helpers.d.ts.map +1 -1
- package/types/base/utils/slots.d.ts +8 -10
- package/types/base/utils/slots.d.ts.map +1 -1
- package/types/base/utils/uuid.d.ts +1 -1
- package/types/base/utils/uuid.d.ts.map +1 -1
- package/types/components/audio/components/audio.d.ts +23 -9
- package/types/components/audio/components/audio.d.ts.map +1 -1
- package/types/components/audio/styles/index.d.ts +3 -2
- package/types/components/audio/styles/index.d.ts.map +1 -1
- package/types/components/camera/components/camera.d.ts +11 -3
- package/types/components/camera/components/camera.d.ts.map +1 -1
- package/types/components/camera/styles/index.d.ts +3 -2
- package/types/components/camera/styles/index.d.ts.map +1 -1
- package/types/components/capture/components/capture.d.ts +23 -3
- package/types/components/capture/components/capture.d.ts.map +1 -1
- package/types/components/droparea/components/droparea-preview.d.ts +64 -11
- package/types/components/droparea/components/droparea-preview.d.ts.map +1 -1
- package/types/components/droparea/components/droparea.d.ts +58 -13
- package/types/components/droparea/components/droparea.d.ts.map +1 -1
- package/types/components/droparea/styles/index.d.ts +3 -2
- package/types/components/droparea/styles/index.d.ts.map +1 -1
- package/types/components/emit/components/emit.d.ts +15 -3
- package/types/components/emit/components/emit.d.ts.map +1 -1
- package/types/components/list/components/item.d.ts +8 -1
- package/types/components/list/components/item.d.ts.map +1 -1
- package/types/components/list/components/list.d.ts +23 -5
- package/types/components/list/components/list.d.ts.map +1 -1
- package/types/components/paginator/components/paginator.d.ts +32 -8
- package/types/components/paginator/components/paginator.d.ts.map +1 -1
- package/types/components/paginator/styles/index.d.ts +3 -2
- package/types/components/paginator/styles/index.d.ts.map +1 -1
- package/types/components/spinner/components/spinner.d.ts +14 -3
- package/types/components/spinner/components/spinner.d.ts.map +1 -1
- package/types/components/spinner/styles/index.d.ts +3 -2
- package/types/components/spinner/styles/index.d.ts.map +1 -1
- package/types/components/splitview/components/splitview.d.ts +22 -4
- package/types/components/splitview/components/splitview.d.ts.map +1 -1
- package/types/components/splitview/components/splitview.detail.d.ts +12 -2
- package/types/components/splitview/components/splitview.detail.d.ts.map +1 -1
- package/types/components/splitview/components/splitview.master.d.ts +12 -1
- package/types/components/splitview/components/splitview.master.d.ts.map +1 -1
- package/types/components/translate/components/translate.d.ts +44 -10
- package/types/components/translate/components/translate.d.ts.map +1 -1
|
@@ -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
|
})
|
|
@@ -2,7 +2,12 @@ import { Component } from '#base/index.js'
|
|
|
2
2
|
import styles from '../styles/index.js'
|
|
3
3
|
|
|
4
4
|
const tag = 'ark-camera'
|
|
5
|
+
/**
|
|
6
|
+
* Camera capture component.
|
|
7
|
+
*/
|
|
5
8
|
export class Camera extends Component {
|
|
9
|
+
/** @param {object} context
|
|
10
|
+
* @returns {this} */
|
|
6
11
|
init (context = {}) {
|
|
7
12
|
this.width = this.width || context.width || 320
|
|
8
13
|
this.height = this.height || context.height || 320
|
|
@@ -47,6 +52,7 @@ export class Camera extends Component {
|
|
|
47
52
|
return canvas.toDataURL('image/jpg')
|
|
48
53
|
}
|
|
49
54
|
|
|
55
|
+
/** @returns {Promise<void>} */
|
|
50
56
|
async start () {
|
|
51
57
|
const stream = await this.global.navigator.mediaDevices.getUserMedia({
|
|
52
58
|
video: {
|
|
@@ -60,18 +66,27 @@ export class Camera extends Component {
|
|
|
60
66
|
this.video.srcObject = stream
|
|
61
67
|
}
|
|
62
68
|
|
|
69
|
+
/** @returns {void} */
|
|
63
70
|
stop () {
|
|
64
71
|
// @ts-ignore
|
|
65
72
|
const tracks = this.video.srcObject ? this.video.srcObject.getTracks() : []
|
|
66
73
|
tracks.forEach(track => track.stop())
|
|
67
74
|
}
|
|
68
75
|
|
|
76
|
+
/** @param {string} facingMode
|
|
77
|
+
* @returns {Promise<void>} */
|
|
69
78
|
async setCameraOrientation (facingMode) {
|
|
70
79
|
this.stop()
|
|
71
80
|
this.facingMode = facingMode
|
|
72
81
|
await this.start()
|
|
73
82
|
}
|
|
74
83
|
|
|
84
|
+
/** @returns {void} */
|
|
85
|
+
disconnectedCallback () {
|
|
86
|
+
this.stop()
|
|
87
|
+
super.disconnectedCallback()
|
|
88
|
+
}
|
|
89
|
+
|
|
75
90
|
/** @returns {HTMLVideoElement} */
|
|
76
91
|
get video () {
|
|
77
92
|
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
|
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Component } from "#base/index.js"
|
|
2
2
|
|
|
3
3
|
const tag = 'ark-capture'
|
|
4
|
+
/** Template-driven renderer component. */
|
|
4
5
|
export class Capture extends Component {
|
|
5
6
|
constructor () {
|
|
6
7
|
super()
|
|
@@ -12,9 +13,10 @@ export class Capture extends Component {
|
|
|
12
13
|
return ['receive']
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
/** @param {
|
|
16
|
+
/** @param {object} context
|
|
17
|
+
* @returns {this} */
|
|
16
18
|
init (context = {}) {
|
|
17
|
-
const data =
|
|
19
|
+
const data = this._parseJSON(this._pop(':scope > data')?.textContent)
|
|
18
20
|
this.source = /** @type {object} */ (
|
|
19
21
|
context.source) || data || this.source || {}
|
|
20
22
|
this.template = context.template || this.template || (
|
|
@@ -23,6 +25,7 @@ export class Capture extends Component {
|
|
|
23
25
|
return super.init()
|
|
24
26
|
}
|
|
25
27
|
|
|
28
|
+
/** @returns {this} */
|
|
26
29
|
render () {
|
|
27
30
|
const outputTemplate = this._pop(':scope > template')?.innerHTML
|
|
28
31
|
this.template = (
|
|
@@ -36,19 +39,60 @@ export class Capture extends Component {
|
|
|
36
39
|
return super.render()
|
|
37
40
|
}
|
|
38
41
|
|
|
42
|
+
/** @param {{detail:any}} event */
|
|
39
43
|
handle (event) {
|
|
40
44
|
const source = event.detail
|
|
41
45
|
this.init({ source }).render()
|
|
42
46
|
}
|
|
43
47
|
|
|
48
|
+
/**
|
|
49
|
+
* @param {string} template
|
|
50
|
+
* @returns {(data: any) => string}
|
|
51
|
+
*/
|
|
44
52
|
_format (template) {
|
|
45
|
-
|
|
53
|
+
let render = null
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
render = Function(`return \`${template}\``)
|
|
57
|
+
} catch (error) {
|
|
58
|
+
this.emit('error', error)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return (data) => {
|
|
62
|
+
if (!render) return ''
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
return render.call(data)
|
|
66
|
+
} catch (error) {
|
|
67
|
+
this.emit('error', error)
|
|
68
|
+
return ''
|
|
69
|
+
}
|
|
70
|
+
}
|
|
46
71
|
}
|
|
47
72
|
|
|
73
|
+
/**
|
|
74
|
+
* @param {string} selector
|
|
75
|
+
* @returns {HTMLElement|null}
|
|
76
|
+
*/
|
|
48
77
|
_pop (selector) {
|
|
49
78
|
const element = this.querySelector(selector)
|
|
50
79
|
element?.remove()
|
|
51
|
-
return element
|
|
80
|
+
return /** @type {HTMLElement|null} */ (element)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @param {string|null} source
|
|
85
|
+
* @returns {object|null}
|
|
86
|
+
*/
|
|
87
|
+
_parseJSON (source) {
|
|
88
|
+
if (!source) return null
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
return JSON.parse(source)
|
|
92
|
+
} catch (error) {
|
|
93
|
+
this.emit('error', error)
|
|
94
|
+
return null
|
|
95
|
+
}
|
|
52
96
|
}
|
|
53
97
|
}
|
|
54
98
|
Component.define(tag, Capture)
|