@digipair/skill-web-interact 0.90.0 → 0.91.0-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/.swcrc +28 -0
- package/README.md +7 -0
- package/eslint.config.mjs +22 -0
- package/package.json +21 -5
- package/rollup.config.cjs +28 -0
- package/src/lib/skill-web-interact.spec.ts +7 -0
- package/src/lib/skill-web-interact.ts +168 -0
- package/tsconfig.json +13 -0
- package/tsconfig.lib.json +19 -0
- package/index.cjs.d.ts +0 -1
- package/index.cjs.js +0 -148
- package/index.esm.js +0 -135
- package/libs/skill-web-interact/src/lib/skill-web-interact.d.ts +0 -11
- /package/{index.d.ts → src/index.d.ts} +0 -0
- /package/{libs/skill-web-interact/src/index.d.ts → src/index.ts} +0 -0
- /package/{schema.fr.json → src/schema.fr.json} +0 -0
- /package/{schema.json → src/schema.json} +0 -0
package/.swcrc
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"jsc": {
|
|
3
|
+
"target": "es2017",
|
|
4
|
+
"parser": {
|
|
5
|
+
"syntax": "typescript",
|
|
6
|
+
"decorators": true,
|
|
7
|
+
"dynamicImport": true
|
|
8
|
+
},
|
|
9
|
+
"transform": {
|
|
10
|
+
"decoratorMetadata": true,
|
|
11
|
+
"legacyDecorator": true
|
|
12
|
+
},
|
|
13
|
+
"keepClassNames": true,
|
|
14
|
+
"externalHelpers": true,
|
|
15
|
+
"loose": true
|
|
16
|
+
},
|
|
17
|
+
"module": {
|
|
18
|
+
"type": "es6"
|
|
19
|
+
},
|
|
20
|
+
"sourceMaps": true,
|
|
21
|
+
"exclude": [
|
|
22
|
+
"jest.config.ts",
|
|
23
|
+
".*\\.spec.tsx?$",
|
|
24
|
+
".*\\.test.tsx?$",
|
|
25
|
+
"./src/jest-setup.ts$",
|
|
26
|
+
"./**/jest-setup.ts$"
|
|
27
|
+
]
|
|
28
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import baseConfig from '../../eslint.config.mjs';
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
...baseConfig,
|
|
5
|
+
{
|
|
6
|
+
files: ['**/*.json'],
|
|
7
|
+
rules: {
|
|
8
|
+
'@nx/dependency-checks': [
|
|
9
|
+
'error',
|
|
10
|
+
{
|
|
11
|
+
ignoredFiles: [
|
|
12
|
+
'{projectRoot}/eslint.config.{js,cjs,mjs}',
|
|
13
|
+
'{projectRoot}/rollup.config.{js,ts,mjs,mts,cjs,cts}',
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
languageOptions: {
|
|
19
|
+
parser: await import('jsonc-eslint-parser'),
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
];
|
package/package.json
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digipair/skill-web-interact",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.91.0-0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/libs/skill-web-interact/index.cjs.js",
|
|
6
|
+
"module": "dist/libs/skill-web-interact/index.esm.js",
|
|
7
|
+
"types": "dist/libs/skill-web-interact/index.esm.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./package.json": "./libs/skill-web-interact/package.json",
|
|
10
|
+
".": {
|
|
11
|
+
"development": "./dist/libs/skill-web-interact/src/index.ts",
|
|
12
|
+
"types": "./dist/libs/skill-web-interact/index.esm.d.ts",
|
|
13
|
+
"import": "./dist/libs/skill-web-interact/index.esm.js",
|
|
14
|
+
"default": "./dist/libs/skill-web-interact/index.cjs.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
4
17
|
"keywords": [
|
|
5
18
|
"digipair",
|
|
6
19
|
"web",
|
|
7
20
|
"util"
|
|
8
21
|
],
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
22
|
+
"nx": {
|
|
23
|
+
"name": "skill-web-interact"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@digipair/engine": "0.91.0-0"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const { withNx } = require('@nx/rollup/with-nx');
|
|
2
|
+
|
|
3
|
+
module.exports = withNx(
|
|
4
|
+
{
|
|
5
|
+
main: 'libs/skill-web-interact/src/index.ts',
|
|
6
|
+
outputPath: 'dist/libs/skill-web-interact',
|
|
7
|
+
tsConfig: 'libs/skill-web-interact/tsconfig.lib.json',
|
|
8
|
+
compiler: 'swc',
|
|
9
|
+
format: ['esm', "cjs"],
|
|
10
|
+
assets: [
|
|
11
|
+
{
|
|
12
|
+
input: 'libs/skill-web-interact/',
|
|
13
|
+
glob: 'package.json',
|
|
14
|
+
output: '.'
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
input: 'libs/skill-web-interact/src/',
|
|
18
|
+
glob: '*.json',
|
|
19
|
+
output: '.'
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
// Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
|
|
25
|
+
// e.g.
|
|
26
|
+
// output: { sourcemap: true },
|
|
27
|
+
}
|
|
28
|
+
);
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
|
+
import { PinsSettings } from '@digipair/engine';
|
|
4
|
+
|
|
5
|
+
class WebInteractService {
|
|
6
|
+
async setAttribute(params: any, _pinsSettingsList: PinsSettings[], _context: any): Promise<any> {
|
|
7
|
+
const { selector, attribute, value } = params;
|
|
8
|
+
const element = document.querySelector(selector) as any;
|
|
9
|
+
|
|
10
|
+
if (attribute === 'textContent') {
|
|
11
|
+
element.textContent = value;
|
|
12
|
+
} else if (attribute === 'value') {
|
|
13
|
+
element.value = value;
|
|
14
|
+
} else if (typeof value === 'string') {
|
|
15
|
+
element.setAttribute(attribute, value);
|
|
16
|
+
} else {
|
|
17
|
+
if (typeof element['__' + attribute] !== 'undefined') {
|
|
18
|
+
element['__' + attribute] = value;
|
|
19
|
+
element.requestUpdate();
|
|
20
|
+
} else {
|
|
21
|
+
element[attribute] = value;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async getAttribute(params: any, _pinsSettingsList: PinsSettings[], _context: any): Promise<any> {
|
|
27
|
+
const { selector, attribute } = params;
|
|
28
|
+
const element = document.querySelector(selector) as any;
|
|
29
|
+
|
|
30
|
+
return element[attribute] ?? element.getAttribute(attribute);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async dispatchEvent(params: any, _pinsSettingsList: PinsSettings[], _context: any): Promise<any> {
|
|
34
|
+
const { selector, name, detail } = params;
|
|
35
|
+
const element = document.querySelector(selector) as any;
|
|
36
|
+
|
|
37
|
+
element.dispatchEvent(new CustomEvent(name, { detail }));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async execute(params: any, _pinsSettingsList: PinsSettings[], _context: any): Promise<any> {
|
|
41
|
+
const { selector, name, args = [] } = params;
|
|
42
|
+
const element = document.querySelector(selector) as any;
|
|
43
|
+
|
|
44
|
+
return element[name](...args);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async goTo(params: any, _pinsSettingsList: PinsSettings[], _context: any): Promise<any> {
|
|
48
|
+
const { url, target = '_self' } = params;
|
|
49
|
+
window.open(url, target);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async reload(_params: any, _pinsSettingsList: PinsSettings[], _context: any): Promise<any> {
|
|
53
|
+
window.location.reload();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async upload(params: any, _pinsSettingsList: PinsSettings[], _context: any): Promise<any> {
|
|
57
|
+
const { accept = '*' } = params;
|
|
58
|
+
|
|
59
|
+
const result = await new Promise(resolve => {
|
|
60
|
+
const input = document.createElement('input');
|
|
61
|
+
input.type = 'file';
|
|
62
|
+
input.multiple = false;
|
|
63
|
+
input.accept = accept;
|
|
64
|
+
input.onchange = (event: any) => {
|
|
65
|
+
const files = event.target.files;
|
|
66
|
+
const file = files[0];
|
|
67
|
+
const reader = new FileReader();
|
|
68
|
+
reader.readAsDataURL(file);
|
|
69
|
+
reader.onload = () => {
|
|
70
|
+
resolve({ value: reader.result as string, filename: file.name });
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
input.click();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async uploadText(params: any, _pinsSettingsList: PinsSettings[], _context: any): Promise<any> {
|
|
80
|
+
const { accept = 'text/plain' } = params;
|
|
81
|
+
|
|
82
|
+
const result = await new Promise(resolve => {
|
|
83
|
+
const input = document.createElement('input');
|
|
84
|
+
input.type = 'file';
|
|
85
|
+
input.multiple = false;
|
|
86
|
+
input.accept = accept;
|
|
87
|
+
input.onchange = (event: any) => {
|
|
88
|
+
const files = event.target.files;
|
|
89
|
+
const file = files[0];
|
|
90
|
+
const reader = new FileReader();
|
|
91
|
+
reader.readAsText(file);
|
|
92
|
+
reader.onload = () => {
|
|
93
|
+
resolve({ value: reader.result as string, filename: file.name });
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
input.click();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async capture(params: any, _pinsSettingsList: PinsSettings[], _context: any): Promise<any> {
|
|
103
|
+
const { deviceId, width = 4096, height = 2160, facingMode = 'environment' } = params;
|
|
104
|
+
|
|
105
|
+
const constraints = {
|
|
106
|
+
audio: false,
|
|
107
|
+
video: {
|
|
108
|
+
width: { ideal: width },
|
|
109
|
+
height: { ideal: height },
|
|
110
|
+
facingMode,
|
|
111
|
+
deviceId,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const video = document.createElement('video');
|
|
116
|
+
video.autoplay = true;
|
|
117
|
+
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
|
118
|
+
video.srcObject = stream;
|
|
119
|
+
await new Promise(resolve => (video.onloadedmetadata = resolve));
|
|
120
|
+
const canvas = document.createElement('canvas');
|
|
121
|
+
canvas.width = video.videoWidth;
|
|
122
|
+
canvas.height = video.videoHeight;
|
|
123
|
+
const ctx = canvas.getContext('2d');
|
|
124
|
+
ctx?.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
125
|
+
const image = canvas.toDataURL('image/jpeg');
|
|
126
|
+
stream.getTracks().forEach(track => track.stop());
|
|
127
|
+
|
|
128
|
+
return image;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async getMediaDevices(
|
|
132
|
+
_params: any,
|
|
133
|
+
_pinsSettingsList: PinsSettings[],
|
|
134
|
+
_context: any,
|
|
135
|
+
): Promise<any> {
|
|
136
|
+
return navigator.mediaDevices.enumerateDevices();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export const setAttribute = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
|
|
141
|
+
new WebInteractService().setAttribute(params, pinsSettingsList, context);
|
|
142
|
+
|
|
143
|
+
export const getAttribute = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
|
|
144
|
+
new WebInteractService().getAttribute(params, pinsSettingsList, context);
|
|
145
|
+
|
|
146
|
+
export const dispatchEvent = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
|
|
147
|
+
new WebInteractService().dispatchEvent(params, pinsSettingsList, context);
|
|
148
|
+
|
|
149
|
+
export const execute = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
|
|
150
|
+
new WebInteractService().execute(params, pinsSettingsList, context);
|
|
151
|
+
|
|
152
|
+
export const goTo = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
|
|
153
|
+
new WebInteractService().goTo(params, pinsSettingsList, context);
|
|
154
|
+
|
|
155
|
+
export const reload = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
|
|
156
|
+
new WebInteractService().reload(params, pinsSettingsList, context);
|
|
157
|
+
|
|
158
|
+
export const upload = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
|
|
159
|
+
new WebInteractService().upload(params, pinsSettingsList, context);
|
|
160
|
+
|
|
161
|
+
export const uploadText = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
|
|
162
|
+
new WebInteractService().uploadText(params, pinsSettingsList, context);
|
|
163
|
+
|
|
164
|
+
export const capture = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
|
|
165
|
+
new WebInteractService().capture(params, pinsSettingsList, context);
|
|
166
|
+
|
|
167
|
+
export const getMediaDevices = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
|
|
168
|
+
new WebInteractService().getMediaDevices(params, pinsSettingsList, context);
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "src",
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
|
|
7
|
+
"emitDeclarationOnly": true,
|
|
8
|
+
"module": "esnext",
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"types": ["node"]
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*.ts"],
|
|
14
|
+
"references": [
|
|
15
|
+
{
|
|
16
|
+
"path": "../engine/tsconfig.lib.json"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
package/index.cjs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
package/index.cjs.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unused-vars */ let WebInteractService = class WebInteractService {
|
|
6
|
-
async setAttribute(params, _pinsSettingsList, _context) {
|
|
7
|
-
const { selector, attribute, value } = params;
|
|
8
|
-
const element = document.querySelector(selector);
|
|
9
|
-
if (attribute === 'textContent') {
|
|
10
|
-
element.textContent = value;
|
|
11
|
-
} else if (attribute === 'value') {
|
|
12
|
-
element.value = value;
|
|
13
|
-
} else if (typeof value === 'string') {
|
|
14
|
-
element.setAttribute(attribute, value);
|
|
15
|
-
} else {
|
|
16
|
-
if (typeof element['__' + attribute] !== 'undefined') {
|
|
17
|
-
element['__' + attribute] = value;
|
|
18
|
-
element.requestUpdate();
|
|
19
|
-
} else {
|
|
20
|
-
element[attribute] = value;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
async getAttribute(params, _pinsSettingsList, _context) {
|
|
25
|
-
const { selector, attribute } = params;
|
|
26
|
-
const element = document.querySelector(selector);
|
|
27
|
-
var _element_attribute;
|
|
28
|
-
return (_element_attribute = element[attribute]) != null ? _element_attribute : element.getAttribute(attribute);
|
|
29
|
-
}
|
|
30
|
-
async dispatchEvent(params, _pinsSettingsList, _context) {
|
|
31
|
-
const { selector, name, detail } = params;
|
|
32
|
-
const element = document.querySelector(selector);
|
|
33
|
-
element.dispatchEvent(new CustomEvent(name, {
|
|
34
|
-
detail
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
async execute(params, _pinsSettingsList, _context) {
|
|
38
|
-
const { selector, name, args = [] } = params;
|
|
39
|
-
const element = document.querySelector(selector);
|
|
40
|
-
return element[name](...args);
|
|
41
|
-
}
|
|
42
|
-
async goTo(params, _pinsSettingsList, _context) {
|
|
43
|
-
const { url, target = '_self' } = params;
|
|
44
|
-
window.open(url, target);
|
|
45
|
-
}
|
|
46
|
-
async reload(_params, _pinsSettingsList, _context) {
|
|
47
|
-
window.location.reload();
|
|
48
|
-
}
|
|
49
|
-
async upload(params, _pinsSettingsList, _context) {
|
|
50
|
-
const { accept = '*' } = params;
|
|
51
|
-
const result = await new Promise((resolve)=>{
|
|
52
|
-
const input = document.createElement('input');
|
|
53
|
-
input.type = 'file';
|
|
54
|
-
input.multiple = false;
|
|
55
|
-
input.accept = accept;
|
|
56
|
-
input.onchange = (event)=>{
|
|
57
|
-
const files = event.target.files;
|
|
58
|
-
const file = files[0];
|
|
59
|
-
const reader = new FileReader();
|
|
60
|
-
reader.readAsDataURL(file);
|
|
61
|
-
reader.onload = ()=>{
|
|
62
|
-
resolve({
|
|
63
|
-
value: reader.result,
|
|
64
|
-
filename: file.name
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
input.click();
|
|
69
|
-
});
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
async uploadText(params, _pinsSettingsList, _context) {
|
|
73
|
-
const { accept = 'text/plain' } = params;
|
|
74
|
-
const result = await new Promise((resolve)=>{
|
|
75
|
-
const input = document.createElement('input');
|
|
76
|
-
input.type = 'file';
|
|
77
|
-
input.multiple = false;
|
|
78
|
-
input.accept = accept;
|
|
79
|
-
input.onchange = (event)=>{
|
|
80
|
-
const files = event.target.files;
|
|
81
|
-
const file = files[0];
|
|
82
|
-
const reader = new FileReader();
|
|
83
|
-
reader.readAsText(file);
|
|
84
|
-
reader.onload = ()=>{
|
|
85
|
-
resolve({
|
|
86
|
-
value: reader.result,
|
|
87
|
-
filename: file.name
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
input.click();
|
|
92
|
-
});
|
|
93
|
-
return result;
|
|
94
|
-
}
|
|
95
|
-
async capture(params, _pinsSettingsList, _context) {
|
|
96
|
-
const { deviceId, width = 4096, height = 2160, facingMode = 'environment' } = params;
|
|
97
|
-
const constraints = {
|
|
98
|
-
audio: false,
|
|
99
|
-
video: {
|
|
100
|
-
width: {
|
|
101
|
-
ideal: width
|
|
102
|
-
},
|
|
103
|
-
height: {
|
|
104
|
-
ideal: height
|
|
105
|
-
},
|
|
106
|
-
facingMode,
|
|
107
|
-
deviceId
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
const video = document.createElement('video');
|
|
111
|
-
video.autoplay = true;
|
|
112
|
-
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
|
113
|
-
video.srcObject = stream;
|
|
114
|
-
await new Promise((resolve)=>video.onloadedmetadata = resolve);
|
|
115
|
-
const canvas = document.createElement('canvas');
|
|
116
|
-
canvas.width = video.videoWidth;
|
|
117
|
-
canvas.height = video.videoHeight;
|
|
118
|
-
const ctx = canvas.getContext('2d');
|
|
119
|
-
ctx == null ? void 0 : ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
120
|
-
const image = canvas.toDataURL('image/jpeg');
|
|
121
|
-
stream.getTracks().forEach((track)=>track.stop());
|
|
122
|
-
return image;
|
|
123
|
-
}
|
|
124
|
-
async getMediaDevices(_params, _pinsSettingsList, _context) {
|
|
125
|
-
return navigator.mediaDevices.enumerateDevices();
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
const setAttribute = (params, pinsSettingsList, context)=>new WebInteractService().setAttribute(params, pinsSettingsList, context);
|
|
129
|
-
const getAttribute = (params, pinsSettingsList, context)=>new WebInteractService().getAttribute(params, pinsSettingsList, context);
|
|
130
|
-
const dispatchEvent = (params, pinsSettingsList, context)=>new WebInteractService().dispatchEvent(params, pinsSettingsList, context);
|
|
131
|
-
const execute = (params, pinsSettingsList, context)=>new WebInteractService().execute(params, pinsSettingsList, context);
|
|
132
|
-
const goTo = (params, pinsSettingsList, context)=>new WebInteractService().goTo(params, pinsSettingsList, context);
|
|
133
|
-
const reload = (params, pinsSettingsList, context)=>new WebInteractService().reload(params, pinsSettingsList, context);
|
|
134
|
-
const upload = (params, pinsSettingsList, context)=>new WebInteractService().upload(params, pinsSettingsList, context);
|
|
135
|
-
const uploadText = (params, pinsSettingsList, context)=>new WebInteractService().uploadText(params, pinsSettingsList, context);
|
|
136
|
-
const capture = (params, pinsSettingsList, context)=>new WebInteractService().capture(params, pinsSettingsList, context);
|
|
137
|
-
const getMediaDevices = (params, pinsSettingsList, context)=>new WebInteractService().getMediaDevices(params, pinsSettingsList, context);
|
|
138
|
-
|
|
139
|
-
exports.capture = capture;
|
|
140
|
-
exports.dispatchEvent = dispatchEvent;
|
|
141
|
-
exports.execute = execute;
|
|
142
|
-
exports.getAttribute = getAttribute;
|
|
143
|
-
exports.getMediaDevices = getMediaDevices;
|
|
144
|
-
exports.goTo = goTo;
|
|
145
|
-
exports.reload = reload;
|
|
146
|
-
exports.setAttribute = setAttribute;
|
|
147
|
-
exports.upload = upload;
|
|
148
|
-
exports.uploadText = uploadText;
|
package/index.esm.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unused-vars */ let WebInteractService = class WebInteractService {
|
|
2
|
-
async setAttribute(params, _pinsSettingsList, _context) {
|
|
3
|
-
const { selector, attribute, value } = params;
|
|
4
|
-
const element = document.querySelector(selector);
|
|
5
|
-
if (attribute === 'textContent') {
|
|
6
|
-
element.textContent = value;
|
|
7
|
-
} else if (attribute === 'value') {
|
|
8
|
-
element.value = value;
|
|
9
|
-
} else if (typeof value === 'string') {
|
|
10
|
-
element.setAttribute(attribute, value);
|
|
11
|
-
} else {
|
|
12
|
-
if (typeof element['__' + attribute] !== 'undefined') {
|
|
13
|
-
element['__' + attribute] = value;
|
|
14
|
-
element.requestUpdate();
|
|
15
|
-
} else {
|
|
16
|
-
element[attribute] = value;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
async getAttribute(params, _pinsSettingsList, _context) {
|
|
21
|
-
const { selector, attribute } = params;
|
|
22
|
-
const element = document.querySelector(selector);
|
|
23
|
-
var _element_attribute;
|
|
24
|
-
return (_element_attribute = element[attribute]) != null ? _element_attribute : element.getAttribute(attribute);
|
|
25
|
-
}
|
|
26
|
-
async dispatchEvent(params, _pinsSettingsList, _context) {
|
|
27
|
-
const { selector, name, detail } = params;
|
|
28
|
-
const element = document.querySelector(selector);
|
|
29
|
-
element.dispatchEvent(new CustomEvent(name, {
|
|
30
|
-
detail
|
|
31
|
-
}));
|
|
32
|
-
}
|
|
33
|
-
async execute(params, _pinsSettingsList, _context) {
|
|
34
|
-
const { selector, name, args = [] } = params;
|
|
35
|
-
const element = document.querySelector(selector);
|
|
36
|
-
return element[name](...args);
|
|
37
|
-
}
|
|
38
|
-
async goTo(params, _pinsSettingsList, _context) {
|
|
39
|
-
const { url, target = '_self' } = params;
|
|
40
|
-
window.open(url, target);
|
|
41
|
-
}
|
|
42
|
-
async reload(_params, _pinsSettingsList, _context) {
|
|
43
|
-
window.location.reload();
|
|
44
|
-
}
|
|
45
|
-
async upload(params, _pinsSettingsList, _context) {
|
|
46
|
-
const { accept = '*' } = params;
|
|
47
|
-
const result = await new Promise((resolve)=>{
|
|
48
|
-
const input = document.createElement('input');
|
|
49
|
-
input.type = 'file';
|
|
50
|
-
input.multiple = false;
|
|
51
|
-
input.accept = accept;
|
|
52
|
-
input.onchange = (event)=>{
|
|
53
|
-
const files = event.target.files;
|
|
54
|
-
const file = files[0];
|
|
55
|
-
const reader = new FileReader();
|
|
56
|
-
reader.readAsDataURL(file);
|
|
57
|
-
reader.onload = ()=>{
|
|
58
|
-
resolve({
|
|
59
|
-
value: reader.result,
|
|
60
|
-
filename: file.name
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
input.click();
|
|
65
|
-
});
|
|
66
|
-
return result;
|
|
67
|
-
}
|
|
68
|
-
async uploadText(params, _pinsSettingsList, _context) {
|
|
69
|
-
const { accept = 'text/plain' } = params;
|
|
70
|
-
const result = await new Promise((resolve)=>{
|
|
71
|
-
const input = document.createElement('input');
|
|
72
|
-
input.type = 'file';
|
|
73
|
-
input.multiple = false;
|
|
74
|
-
input.accept = accept;
|
|
75
|
-
input.onchange = (event)=>{
|
|
76
|
-
const files = event.target.files;
|
|
77
|
-
const file = files[0];
|
|
78
|
-
const reader = new FileReader();
|
|
79
|
-
reader.readAsText(file);
|
|
80
|
-
reader.onload = ()=>{
|
|
81
|
-
resolve({
|
|
82
|
-
value: reader.result,
|
|
83
|
-
filename: file.name
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
input.click();
|
|
88
|
-
});
|
|
89
|
-
return result;
|
|
90
|
-
}
|
|
91
|
-
async capture(params, _pinsSettingsList, _context) {
|
|
92
|
-
const { deviceId, width = 4096, height = 2160, facingMode = 'environment' } = params;
|
|
93
|
-
const constraints = {
|
|
94
|
-
audio: false,
|
|
95
|
-
video: {
|
|
96
|
-
width: {
|
|
97
|
-
ideal: width
|
|
98
|
-
},
|
|
99
|
-
height: {
|
|
100
|
-
ideal: height
|
|
101
|
-
},
|
|
102
|
-
facingMode,
|
|
103
|
-
deviceId
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
const video = document.createElement('video');
|
|
107
|
-
video.autoplay = true;
|
|
108
|
-
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
|
109
|
-
video.srcObject = stream;
|
|
110
|
-
await new Promise((resolve)=>video.onloadedmetadata = resolve);
|
|
111
|
-
const canvas = document.createElement('canvas');
|
|
112
|
-
canvas.width = video.videoWidth;
|
|
113
|
-
canvas.height = video.videoHeight;
|
|
114
|
-
const ctx = canvas.getContext('2d');
|
|
115
|
-
ctx == null ? void 0 : ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
116
|
-
const image = canvas.toDataURL('image/jpeg');
|
|
117
|
-
stream.getTracks().forEach((track)=>track.stop());
|
|
118
|
-
return image;
|
|
119
|
-
}
|
|
120
|
-
async getMediaDevices(_params, _pinsSettingsList, _context) {
|
|
121
|
-
return navigator.mediaDevices.enumerateDevices();
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
const setAttribute = (params, pinsSettingsList, context)=>new WebInteractService().setAttribute(params, pinsSettingsList, context);
|
|
125
|
-
const getAttribute = (params, pinsSettingsList, context)=>new WebInteractService().getAttribute(params, pinsSettingsList, context);
|
|
126
|
-
const dispatchEvent = (params, pinsSettingsList, context)=>new WebInteractService().dispatchEvent(params, pinsSettingsList, context);
|
|
127
|
-
const execute = (params, pinsSettingsList, context)=>new WebInteractService().execute(params, pinsSettingsList, context);
|
|
128
|
-
const goTo = (params, pinsSettingsList, context)=>new WebInteractService().goTo(params, pinsSettingsList, context);
|
|
129
|
-
const reload = (params, pinsSettingsList, context)=>new WebInteractService().reload(params, pinsSettingsList, context);
|
|
130
|
-
const upload = (params, pinsSettingsList, context)=>new WebInteractService().upload(params, pinsSettingsList, context);
|
|
131
|
-
const uploadText = (params, pinsSettingsList, context)=>new WebInteractService().uploadText(params, pinsSettingsList, context);
|
|
132
|
-
const capture = (params, pinsSettingsList, context)=>new WebInteractService().capture(params, pinsSettingsList, context);
|
|
133
|
-
const getMediaDevices = (params, pinsSettingsList, context)=>new WebInteractService().getMediaDevices(params, pinsSettingsList, context);
|
|
134
|
-
|
|
135
|
-
export { capture, dispatchEvent, execute, getAttribute, getMediaDevices, goTo, reload, setAttribute, upload, uploadText };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { PinsSettings } from '@digipair/engine';
|
|
2
|
-
export declare const setAttribute: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
|
|
3
|
-
export declare const getAttribute: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
|
|
4
|
-
export declare const dispatchEvent: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
|
|
5
|
-
export declare const execute: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
|
|
6
|
-
export declare const goTo: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
|
|
7
|
-
export declare const reload: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
|
|
8
|
-
export declare const upload: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
|
|
9
|
-
export declare const uploadText: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
|
|
10
|
-
export declare const capture: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
|
|
11
|
-
export declare const getMediaDevices: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|