@twintag/twintag-core 0.2.284-fix-scanner-stream-visibility-a695ce585af24862ce02d73ace27e861e0e3e72f → 0.2.284-fix-scanner-stream-visibility-e1001dac4bbbb51970b19c08e9a5c830ae722924
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/dist/cjs/@worker-helper-fa4712a7.js +240 -0
- package/dist/cjs/twintag-pdf-viewer.cjs.entry.js +2 -193
- package/dist/cjs/twintag-qr-scanner.cjs.entry.js +86 -10
- package/dist/collection/components/twintag-scanner/twintag-qr-scanner.js +36 -9
- package/dist/collection/scanner-store.js +4 -0
- package/dist/collection/utils/create-local-store.js +43 -0
- package/dist/collection/utils/is-empty.js +3 -0
- package/dist/collection/version.js +1 -1
- package/dist/components/index3.js +237 -0
- package/dist/components/twintag-pdf-viewer2.js +2 -193
- package/dist/components/twintag-qr-scanner.js +86 -10
- package/dist/esm/@worker-helper-e45428b7.js +237 -0
- package/dist/esm/{index-174285a2.js → index-e1a48b05.js} +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/stencil-web-components.js +1 -1
- package/dist/esm/twintag-auth-callback.entry.js +1 -1
- package/dist/esm/twintag-auth-logout.entry.js +1 -1
- package/dist/esm/twintag-media.entry.js +1 -1
- package/dist/esm/twintag-ocr-scanner.entry.js +1 -1
- package/dist/esm/twintag-offline-actions.entry.js +1 -1
- package/dist/esm/twintag-offline-state.entry.js +1 -1
- package/dist/esm/twintag-offline-support.entry.js +1 -1
- package/dist/esm/twintag-pdf-viewer.entry.js +2 -193
- package/dist/esm/twintag-preview.entry.js +1 -1
- package/dist/esm/twintag-qr-scanner.entry.js +87 -11
- package/dist/esm/twintag-share.entry.js +1 -1
- package/dist/esm/twintag-spinner.entry.js +1 -1
- package/dist/stencil-web-components/p-1807206d.entry.js +1 -0
- package/dist/stencil-web-components/{p-67e2625e.entry.js → p-1e296694.entry.js} +1 -1
- package/dist/stencil-web-components/{p-4a001573.entry.js → p-5bd6d110.entry.js} +1 -1
- package/dist/stencil-web-components/{p-84e1cfed.entry.js → p-6cd7075c.entry.js} +1 -1
- package/dist/stencil-web-components/p-7943b86a.entry.js +1 -0
- package/dist/stencil-web-components/p-7b959006.js +1 -0
- package/dist/stencil-web-components/p-8806444b.entry.js +1 -0
- package/dist/stencil-web-components/{p-37b2160f.entry.js → p-9f7518ab.entry.js} +1 -1
- package/dist/stencil-web-components/{p-5f1060fe.entry.js → p-a53a2c70.entry.js} +1 -1
- package/dist/stencil-web-components/{p-feeba1cd.entry.js → p-a6f626bb.entry.js} +1 -1
- package/dist/stencil-web-components/{p-fb43176d.entry.js → p-d1230452.entry.js} +1 -1
- package/dist/stencil-web-components/{p-dff77416.entry.js → p-d428ed6b.entry.js} +1 -1
- package/dist/stencil-web-components/{p-cb286d41.js → p-d5d0e2ee.js} +1 -1
- package/dist/stencil-web-components/{p-0be73e86.entry.js → p-f58c7a83.entry.js} +1 -1
- package/dist/stencil-web-components/stencil-web-components.esm.js +1 -1
- package/dist/types/scanner-store.d.ts +3 -0
- package/dist/types/utils/create-local-store.d.ts +1 -0
- package/dist/types/utils/is-empty.d.ts +1 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/@worker-helper-6877046e.js +0 -48
- package/dist/components/@worker-helper.js +0 -46
- package/dist/esm/@worker-helper-f3e880f2.js +0 -46
- package/dist/stencil-web-components/p-01d4afb8.entry.js +0 -1
- package/dist/stencil-web-components/p-5e046324.js +0 -1
- package/dist/stencil-web-components/p-821ba724.entry.js +0 -1
- package/dist/stencil-web-components/p-a1c64978.entry.js +0 -1
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const index = require('./index-2c25b2e9.js');
|
|
4
|
+
|
|
5
|
+
const appendToMap = (map, propName, value) => {
|
|
6
|
+
const items = map.get(propName);
|
|
7
|
+
if (!items) {
|
|
8
|
+
map.set(propName, [value]);
|
|
9
|
+
}
|
|
10
|
+
else if (!items.includes(value)) {
|
|
11
|
+
items.push(value);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const debounce = (fn, ms) => {
|
|
15
|
+
let timeoutId;
|
|
16
|
+
return (...args) => {
|
|
17
|
+
if (timeoutId) {
|
|
18
|
+
clearTimeout(timeoutId);
|
|
19
|
+
}
|
|
20
|
+
timeoutId = setTimeout(() => {
|
|
21
|
+
timeoutId = 0;
|
|
22
|
+
fn(...args);
|
|
23
|
+
}, ms);
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Check if a possible element isConnected.
|
|
29
|
+
* The property might not be there, so we check for it.
|
|
30
|
+
*
|
|
31
|
+
* We want it to return true if isConnected is not a property,
|
|
32
|
+
* otherwise we would remove these elements and would not update.
|
|
33
|
+
*
|
|
34
|
+
* Better leak in Edge than to be useless.
|
|
35
|
+
*/
|
|
36
|
+
const isConnected = (maybeElement) => !('isConnected' in maybeElement) || maybeElement.isConnected;
|
|
37
|
+
const cleanupElements = debounce((map) => {
|
|
38
|
+
for (let key of map.keys()) {
|
|
39
|
+
map.set(key, map.get(key).filter(isConnected));
|
|
40
|
+
}
|
|
41
|
+
}, 2000);
|
|
42
|
+
const stencilSubscription = () => {
|
|
43
|
+
if (typeof index.getRenderingRef !== 'function') {
|
|
44
|
+
// If we are not in a stencil project, we do nothing.
|
|
45
|
+
// This function is not really exported by @stencil/core.
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
const elmsToUpdate = new Map();
|
|
49
|
+
return {
|
|
50
|
+
dispose: () => elmsToUpdate.clear(),
|
|
51
|
+
get: (propName) => {
|
|
52
|
+
const elm = index.getRenderingRef();
|
|
53
|
+
if (elm) {
|
|
54
|
+
appendToMap(elmsToUpdate, propName, elm);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
set: (propName) => {
|
|
58
|
+
const elements = elmsToUpdate.get(propName);
|
|
59
|
+
if (elements) {
|
|
60
|
+
elmsToUpdate.set(propName, elements.filter(index.forceUpdate));
|
|
61
|
+
}
|
|
62
|
+
cleanupElements(elmsToUpdate);
|
|
63
|
+
},
|
|
64
|
+
reset: () => {
|
|
65
|
+
elmsToUpdate.forEach((elms) => elms.forEach(index.forceUpdate));
|
|
66
|
+
cleanupElements(elmsToUpdate);
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const unwrap = (val) => (typeof val === 'function' ? val() : val);
|
|
72
|
+
const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) => {
|
|
73
|
+
const unwrappedState = unwrap(defaultState);
|
|
74
|
+
let states = new Map(Object.entries(unwrappedState !== null && unwrappedState !== void 0 ? unwrappedState : {}));
|
|
75
|
+
const handlers = {
|
|
76
|
+
dispose: [],
|
|
77
|
+
get: [],
|
|
78
|
+
set: [],
|
|
79
|
+
reset: [],
|
|
80
|
+
};
|
|
81
|
+
const reset = () => {
|
|
82
|
+
var _a;
|
|
83
|
+
// When resetting the state, the default state may be a function - unwrap it to invoke it.
|
|
84
|
+
// otherwise, the state won't be properly reset
|
|
85
|
+
states = new Map(Object.entries((_a = unwrap(defaultState)) !== null && _a !== void 0 ? _a : {}));
|
|
86
|
+
handlers.reset.forEach((cb) => cb());
|
|
87
|
+
};
|
|
88
|
+
const dispose = () => {
|
|
89
|
+
// Call first dispose as resetting the state would
|
|
90
|
+
// cause less updates ;)
|
|
91
|
+
handlers.dispose.forEach((cb) => cb());
|
|
92
|
+
reset();
|
|
93
|
+
};
|
|
94
|
+
const get = (propName) => {
|
|
95
|
+
handlers.get.forEach((cb) => cb(propName));
|
|
96
|
+
return states.get(propName);
|
|
97
|
+
};
|
|
98
|
+
const set = (propName, value) => {
|
|
99
|
+
const oldValue = states.get(propName);
|
|
100
|
+
if (shouldUpdate(value, oldValue, propName)) {
|
|
101
|
+
states.set(propName, value);
|
|
102
|
+
handlers.set.forEach((cb) => cb(propName, value, oldValue));
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const state = (typeof Proxy === 'undefined'
|
|
106
|
+
? {}
|
|
107
|
+
: new Proxy(unwrappedState, {
|
|
108
|
+
get(_, propName) {
|
|
109
|
+
return get(propName);
|
|
110
|
+
},
|
|
111
|
+
ownKeys(_) {
|
|
112
|
+
return Array.from(states.keys());
|
|
113
|
+
},
|
|
114
|
+
getOwnPropertyDescriptor() {
|
|
115
|
+
return {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
configurable: true,
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
has(_, propName) {
|
|
121
|
+
return states.has(propName);
|
|
122
|
+
},
|
|
123
|
+
set(_, propName, value) {
|
|
124
|
+
set(propName, value);
|
|
125
|
+
return true;
|
|
126
|
+
},
|
|
127
|
+
}));
|
|
128
|
+
const on = (eventName, callback) => {
|
|
129
|
+
handlers[eventName].push(callback);
|
|
130
|
+
return () => {
|
|
131
|
+
removeFromArray(handlers[eventName], callback);
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
const onChange = (propName, cb) => {
|
|
135
|
+
const unSet = on('set', (key, newValue) => {
|
|
136
|
+
if (key === propName) {
|
|
137
|
+
cb(newValue);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
// We need to unwrap the defaultState because it might be a function.
|
|
141
|
+
// Otherwise we might not be sending the right reset value.
|
|
142
|
+
const unReset = on('reset', () => cb(unwrap(defaultState)[propName]));
|
|
143
|
+
return () => {
|
|
144
|
+
unSet();
|
|
145
|
+
unReset();
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
const use = (...subscriptions) => {
|
|
149
|
+
const unsubs = subscriptions.reduce((unsubs, subscription) => {
|
|
150
|
+
if (subscription.set) {
|
|
151
|
+
unsubs.push(on('set', subscription.set));
|
|
152
|
+
}
|
|
153
|
+
if (subscription.get) {
|
|
154
|
+
unsubs.push(on('get', subscription.get));
|
|
155
|
+
}
|
|
156
|
+
if (subscription.reset) {
|
|
157
|
+
unsubs.push(on('reset', subscription.reset));
|
|
158
|
+
}
|
|
159
|
+
if (subscription.dispose) {
|
|
160
|
+
unsubs.push(on('dispose', subscription.dispose));
|
|
161
|
+
}
|
|
162
|
+
return unsubs;
|
|
163
|
+
}, []);
|
|
164
|
+
return () => unsubs.forEach((unsub) => unsub());
|
|
165
|
+
};
|
|
166
|
+
const forceUpdate = (key) => {
|
|
167
|
+
const oldValue = states.get(key);
|
|
168
|
+
handlers.set.forEach((cb) => cb(key, oldValue, oldValue));
|
|
169
|
+
};
|
|
170
|
+
return {
|
|
171
|
+
state,
|
|
172
|
+
get,
|
|
173
|
+
set,
|
|
174
|
+
on,
|
|
175
|
+
onChange,
|
|
176
|
+
use,
|
|
177
|
+
dispose,
|
|
178
|
+
reset,
|
|
179
|
+
forceUpdate,
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
const removeFromArray = (array, item) => {
|
|
183
|
+
const index = array.indexOf(item);
|
|
184
|
+
if (index >= 0) {
|
|
185
|
+
array[index] = array[array.length - 1];
|
|
186
|
+
array.length--;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const createStore = (defaultState, shouldUpdate) => {
|
|
191
|
+
const map = createObservableMap(defaultState, shouldUpdate);
|
|
192
|
+
map.use(stencilSubscription());
|
|
193
|
+
return map;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const pending = new Map();
|
|
197
|
+
const callbacks = new Map();
|
|
198
|
+
|
|
199
|
+
const createWorker = (workerPath, workerName, workerMsgId) => {
|
|
200
|
+
const worker = new Worker(workerPath, {name:workerName});
|
|
201
|
+
|
|
202
|
+
worker.addEventListener('message', ({data}) => {
|
|
203
|
+
if (data) {
|
|
204
|
+
const workerMsg = data[0];
|
|
205
|
+
const id = data[1];
|
|
206
|
+
const value = data[2];
|
|
207
|
+
|
|
208
|
+
if (workerMsg === workerMsgId) {
|
|
209
|
+
const err = data[3];
|
|
210
|
+
const [resolve, reject, callbackIds] = pending.get(id);
|
|
211
|
+
pending.delete(id);
|
|
212
|
+
|
|
213
|
+
if (err) {
|
|
214
|
+
const errObj = (err.isError)
|
|
215
|
+
? Object.assign(new Error(err.value.message), err.value)
|
|
216
|
+
: err.value;
|
|
217
|
+
|
|
218
|
+
index.consoleError(errObj);
|
|
219
|
+
reject(errObj);
|
|
220
|
+
} else {
|
|
221
|
+
if (callbackIds) {
|
|
222
|
+
callbackIds.forEach(id => callbacks.delete(id));
|
|
223
|
+
}
|
|
224
|
+
resolve(value);
|
|
225
|
+
}
|
|
226
|
+
} else if (workerMsg === workerMsgId + '.cb') {
|
|
227
|
+
try {
|
|
228
|
+
callbacks.get(id)(...value);
|
|
229
|
+
} catch (e) {
|
|
230
|
+
index.consoleError(e);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
return worker;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
exports.createStore = createStore;
|
|
240
|
+
exports.createWorker = createWorker;
|
|
@@ -3,205 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-2c25b2e9.js');
|
|
6
|
-
const _workerHelper = require('./@worker-helper-
|
|
6
|
+
const _workerHelper = require('./@worker-helper-fa4712a7.js');
|
|
7
7
|
|
|
8
8
|
const workerName = 'pdf-viewer.worker';
|
|
9
9
|
const workerMsgId = 'stencil.pdf-viewer.worker';
|
|
10
10
|
const workerPath = /*@__PURE__*/(typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/pdf-viewer.worker-451433c3.js').href : new URL('pdf-viewer.worker-451433c3.js', document.currentScript && document.currentScript.src || document.baseURI).href);
|
|
11
11
|
const worker = /*@__PURE__*/_workerHelper.createWorker(workerPath, workerName, workerMsgId);
|
|
12
12
|
|
|
13
|
-
const
|
|
14
|
-
const items = map.get(propName);
|
|
15
|
-
if (!items) {
|
|
16
|
-
map.set(propName, [value]);
|
|
17
|
-
}
|
|
18
|
-
else if (!items.includes(value)) {
|
|
19
|
-
items.push(value);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const debounce = (fn, ms) => {
|
|
23
|
-
let timeoutId;
|
|
24
|
-
return (...args) => {
|
|
25
|
-
if (timeoutId) {
|
|
26
|
-
clearTimeout(timeoutId);
|
|
27
|
-
}
|
|
28
|
-
timeoutId = setTimeout(() => {
|
|
29
|
-
timeoutId = 0;
|
|
30
|
-
fn(...args);
|
|
31
|
-
}, ms);
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Check if a possible element isConnected.
|
|
37
|
-
* The property might not be there, so we check for it.
|
|
38
|
-
*
|
|
39
|
-
* We want it to return true if isConnected is not a property,
|
|
40
|
-
* otherwise we would remove these elements and would not update.
|
|
41
|
-
*
|
|
42
|
-
* Better leak in Edge than to be useless.
|
|
43
|
-
*/
|
|
44
|
-
const isConnected = (maybeElement) => !('isConnected' in maybeElement) || maybeElement.isConnected;
|
|
45
|
-
const cleanupElements = debounce((map) => {
|
|
46
|
-
for (let key of map.keys()) {
|
|
47
|
-
map.set(key, map.get(key).filter(isConnected));
|
|
48
|
-
}
|
|
49
|
-
}, 2000);
|
|
50
|
-
const stencilSubscription = () => {
|
|
51
|
-
if (typeof index.getRenderingRef !== 'function') {
|
|
52
|
-
// If we are not in a stencil project, we do nothing.
|
|
53
|
-
// This function is not really exported by @stencil/core.
|
|
54
|
-
return {};
|
|
55
|
-
}
|
|
56
|
-
const elmsToUpdate = new Map();
|
|
57
|
-
return {
|
|
58
|
-
dispose: () => elmsToUpdate.clear(),
|
|
59
|
-
get: (propName) => {
|
|
60
|
-
const elm = index.getRenderingRef();
|
|
61
|
-
if (elm) {
|
|
62
|
-
appendToMap(elmsToUpdate, propName, elm);
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
set: (propName) => {
|
|
66
|
-
const elements = elmsToUpdate.get(propName);
|
|
67
|
-
if (elements) {
|
|
68
|
-
elmsToUpdate.set(propName, elements.filter(index.forceUpdate));
|
|
69
|
-
}
|
|
70
|
-
cleanupElements(elmsToUpdate);
|
|
71
|
-
},
|
|
72
|
-
reset: () => {
|
|
73
|
-
elmsToUpdate.forEach((elms) => elms.forEach(index.forceUpdate));
|
|
74
|
-
cleanupElements(elmsToUpdate);
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const unwrap = (val) => (typeof val === 'function' ? val() : val);
|
|
80
|
-
const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) => {
|
|
81
|
-
const unwrappedState = unwrap(defaultState);
|
|
82
|
-
let states = new Map(Object.entries(unwrappedState !== null && unwrappedState !== void 0 ? unwrappedState : {}));
|
|
83
|
-
const handlers = {
|
|
84
|
-
dispose: [],
|
|
85
|
-
get: [],
|
|
86
|
-
set: [],
|
|
87
|
-
reset: [],
|
|
88
|
-
};
|
|
89
|
-
const reset = () => {
|
|
90
|
-
var _a;
|
|
91
|
-
// When resetting the state, the default state may be a function - unwrap it to invoke it.
|
|
92
|
-
// otherwise, the state won't be properly reset
|
|
93
|
-
states = new Map(Object.entries((_a = unwrap(defaultState)) !== null && _a !== void 0 ? _a : {}));
|
|
94
|
-
handlers.reset.forEach((cb) => cb());
|
|
95
|
-
};
|
|
96
|
-
const dispose = () => {
|
|
97
|
-
// Call first dispose as resetting the state would
|
|
98
|
-
// cause less updates ;)
|
|
99
|
-
handlers.dispose.forEach((cb) => cb());
|
|
100
|
-
reset();
|
|
101
|
-
};
|
|
102
|
-
const get = (propName) => {
|
|
103
|
-
handlers.get.forEach((cb) => cb(propName));
|
|
104
|
-
return states.get(propName);
|
|
105
|
-
};
|
|
106
|
-
const set = (propName, value) => {
|
|
107
|
-
const oldValue = states.get(propName);
|
|
108
|
-
if (shouldUpdate(value, oldValue, propName)) {
|
|
109
|
-
states.set(propName, value);
|
|
110
|
-
handlers.set.forEach((cb) => cb(propName, value, oldValue));
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
const state = (typeof Proxy === 'undefined'
|
|
114
|
-
? {}
|
|
115
|
-
: new Proxy(unwrappedState, {
|
|
116
|
-
get(_, propName) {
|
|
117
|
-
return get(propName);
|
|
118
|
-
},
|
|
119
|
-
ownKeys(_) {
|
|
120
|
-
return Array.from(states.keys());
|
|
121
|
-
},
|
|
122
|
-
getOwnPropertyDescriptor() {
|
|
123
|
-
return {
|
|
124
|
-
enumerable: true,
|
|
125
|
-
configurable: true,
|
|
126
|
-
};
|
|
127
|
-
},
|
|
128
|
-
has(_, propName) {
|
|
129
|
-
return states.has(propName);
|
|
130
|
-
},
|
|
131
|
-
set(_, propName, value) {
|
|
132
|
-
set(propName, value);
|
|
133
|
-
return true;
|
|
134
|
-
},
|
|
135
|
-
}));
|
|
136
|
-
const on = (eventName, callback) => {
|
|
137
|
-
handlers[eventName].push(callback);
|
|
138
|
-
return () => {
|
|
139
|
-
removeFromArray(handlers[eventName], callback);
|
|
140
|
-
};
|
|
141
|
-
};
|
|
142
|
-
const onChange = (propName, cb) => {
|
|
143
|
-
const unSet = on('set', (key, newValue) => {
|
|
144
|
-
if (key === propName) {
|
|
145
|
-
cb(newValue);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
// We need to unwrap the defaultState because it might be a function.
|
|
149
|
-
// Otherwise we might not be sending the right reset value.
|
|
150
|
-
const unReset = on('reset', () => cb(unwrap(defaultState)[propName]));
|
|
151
|
-
return () => {
|
|
152
|
-
unSet();
|
|
153
|
-
unReset();
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
const use = (...subscriptions) => {
|
|
157
|
-
const unsubs = subscriptions.reduce((unsubs, subscription) => {
|
|
158
|
-
if (subscription.set) {
|
|
159
|
-
unsubs.push(on('set', subscription.set));
|
|
160
|
-
}
|
|
161
|
-
if (subscription.get) {
|
|
162
|
-
unsubs.push(on('get', subscription.get));
|
|
163
|
-
}
|
|
164
|
-
if (subscription.reset) {
|
|
165
|
-
unsubs.push(on('reset', subscription.reset));
|
|
166
|
-
}
|
|
167
|
-
if (subscription.dispose) {
|
|
168
|
-
unsubs.push(on('dispose', subscription.dispose));
|
|
169
|
-
}
|
|
170
|
-
return unsubs;
|
|
171
|
-
}, []);
|
|
172
|
-
return () => unsubs.forEach((unsub) => unsub());
|
|
173
|
-
};
|
|
174
|
-
const forceUpdate = (key) => {
|
|
175
|
-
const oldValue = states.get(key);
|
|
176
|
-
handlers.set.forEach((cb) => cb(key, oldValue, oldValue));
|
|
177
|
-
};
|
|
178
|
-
return {
|
|
179
|
-
state,
|
|
180
|
-
get,
|
|
181
|
-
set,
|
|
182
|
-
on,
|
|
183
|
-
onChange,
|
|
184
|
-
use,
|
|
185
|
-
dispose,
|
|
186
|
-
reset,
|
|
187
|
-
forceUpdate,
|
|
188
|
-
};
|
|
189
|
-
};
|
|
190
|
-
const removeFromArray = (array, item) => {
|
|
191
|
-
const index = array.indexOf(item);
|
|
192
|
-
if (index >= 0) {
|
|
193
|
-
array[index] = array[array.length - 1];
|
|
194
|
-
array.length--;
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
const createStore = (defaultState, shouldUpdate) => {
|
|
199
|
-
const map = createObservableMap(defaultState, shouldUpdate);
|
|
200
|
-
map.use(stencilSubscription());
|
|
201
|
-
return map;
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
const pdfStore = createStore({
|
|
13
|
+
const pdfStore = _workerHelper.createStore({
|
|
205
14
|
docs: new Map(),
|
|
206
15
|
});
|
|
207
16
|
|
|
@@ -4,13 +4,64 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const index = require('./index-2c25b2e9.js');
|
|
6
6
|
const index$1 = require('./index-8407a91f.js');
|
|
7
|
-
const _workerHelper = require('./@worker-helper-
|
|
7
|
+
const _workerHelper = require('./@worker-helper-fa4712a7.js');
|
|
8
|
+
|
|
9
|
+
const safeRead = (storage, key) => {
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(storage.getItem(key));
|
|
12
|
+
}
|
|
13
|
+
catch (_a) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const debounce = (fn) => {
|
|
18
|
+
let called = false;
|
|
19
|
+
return () => {
|
|
20
|
+
if (called) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
called = true;
|
|
24
|
+
setTimeout(() => {
|
|
25
|
+
fn();
|
|
26
|
+
called = false;
|
|
27
|
+
}, 0);
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const createStorageStore = (storage, key, defaultValues, syncAcrossTabs = false) => {
|
|
31
|
+
var _a;
|
|
32
|
+
const store = _workerHelper.createStore((_a = safeRead(storage, key)) !== null && _a !== void 0 ? _a : defaultValues);
|
|
33
|
+
// Need to sync later or we would get ourselves in an infinite loop.
|
|
34
|
+
const write = debounce(() => storage.setItem(key, JSON.stringify(store.state)));
|
|
35
|
+
write();
|
|
36
|
+
if (syncAcrossTabs) {
|
|
37
|
+
window.addEventListener('storage', () => {
|
|
38
|
+
const currentState = safeRead(storage, key);
|
|
39
|
+
if (currentState === null) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
for (const key in currentState) {
|
|
43
|
+
store.set(key, currentState[key]);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
store.use({ set: write, reset: write });
|
|
48
|
+
return store;
|
|
49
|
+
};
|
|
50
|
+
const createLocalStore = (key, defaultValues, syncAcrossTabs = false) => createStorageStore(localStorage, key, defaultValues, syncAcrossTabs);
|
|
51
|
+
|
|
52
|
+
const scannerStore = createLocalStore('twintag-barcode-scanner', {
|
|
53
|
+
deviceId: '',
|
|
54
|
+
});
|
|
8
55
|
|
|
9
56
|
const workerName = 'scanner.worker';
|
|
10
57
|
const workerMsgId = 'stencil.scanner.worker';
|
|
11
58
|
const workerPath = /*@__PURE__*/(typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/scanner.worker-02c80109.js').href : new URL('scanner.worker-02c80109.js', document.currentScript && document.currentScript.src || document.baseURI).href);
|
|
12
59
|
const worker = /*@__PURE__*/_workerHelper.createWorker(workerPath, workerName, workerMsgId);
|
|
13
60
|
|
|
61
|
+
function isEmpty(str) {
|
|
62
|
+
return !str || str.length === 0 || !str.trim();
|
|
63
|
+
}
|
|
64
|
+
|
|
14
65
|
const twintagScannerCss = ":host{--twintag-scanner-bg-select-cameras:white;--twintag-scanner-text-select-cameras:black;--twintag-scanner-radius-select-cameras:6px 0 0 0;--twintag-scanner-min-height:min-content;--twintag-scanner-corners-color:white;--twintag-scanner-corners-width:4px;--twintag-scanner-corners-length:36px;--twintag-scanner-corners-offset:24px;display:grid;place-items:center;position:relative;width:100%}:host .icon-container{display:grid;place-items:center;position:absolute;inset:0;z-index:-2222}:host .icon-container .check-icon{opacity:0;z-index:2222}:host .video-container{--crop:0;--crop-x:var(--crop);--crop-y:var(--crop);display:flex;align-items:center;justify-content:center;position:relative;width:100%;height:100%;opacity:0;overflow:hidden;z-index:1}:host .video-container::after{content:\"\";position:absolute;width:100%;height:100%;opacity:inherit;background:rgba(0, 0, 0, 0.5);-webkit-clip-path:polygon(0% 0%, 0% 100%, calc(var(--crop-x) * 1%) 100%, calc(var(--crop-x) * 1%) calc(var(--crop-y) * 1%), calc(calc(100 - var(--crop-x)) * 1%) calc(var(--crop-y) * 1%), calc(calc(100 - var(--crop-x)) * 1%) calc(calc(100 - var(--crop-y)) * 1%), calc(var(--crop-x) * 1%) calc(calc(100 - var(--crop-y)) * 1%), calc(var(--crop-x) * 1%) 100%, 100% 100%, 100% 0%);clip-path:polygon(0% 0%, 0% 100%, calc(var(--crop-x) * 1%) 100%, calc(var(--crop-x) * 1%) calc(var(--crop-y) * 1%), calc(calc(100 - var(--crop-x)) * 1%) calc(var(--crop-y) * 1%), calc(calc(100 - var(--crop-x)) * 1%) calc(calc(100 - var(--crop-y)) * 1%), calc(var(--crop-x) * 1%) calc(calc(100 - var(--crop-y)) * 1%), calc(var(--crop-x) * 1%) 100%, 100% 100%, 100% 0%)}:host .video-container:before{display:block;content:\"\";width:100%;padding-top:100%}:host .video-container .video-corners{position:absolute;width:calc((1 - var(--crop-x) / 50) * 100% + var(--twintag-scanner-corners-offset));height:calc((1 - var(--crop-y) / 50) * 100% + var(--twintag-scanner-corners-offset));opacity:inherit;background:linear-gradient(to right, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 0 0, linear-gradient(to right, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 0 100%, linear-gradient(to left, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 100% 0, linear-gradient(to left, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 100% 100%, linear-gradient(to bottom, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 0 0, linear-gradient(to bottom, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 100% 0, linear-gradient(to top, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 0 100%, linear-gradient(to top, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 100% 100%;background-size:var(--twintag-scanner-corners-length) var(--twintag-scanner-corners-length);background-repeat:no-repeat;z-index:2222}:host .video-container video{position:absolute;width:100% !important;object-fit:cover;object-position:center;aspect-ratio:1/1 !important;min-height:var(--twintag-scanner-min-height)}";
|
|
15
66
|
|
|
16
67
|
const MAX_STAGE_VALUE = 400;
|
|
@@ -75,7 +126,7 @@ const TwintagQRScanner = class {
|
|
|
75
126
|
// @ts-ignore - old typscript version
|
|
76
127
|
signal: this.eventsController.signal,
|
|
77
128
|
});
|
|
78
|
-
document.addEventListener(
|
|
129
|
+
document.addEventListener('visibilitychange', async () => {
|
|
79
130
|
if (document.hidden) {
|
|
80
131
|
if (this.stream) {
|
|
81
132
|
this.stopStream();
|
|
@@ -155,7 +206,7 @@ const TwintagQRScanner = class {
|
|
|
155
206
|
}
|
|
156
207
|
}
|
|
157
208
|
catch (err) {
|
|
158
|
-
|
|
209
|
+
throw new Error(err);
|
|
159
210
|
}
|
|
160
211
|
}
|
|
161
212
|
async getTrackSettings(constraints) {
|
|
@@ -164,7 +215,7 @@ const TwintagQRScanner = class {
|
|
|
164
215
|
return stream.getVideoTracks()[0].getSettings();
|
|
165
216
|
}
|
|
166
217
|
catch (err) {
|
|
167
|
-
|
|
218
|
+
throw new Error(err);
|
|
168
219
|
}
|
|
169
220
|
}
|
|
170
221
|
async getMedia(constraints) {
|
|
@@ -174,6 +225,19 @@ const TwintagQRScanner = class {
|
|
|
174
225
|
max: 1920,
|
|
175
226
|
};
|
|
176
227
|
try {
|
|
228
|
+
if (!isEmpty(scannerStore.get('deviceId'))) {
|
|
229
|
+
try {
|
|
230
|
+
const device_constraints = JSON.parse(JSON.stringify(constraints));
|
|
231
|
+
device_constraints.video.deviceId = {
|
|
232
|
+
exact: scannerStore.get('deviceId'),
|
|
233
|
+
};
|
|
234
|
+
await this.updateStream(device_constraints);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
catch (_) {
|
|
238
|
+
console.warn('Invalid deviceId stored in localStorage. Resetting...');
|
|
239
|
+
}
|
|
240
|
+
}
|
|
177
241
|
await this.updateStream(constraints);
|
|
178
242
|
const raw_devices = await navigator.mediaDevices.enumerateDevices();
|
|
179
243
|
const devices = raw_devices.filter((device) => device.kind.toLowerCase() === 'videoinput' &&
|
|
@@ -182,8 +246,10 @@ const TwintagQRScanner = class {
|
|
|
182
246
|
return;
|
|
183
247
|
}
|
|
184
248
|
if (devices.length === 1) {
|
|
249
|
+
const deviceId = devices[0].deviceId;
|
|
250
|
+
scannerStore.set('deviceId', deviceId);
|
|
185
251
|
constraints.video.deviceId = {
|
|
186
|
-
exact:
|
|
252
|
+
exact: deviceId,
|
|
187
253
|
};
|
|
188
254
|
await this.updateStream(constraints);
|
|
189
255
|
}
|
|
@@ -201,8 +267,10 @@ const TwintagQRScanner = class {
|
|
|
201
267
|
// back camera with the highest resolution
|
|
202
268
|
const backCamera = devices[backCameraIndex];
|
|
203
269
|
if (backCamera) {
|
|
270
|
+
const deviceId = backCamera.deviceId;
|
|
271
|
+
scannerStore.set('deviceId', deviceId);
|
|
204
272
|
constraints.video.deviceId = {
|
|
205
|
-
exact:
|
|
273
|
+
exact: deviceId,
|
|
206
274
|
};
|
|
207
275
|
await this.updateStream(constraints);
|
|
208
276
|
return;
|
|
@@ -217,10 +285,17 @@ const TwintagQRScanner = class {
|
|
|
217
285
|
}
|
|
218
286
|
}
|
|
219
287
|
catch (err) {
|
|
220
|
-
|
|
288
|
+
if (err instanceof Error) {
|
|
289
|
+
console.error(err.message);
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
console.error(err);
|
|
293
|
+
}
|
|
221
294
|
}
|
|
222
|
-
|
|
223
|
-
this.
|
|
295
|
+
finally {
|
|
296
|
+
if (this.stream) {
|
|
297
|
+
this.streamIsActive.emit(true);
|
|
298
|
+
}
|
|
224
299
|
}
|
|
225
300
|
}
|
|
226
301
|
async startStream() {
|
|
@@ -242,7 +317,8 @@ const TwintagQRScanner = class {
|
|
|
242
317
|
opacity: 1,
|
|
243
318
|
onComplete: () => {
|
|
244
319
|
const currentStage = Math.min(this.video.videoWidth, this.video.videoHeight);
|
|
245
|
-
this.stageScale =
|
|
320
|
+
this.stageScale =
|
|
321
|
+
Math.min(currentStage, MAX_STAGE_VALUE) / currentStage;
|
|
246
322
|
this.stage = currentStage * this.stageScale;
|
|
247
323
|
this.canvas.width = this.stage;
|
|
248
324
|
this.canvas.height = this.stage;
|