@knowark/componarkjs 1.7.3
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/Makefile +49 -0
- package/README.md +47 -0
- package/knowarkjs.code-workspace +29 -0
- package/lib/base/component/README.rst +113 -0
- package/lib/base/component/component.js +115 -0
- package/lib/base/component/component.test.js +327 -0
- package/lib/base/component/index.js +3 -0
- package/lib/base/index.js +1 -0
- package/lib/base/styles/index.js +3 -0
- package/lib/base/styles/styles.js +320 -0
- package/lib/base/utils/define.js +21 -0
- package/lib/base/utils/define.test.js +62 -0
- package/lib/base/utils/format.js +24 -0
- package/lib/base/utils/format.test.js +19 -0
- package/lib/base/utils/helpers.js +96 -0
- package/lib/base/utils/helpers.test.js +154 -0
- package/lib/base/utils/index.js +5 -0
- package/lib/base/utils/slots.js +18 -0
- package/lib/base/utils/slots.test.js +52 -0
- package/lib/base/utils/uuid.js +9 -0
- package/lib/base/utils/uuid.test.js +19 -0
- package/lib/components/audio/README.md +22 -0
- package/lib/components/audio/components/audio.js +103 -0
- package/lib/components/audio/components/audio.test.js +127 -0
- package/lib/components/audio/index.js +1 -0
- package/lib/components/audio/styles/ark.css.js +83 -0
- package/lib/components/audio/styles/index.js +2 -0
- package/lib/components/camera/README.md +64 -0
- package/lib/components/camera/components/camera.js +85 -0
- package/lib/components/camera/components/camera.test.js +104 -0
- package/lib/components/camera/index.js +1 -0
- package/lib/components/camera/styles/ark.css.js +17 -0
- package/lib/components/camera/styles/index.js +2 -0
- package/lib/components/capture/components/capture.js +54 -0
- package/lib/components/capture/components/capture.test.js +112 -0
- package/lib/components/capture/index.js +1 -0
- package/lib/components/droparea/README.md +51 -0
- package/lib/components/droparea/components/droparea-preview.js +159 -0
- package/lib/components/droparea/components/droparea-preview.test.js +105 -0
- package/lib/components/droparea/components/droparea.js +165 -0
- package/lib/components/droparea/components/droparea.test.js +320 -0
- package/lib/components/droparea/index.js +1 -0
- package/lib/components/droparea/styles/ark.css.js +235 -0
- package/lib/components/droparea/styles/index.js +3 -0
- package/lib/components/emit/components/emit.js +33 -0
- package/lib/components/emit/components/emit.test.js +138 -0
- package/lib/components/emit/index.js +1 -0
- package/lib/components/index.js +9 -0
- package/lib/components/list/README.md +103 -0
- package/lib/components/list/components/item.test.js +93 -0
- package/lib/components/list/components/list.item.js +22 -0
- package/lib/components/list/components/list.js +96 -0
- package/lib/components/list/components/list.test.js +267 -0
- package/lib/components/list/index.js +2 -0
- package/lib/components/paginator/README.md +32 -0
- package/lib/components/paginator/components/paginator.js +110 -0
- package/lib/components/paginator/components/paginator.test.js +131 -0
- package/lib/components/paginator/index.js +1 -0
- package/lib/components/paginator/styles/ark.css.js +196 -0
- package/lib/components/paginator/styles/index.js +2 -0
- package/lib/components/spinner/README.md +41 -0
- package/lib/components/spinner/components/spinner.js +105 -0
- package/lib/components/spinner/components/spinner.test.js +50 -0
- package/lib/components/spinner/index.js +1 -0
- package/lib/components/spinner/styles/ark.css.js +658 -0
- package/lib/components/spinner/styles/index.js +2 -0
- package/lib/components/splitview/README.md +63 -0
- package/lib/components/splitview/components/splitview.detail.js +46 -0
- package/lib/components/splitview/components/splitview.detail.test.js +92 -0
- package/lib/components/splitview/components/splitview.js +69 -0
- package/lib/components/splitview/components/splitview.master.js +26 -0
- package/lib/components/splitview/components/splitview.master.test.js +55 -0
- package/lib/components/splitview/components/splitview.test.js +76 -0
- package/lib/components/splitview/index.js +3 -0
- package/lib/components/translate/README.md +56 -0
- package/lib/components/translate/components/translate.js +100 -0
- package/lib/components/translate/components/translate.test.js +226 -0
- package/lib/components/translate/index.js +1 -0
- package/lib/index.js +2 -0
- package/package.json +68 -0
- package/showcase/design/.htaccess +8 -0
- package/showcase/design/core/factories/development/development.factory.js +5 -0
- package/showcase/design/core/factories/development/index.js +1 -0
- package/showcase/design/core/factories/index.js +11 -0
- package/showcase/design/core/factories/standard.factory.js +19 -0
- package/showcase/design/index.html +22 -0
- package/showcase/design/index.js +7 -0
- package/showcase/design/screens/base/audio/audioDemo.js +32 -0
- package/showcase/design/screens/base/audio/index.js +25 -0
- package/showcase/design/screens/base/camera/cameraDemo.js +83 -0
- package/showcase/design/screens/base/camera/index.js +25 -0
- package/showcase/design/screens/base/droparea/dropareaDemo.js +88 -0
- package/showcase/design/screens/base/droparea/index.js +25 -0
- package/showcase/design/screens/base/index.js +42 -0
- package/showcase/design/screens/base/list/index.js +25 -0
- package/showcase/design/screens/base/list/listDemo.js +89 -0
- package/showcase/design/screens/base/paginator/index.js +25 -0
- package/showcase/design/screens/base/paginator/paginatorDemo.js +82 -0
- package/showcase/design/screens/base/root.component.js +294 -0
- package/showcase/design/screens/base/root.routes.js +28 -0
- package/showcase/design/screens/base/spinner/index.js +25 -0
- package/showcase/design/screens/base/spinner/spinnerDemo.js +55 -0
- package/showcase/design/screens/base/splitview/detailDemo.js +40 -0
- package/showcase/design/screens/base/splitview/index.js +25 -0
- package/showcase/design/screens/base/splitview/splitViewDemo.js +58 -0
- package/showcase/design/screens/base/translate/index.js +20 -0
- package/showcase/design/screens/base/translate/translateDemo.js +43 -0
- package/showcase/design/screens/main.js +12 -0
- package/showcase/design/screens/screens.routes.js +23 -0
- package/showcase/index.html +86 -0
- package/showcase/index.js +5 -0
- package/showcase/locales/en/default.json +5 -0
- package/showcase/locales/es/default.json +5 -0
- package/showcase/locales/fr/default.json +5 -0
- package/tsconfig.json +23 -0
- package/webpack.config.cjs +118 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { Translate } from './translate.js'
|
|
2
|
+
|
|
3
|
+
describe('Translate', () => {
|
|
4
|
+
let container = null
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
container = document.createElement('div')
|
|
7
|
+
document.body.appendChild(container)
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
container.remove()
|
|
12
|
+
container = null
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('can be instantiated', () => {
|
|
16
|
+
container.innerHTML = /* html */`
|
|
17
|
+
<ark-translate>
|
|
18
|
+
</ark-translate>
|
|
19
|
+
`
|
|
20
|
+
|
|
21
|
+
const translate = container.querySelector('ark-translate')
|
|
22
|
+
|
|
23
|
+
expect(translate).toBeTruthy()
|
|
24
|
+
expect(translate).toBe(translate.init())
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('translates the marked text inside the given root', async () => {
|
|
28
|
+
const root = document.createElement('div')
|
|
29
|
+
root.innerHTML = /* html */`
|
|
30
|
+
<span data-i18n="hello">Hello</span>
|
|
31
|
+
<p>
|
|
32
|
+
<span data-i18n="happy">Happy</span>!!!
|
|
33
|
+
<span data-i18n="world">World</span>!!!
|
|
34
|
+
</p>
|
|
35
|
+
`
|
|
36
|
+
container.appendChild(root)
|
|
37
|
+
const translateContainer = document.createElement('div')
|
|
38
|
+
translateContainer.innerHTML = /* html */`
|
|
39
|
+
<ark-translate>
|
|
40
|
+
<template>{
|
|
41
|
+
"en": {
|
|
42
|
+
"default": {
|
|
43
|
+
"hello": "Hello",
|
|
44
|
+
"world": "World"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"es": {
|
|
48
|
+
"default": {
|
|
49
|
+
"hello": "Hola",
|
|
50
|
+
"world": "Mundo"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}</template>
|
|
54
|
+
</ark-translate>
|
|
55
|
+
`
|
|
56
|
+
container.appendChild(translateContainer)
|
|
57
|
+
const translate = /** @type Translate **/ (
|
|
58
|
+
translateContainer.querySelector('ark-translate'))
|
|
59
|
+
|
|
60
|
+
await translate.transliterate()
|
|
61
|
+
|
|
62
|
+
const expectedRoot = document.createElement('div')
|
|
63
|
+
expectedRoot.innerHTML = /* html */`
|
|
64
|
+
<span data-i18n="hello">Hola</span>
|
|
65
|
+
<p>
|
|
66
|
+
<span data-i18n="happy">Happy</span>!!!
|
|
67
|
+
<span data-i18n="world">Mundo</span>!!!
|
|
68
|
+
</p>
|
|
69
|
+
`
|
|
70
|
+
expect(root).toEqual(expectedRoot)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('might use different translation languages and namespaces', async () => {
|
|
74
|
+
const root = document.createElement('div')
|
|
75
|
+
root.innerHTML = /* html */`
|
|
76
|
+
<span data-i18n="introModule:hello">hello</span>
|
|
77
|
+
<p>
|
|
78
|
+
<span data-i18n="introModule:happy">happy</span>!!!
|
|
79
|
+
<span data-i18n="introModule:world">world</span>!!!
|
|
80
|
+
</p>
|
|
81
|
+
`
|
|
82
|
+
container.appendChild(root)
|
|
83
|
+
const translateContainer = document.createElement('div')
|
|
84
|
+
translateContainer.innerHTML = /* html */`
|
|
85
|
+
<ark-translate>
|
|
86
|
+
<template>{
|
|
87
|
+
"es": {
|
|
88
|
+
"default": {
|
|
89
|
+
"hello": "Hola",
|
|
90
|
+
"world": "Mundo"
|
|
91
|
+
},
|
|
92
|
+
"introModule": {
|
|
93
|
+
"hello": "Quiubo",
|
|
94
|
+
"world": "Gente"
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"en": {
|
|
98
|
+
"default": {
|
|
99
|
+
"hello": "Hello",
|
|
100
|
+
"world": "World"
|
|
101
|
+
},
|
|
102
|
+
"introModule": {
|
|
103
|
+
"hello": "Hey",
|
|
104
|
+
"world": "Folks"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}</template>
|
|
108
|
+
</ark-translate>
|
|
109
|
+
`
|
|
110
|
+
container.appendChild(translateContainer)
|
|
111
|
+
const translate = /** @type Translate **/ (
|
|
112
|
+
translateContainer.querySelector('ark-translate'))
|
|
113
|
+
|
|
114
|
+
let options = { language: 'en', }
|
|
115
|
+
await translate.transliterate(options)
|
|
116
|
+
|
|
117
|
+
const expectedRoot = document.createElement('div')
|
|
118
|
+
expectedRoot.innerHTML = /* html */`
|
|
119
|
+
<span data-i18n="introModule:hello">Hey</span>
|
|
120
|
+
<p>
|
|
121
|
+
<span data-i18n="introModule:happy">happy</span>!!!
|
|
122
|
+
<span data-i18n="introModule:world">Folks</span>!!!
|
|
123
|
+
</p>
|
|
124
|
+
`
|
|
125
|
+
expect(root).toEqual(expectedRoot)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
// Unknown Namespace:
|
|
129
|
+
|
|
130
|
+
root.innerHTML = /* html */`
|
|
131
|
+
<span data-i18n="unknown:hello">Hello</span>
|
|
132
|
+
<p>
|
|
133
|
+
<span data-i18n="unknown:happy">Happy</span>!!!
|
|
134
|
+
<span data-i18n="unknown:world">World</span>!!!
|
|
135
|
+
</p>
|
|
136
|
+
`
|
|
137
|
+
|
|
138
|
+
options = { language: 'es' }
|
|
139
|
+
await translate.transliterate(options)
|
|
140
|
+
|
|
141
|
+
expectedRoot.innerHTML = /* html */`
|
|
142
|
+
<span data-i18n="unknown:hello">Hello</span>
|
|
143
|
+
<p>
|
|
144
|
+
<span data-i18n="unknown:happy">Happy</span>!!!
|
|
145
|
+
<span data-i18n="unknown:world">World</span>!!!
|
|
146
|
+
</p>
|
|
147
|
+
`
|
|
148
|
+
expect(root).toEqual(expectedRoot)
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it('translates the page content on language changes', async () => {
|
|
152
|
+
const translateContainer = document.createElement('div')
|
|
153
|
+
translateContainer.innerHTML = /* html */`
|
|
154
|
+
<ark-translate languages="es,en">
|
|
155
|
+
<template>{
|
|
156
|
+
"es": {
|
|
157
|
+
"default": {
|
|
158
|
+
"hello": "Hola",
|
|
159
|
+
"world": "Mundo"
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
"en": {
|
|
163
|
+
"default": {
|
|
164
|
+
"hello": "Hello",
|
|
165
|
+
"world": "World"
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}</template>
|
|
169
|
+
</ark-translate>
|
|
170
|
+
`
|
|
171
|
+
container.appendChild(translateContainer)
|
|
172
|
+
const translate = /** @type Translate **/ (
|
|
173
|
+
translateContainer.querySelector('ark-translate'))
|
|
174
|
+
const mockEvent = {
|
|
175
|
+
target: {value: 'en'}, stopPropagation: () => {}}
|
|
176
|
+
let givenOptions = null
|
|
177
|
+
translate.transliterate = async (options) => {
|
|
178
|
+
givenOptions = options }
|
|
179
|
+
|
|
180
|
+
await translate.onLanguageChanged(mockEvent)
|
|
181
|
+
|
|
182
|
+
expect(givenOptions).toEqual({language: 'en'})
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
it('fetches its translation files from the server', async () => {
|
|
187
|
+
const root = document.createElement('div')
|
|
188
|
+
root.innerHTML = /* html */`
|
|
189
|
+
<span data-i18n="hello">hello</span>
|
|
190
|
+
<p>
|
|
191
|
+
<span data-i18n="happy">happy</span>!!!
|
|
192
|
+
<span data-i18n="world">world</span>!!!
|
|
193
|
+
</p>
|
|
194
|
+
`
|
|
195
|
+
container.appendChild(root)
|
|
196
|
+
const translateContainer = document.createElement('div')
|
|
197
|
+
translateContainer.innerHTML = `
|
|
198
|
+
<ark-translate languages="es,en"></ark-translate>
|
|
199
|
+
`
|
|
200
|
+
container.appendChild(translateContainer)
|
|
201
|
+
const translate = /** @type Translate **/ (
|
|
202
|
+
translateContainer.querySelector('ark-translate'))
|
|
203
|
+
|
|
204
|
+
const mockFetch = async (url) => ({
|
|
205
|
+
json: async () => ({
|
|
206
|
+
"hello": "Hola",
|
|
207
|
+
"world": "Mundo",
|
|
208
|
+
"happy": "Feliz"
|
|
209
|
+
})
|
|
210
|
+
})
|
|
211
|
+
translate.init({ global: {
|
|
212
|
+
fetch: mockFetch, document: document } })
|
|
213
|
+
|
|
214
|
+
await translate.transliterate({language: 'es'})
|
|
215
|
+
|
|
216
|
+
const expectedRoot = document.createElement('div')
|
|
217
|
+
expectedRoot.innerHTML = /* html */`
|
|
218
|
+
<span data-i18n="hello">Hola</span>
|
|
219
|
+
<p>
|
|
220
|
+
<span data-i18n="happy">Feliz</span>!!!
|
|
221
|
+
<span data-i18n="world">Mundo</span>!!!
|
|
222
|
+
</p>
|
|
223
|
+
`
|
|
224
|
+
expect(root).toEqual(expectedRoot)
|
|
225
|
+
})
|
|
226
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Translate } from './components/translate.js'
|
package/lib/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@knowark/componarkjs",
|
|
3
|
+
"version": "1.7.3",
|
|
4
|
+
"author": "Knowark",
|
|
5
|
+
"description": "Knowark's Web Components Library",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"main": "lib/index.js",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' npx jest --coverage",
|
|
11
|
+
"dev": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' webpack serve --mode development --env development",
|
|
12
|
+
"prod": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' webpack --mode production --env production"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/knowark/componark.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"web",
|
|
20
|
+
"components"
|
|
21
|
+
],
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@knowark/injectarkjs": "^0.9.1",
|
|
24
|
+
"@knowark/routarkjs": "^0.6.5",
|
|
25
|
+
"@types/jest": "^29.5.2",
|
|
26
|
+
"clean-webpack-plugin": "^4.0.0",
|
|
27
|
+
"copy-webpack-plugin": "^11.0.0",
|
|
28
|
+
"file-loader": "^6.2.0",
|
|
29
|
+
"html-webpack-plugin": "^5.5.1",
|
|
30
|
+
"jest": "^29.5.0",
|
|
31
|
+
"jest-canvas-mock": "^2.5.1",
|
|
32
|
+
"jest-environment-jsdom": "^29.5.0",
|
|
33
|
+
"jsdom": "^22.1.0",
|
|
34
|
+
"npm-check-updates": "^16.10.12",
|
|
35
|
+
"webpack": "^5.85.1",
|
|
36
|
+
"webpack-cli": "^5.1.3",
|
|
37
|
+
"webpack-dev-server": "^4.15.0"
|
|
38
|
+
},
|
|
39
|
+
"directories": {
|
|
40
|
+
"test": "tests"
|
|
41
|
+
},
|
|
42
|
+
"standard": {
|
|
43
|
+
"env": [
|
|
44
|
+
"jest"
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
"jest": {
|
|
48
|
+
"verbose": true,
|
|
49
|
+
"clearMocks": true,
|
|
50
|
+
"testEnvironment": "jsdom",
|
|
51
|
+
"coverageDirectory": "/tmp/componark/coverage",
|
|
52
|
+
"transform": {},
|
|
53
|
+
"setupFiles": [
|
|
54
|
+
"jest-canvas-mock"
|
|
55
|
+
],
|
|
56
|
+
"moduleDirectories": [
|
|
57
|
+
"node_modules",
|
|
58
|
+
"lib"
|
|
59
|
+
],
|
|
60
|
+
"collectCoverageFrom": [
|
|
61
|
+
"**/lib/**",
|
|
62
|
+
"!**/showcase/**"
|
|
63
|
+
],
|
|
64
|
+
"transformIgnorePatterns": [
|
|
65
|
+
"node_modules/(?!@knowark)"
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './development.factory.js'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Routark } from '@knowark/routarkjs'
|
|
2
|
+
|
|
3
|
+
export class StandardFactory {
|
|
4
|
+
/** @param {string} method */
|
|
5
|
+
extract (method) {
|
|
6
|
+
return this[`_${method}`]
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
_router () {
|
|
10
|
+
const design = process.env.ARK_DESIGN
|
|
11
|
+
return new Routark(window, `/${design}/`)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const standardStrategy = {
|
|
16
|
+
Router: {
|
|
17
|
+
method: 'router'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width,
|
|
7
|
+
initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
|
8
|
+
<title>Componark</title>
|
|
9
|
+
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css">
|
|
10
|
+
<link href="https://fonts.googleapis.com/css2?family=Material+Icons" rel="stylesheet">
|
|
11
|
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css"
|
|
12
|
+
integrity="sha512-HK5fgLBL+xu6dm/Ii3z4xhlSUyZgTT9tuc/hSrtw6uzJOvgRr2a9jyxxT1ely+B+xFAmJKVSTbpM/CuL7qxO8w=="
|
|
13
|
+
crossorigin="anonymous" />
|
|
14
|
+
<link href="https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;700&display=swap" rel="stylesheet">
|
|
15
|
+
|
|
16
|
+
</head>
|
|
17
|
+
|
|
18
|
+
<body>
|
|
19
|
+
<main></main>
|
|
20
|
+
</body>
|
|
21
|
+
|
|
22
|
+
</html>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Component } from 'base/component/index.js'
|
|
2
|
+
|
|
3
|
+
export class AudioDemo extends Component {
|
|
4
|
+
init (context) {
|
|
5
|
+
return super.init(context)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
render () {
|
|
9
|
+
this.content = /* html */ `
|
|
10
|
+
<ark-audio></ark-audio>
|
|
11
|
+
|
|
12
|
+
<a
|
|
13
|
+
target="_blank"
|
|
14
|
+
href="https://github.com/knowark/componark/blob/master/lib/components/audio/README.md">
|
|
15
|
+
* Reference
|
|
16
|
+
</a>
|
|
17
|
+
`
|
|
18
|
+
return super.render()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const styles = `
|
|
23
|
+
demo-audio{
|
|
24
|
+
padding: 1rem;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
audio{
|
|
28
|
+
margin: 1rem;
|
|
29
|
+
}
|
|
30
|
+
`
|
|
31
|
+
|
|
32
|
+
Component.define('demo-audio', AudioDemo, styles)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AudioDemo } from './audioDemo.js'
|
|
2
|
+
|
|
3
|
+
export function hub (parentResolver) {
|
|
4
|
+
const resolver = parentResolver.forge({
|
|
5
|
+
strategy: {
|
|
6
|
+
AudioDemo: {
|
|
7
|
+
method: 'component'
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
factory: new ComponentFactory()
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
return resolver.resolve('AudioDemo')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class ComponentFactory {
|
|
17
|
+
/** @param {string} method */
|
|
18
|
+
extract (method) {
|
|
19
|
+
return this[`_${method}`]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
_component () {
|
|
23
|
+
return new AudioDemo()
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Component } from 'base/component/index.js'
|
|
2
|
+
|
|
3
|
+
const tag = 'demo-camera'
|
|
4
|
+
export class CameraDemo extends Component {
|
|
5
|
+
render () {
|
|
6
|
+
this.innerHTML = /* html */ `
|
|
7
|
+
<div class="camera-container">
|
|
8
|
+
<ark-camera></ark-camera>
|
|
9
|
+
<div class="menu">
|
|
10
|
+
<ark-button background="primary" listen on-click="takepicture">Take photo</ark-button>
|
|
11
|
+
<ark-button background="success" listen on-click="startCamera">Start</ark-button>
|
|
12
|
+
<ark-button background="danger" color="dark" listen on-click="stopCamera">stop</ark-button>
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
<img data-photo>
|
|
17
|
+
|
|
18
|
+
<br>
|
|
19
|
+
|
|
20
|
+
<a
|
|
21
|
+
target="_blank"
|
|
22
|
+
href="https://github.com/knowark/componark/blob/master/lib/components/camera/README.md">
|
|
23
|
+
* Reference
|
|
24
|
+
</a>
|
|
25
|
+
`
|
|
26
|
+
|
|
27
|
+
this.camera['start']()
|
|
28
|
+
|
|
29
|
+
return super.render()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
disconnectedCallback () {
|
|
33
|
+
this.camera['stop']()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
takepicture () {
|
|
37
|
+
this.photo.setAttribute('src', this.camera['dataURL'](200, 200))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
startCamera () {
|
|
41
|
+
this.camera['start']()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
stopCamera () {
|
|
45
|
+
this.camera['stop']()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get camera () {
|
|
49
|
+
return this.select('ark-camera')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @returns {HTMLImageElement} */
|
|
53
|
+
get photo () {
|
|
54
|
+
return this.querySelector('[data-photo]')
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const styles = /* css */`
|
|
60
|
+
|
|
61
|
+
demo-camera{
|
|
62
|
+
display: flex;
|
|
63
|
+
flex-direction: column;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
ark-camera, img{
|
|
67
|
+
border-radius: 5px;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.camera-container{
|
|
71
|
+
display: flex;
|
|
72
|
+
flex-direction: column;
|
|
73
|
+
align-items: flex-start;
|
|
74
|
+
padding: 1rem;
|
|
75
|
+
width: 100%;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.ark-button{
|
|
79
|
+
margin:1rem 0.6rem;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
`
|
|
83
|
+
Component.define(tag, CameraDemo, styles)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CameraDemo } from './cameraDemo.js'
|
|
2
|
+
|
|
3
|
+
export function hub (parentResolver) {
|
|
4
|
+
const resolver = parentResolver.forge({
|
|
5
|
+
strategy: {
|
|
6
|
+
CameraDemo: {
|
|
7
|
+
method: 'component'
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
factory: new ComponentFactory()
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
return resolver.resolve('CameraDemo')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class ComponentFactory {
|
|
17
|
+
/** @param {string} method */
|
|
18
|
+
extract (method) {
|
|
19
|
+
return this[`_${method}`]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
_component () {
|
|
23
|
+
return new CameraDemo()
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Component } from 'base/component/index.js'
|
|
2
|
+
|
|
3
|
+
const tag = 'demo-droparea'
|
|
4
|
+
export class DropareaDemo extends Component {
|
|
5
|
+
init(context) {
|
|
6
|
+
return super.init(context)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
render() {
|
|
10
|
+
this.innerHTML = /* html */ `
|
|
11
|
+
<h1 class="title">
|
|
12
|
+
This is a drop area
|
|
13
|
+
</h1>
|
|
14
|
+
<div class="droparea-demo">
|
|
15
|
+
<p>Default(multi)</p>
|
|
16
|
+
<ark-droparea listen on-alter="onFileList"></ark-droparea>
|
|
17
|
+
|
|
18
|
+
<h4>Output as objectURL:</h4>
|
|
19
|
+
<div data-file-multi></div>
|
|
20
|
+
</div>
|
|
21
|
+
<div class="droparea-demo">
|
|
22
|
+
<p>Single</p>
|
|
23
|
+
<ark-droparea single accept="image" max-size="5"></ark-droparea>
|
|
24
|
+
</div>
|
|
25
|
+
<div class="droparea-demo">
|
|
26
|
+
<p>Single</p>
|
|
27
|
+
<ark-droparea data-load single accept="image" max-size="5"></ark-droparea>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
<a
|
|
31
|
+
class="reference"
|
|
32
|
+
target="_blank"
|
|
33
|
+
href="https://github.com/knowark/componark/tree/master/lib/components/droparea/README.md"
|
|
34
|
+
>
|
|
35
|
+
* Reference
|
|
36
|
+
</a>
|
|
37
|
+
`
|
|
38
|
+
return super.render()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async load() {
|
|
42
|
+
const myUrl =
|
|
43
|
+
'https://images.unsplash.com/photo-1530281700549-e82e7bf110d6?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1888&q=80'
|
|
44
|
+
|
|
45
|
+
const myFile = await this.getFileFromUrl(myUrl, 'Dogo.jpeg')
|
|
46
|
+
this.select('ark-droparea[data-load]').update({ contextFiles: [myFile] })
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async getFileFromUrl(url, name, defaultType = 'image/jpeg') {
|
|
50
|
+
const response = await fetch(url)
|
|
51
|
+
const data = await response.blob()
|
|
52
|
+
return new File([data], name, {
|
|
53
|
+
type: response.headers.get('content-type') || defaultType,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async onFileList(event) {
|
|
58
|
+
const element = this.querySelector('[data-file-multi]')
|
|
59
|
+
const droparea = this.select('.ark-droparea')
|
|
60
|
+
const urlList = []
|
|
61
|
+
if (element) {
|
|
62
|
+
droparea.fileList.forEach((file, index) =>
|
|
63
|
+
urlList.push(
|
|
64
|
+
`
|
|
65
|
+
<p>
|
|
66
|
+
<strong>${index}</strong> : ${file.name}
|
|
67
|
+
<strong>url:</strong>"${droparea.mediaList[index].url}"
|
|
68
|
+
<a href="${droparea.mediaList[index].url}" target="_blank">link</a>
|
|
69
|
+
</p>
|
|
70
|
+
`
|
|
71
|
+
)
|
|
72
|
+
)
|
|
73
|
+
element.innerHTML = urlList.join('')
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const styles = /* css */ `
|
|
79
|
+
.title{
|
|
80
|
+
color: var(--primary);
|
|
81
|
+
}
|
|
82
|
+
.droparea-demo{
|
|
83
|
+
max-width: 80%;
|
|
84
|
+
min-width: 250px
|
|
85
|
+
}
|
|
86
|
+
`
|
|
87
|
+
|
|
88
|
+
Component.define(tag, DropareaDemo, styles)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DropareaDemo } from "./dropareaDemo.js"
|
|
2
|
+
|
|
3
|
+
export function hub(parentResolver) {
|
|
4
|
+
const resolver = parentResolver.forge({
|
|
5
|
+
strategy: {
|
|
6
|
+
DropareaDemo: {
|
|
7
|
+
method: "component",
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
factory: new ComponentFactory(),
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
return resolver.resolve("DropareaDemo")
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class ComponentFactory {
|
|
17
|
+
/** @param {string} method */
|
|
18
|
+
extract(method) {
|
|
19
|
+
return this[`_${method}`]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
_component() {
|
|
23
|
+
return new DropareaDemo()
|
|
24
|
+
}
|
|
25
|
+
}
|