@twintag/twintag-core 0.2.285-fix-scanner-stream-visibility-3ba0b17bf1aa6082f0a22c410625205beb9818fe → 0.2.285
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-6877046e.js +48 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/stencil-web-components.cjs.js +1 -1
- package/dist/cjs/twintag-offline-support.cjs.entry.js +1 -1
- package/dist/cjs/twintag-pdf-viewer.cjs.entry.js +193 -2
- package/dist/cjs/twintag-qr-scanner.cjs.entry.js +320 -182
- package/dist/collection/components/twintag-scanner/twintag-qr-scanner.js +74 -136
- package/dist/collection/version.js +1 -1
- package/dist/components/@worker-helper.js +46 -0
- package/dist/components/twintag-offline-support.js +1 -1
- package/dist/components/twintag-pdf-viewer2.js +193 -2
- package/dist/components/twintag-qr-scanner.js +324 -184
- package/dist/esm/@worker-helper-f3e880f2.js +46 -0
- package/dist/esm/{index-e1a48b05.js → index-174285a2.js} +1 -1
- package/dist/esm/loader.js +2 -2
- package/dist/esm/stencil-web-components.js +2 -2
- 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 +2 -2
- package/dist/esm/twintag-pdf-viewer.entry.js +193 -2
- package/dist/esm/twintag-preview.entry.js +1 -1
- package/dist/esm/twintag-qr-scanner.entry.js +321 -183
- package/dist/esm/twintag-share.entry.js +1 -1
- package/dist/esm/twintag-spinner.entry.js +1 -1
- package/dist/stencil-web-components/p-01d4afb8.entry.js +1 -0
- package/dist/stencil-web-components/{p-f58c7a83.entry.js → p-0be73e86.entry.js} +1 -1
- package/dist/stencil-web-components/{p-9f7518ab.entry.js → p-37b2160f.entry.js} +1 -1
- package/dist/stencil-web-components/p-44751cfd.entry.js +1 -0
- package/dist/stencil-web-components/{p-5bd6d110.entry.js → p-4a001573.entry.js} +1 -1
- package/dist/stencil-web-components/p-5e046324.js +1 -0
- package/dist/stencil-web-components/{p-1e296694.entry.js → p-67e2625e.entry.js} +1 -1
- package/dist/stencil-web-components/p-821ba724.entry.js +1 -0
- package/dist/stencil-web-components/{p-6cd7075c.entry.js → p-84e1cfed.entry.js} +1 -1
- package/dist/stencil-web-components/p-a2df3118.entry.js +1 -0
- package/dist/stencil-web-components/{p-d5d0e2ee.js → p-cb286d41.js} +1 -1
- package/dist/stencil-web-components/{p-d428ed6b.entry.js → p-dff77416.entry.js} +1 -1
- package/dist/stencil-web-components/{p-d1230452.entry.js → p-fb43176d.entry.js} +1 -1
- package/dist/stencil-web-components/{p-a6f626bb.entry.js → p-feeba1cd.entry.js} +1 -1
- package/dist/stencil-web-components/stencil-web-components.esm.js +1 -1
- package/dist/types/components/twintag-scanner/twintag-qr-scanner.d.ts +3 -5
- package/dist/types/drone/src/libs/stencil-web-components/.stencil/libs/twintag-sdk/src/lib/version.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/twintag-sdk/src/lib/version.js +1 -1
- package/dist/cjs/@worker-helper-fa4712a7.js +0 -240
- package/dist/collection/scanner-store.js +0 -4
- package/dist/collection/utils/create-local-store.js +0 -43
- package/dist/collection/utils/is-empty.js +0 -3
- package/dist/components/index3.js +0 -237
- package/dist/esm/@worker-helper-e45428b7.js +0 -237
- package/dist/stencil-web-components/p-1807206d.entry.js +0 -1
- package/dist/stencil-web-components/p-7943b86a.entry.js +0 -1
- package/dist/stencil-web-components/p-7b959006.js +0 -1
- package/dist/stencil-web-components/p-8806444b.entry.js +0 -1
- package/dist/stencil-web-components/p-a53a2c70.entry.js +0 -1
- package/dist/types/scanner-store.d.ts +0 -3
- package/dist/types/utils/create-local-store.d.ts +0 -1
- package/dist/types/utils/is-empty.d.ts +0 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const index = require('./index-2c25b2e9.js');
|
|
4
|
+
|
|
5
|
+
const pending = new Map();
|
|
6
|
+
const callbacks = new Map();
|
|
7
|
+
|
|
8
|
+
const createWorker = (workerPath, workerName, workerMsgId) => {
|
|
9
|
+
const worker = new Worker(workerPath, {name:workerName});
|
|
10
|
+
|
|
11
|
+
worker.addEventListener('message', ({data}) => {
|
|
12
|
+
if (data) {
|
|
13
|
+
const workerMsg = data[0];
|
|
14
|
+
const id = data[1];
|
|
15
|
+
const value = data[2];
|
|
16
|
+
|
|
17
|
+
if (workerMsg === workerMsgId) {
|
|
18
|
+
const err = data[3];
|
|
19
|
+
const [resolve, reject, callbackIds] = pending.get(id);
|
|
20
|
+
pending.delete(id);
|
|
21
|
+
|
|
22
|
+
if (err) {
|
|
23
|
+
const errObj = (err.isError)
|
|
24
|
+
? Object.assign(new Error(err.value.message), err.value)
|
|
25
|
+
: err.value;
|
|
26
|
+
|
|
27
|
+
index.consoleError(errObj);
|
|
28
|
+
reject(errObj);
|
|
29
|
+
} else {
|
|
30
|
+
if (callbackIds) {
|
|
31
|
+
callbackIds.forEach(id => callbacks.delete(id));
|
|
32
|
+
}
|
|
33
|
+
resolve(value);
|
|
34
|
+
}
|
|
35
|
+
} else if (workerMsg === workerMsgId + '.cb') {
|
|
36
|
+
try {
|
|
37
|
+
callbacks.get(id)(...value);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
index.consoleError(e);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return worker;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.createWorker = createWorker;
|
package/dist/cjs/loader.cjs.js
CHANGED
|
@@ -14,7 +14,7 @@ const patchEsm = () => {
|
|
|
14
14
|
const defineCustomElements = (win, options) => {
|
|
15
15
|
if (typeof window === 'undefined') return Promise.resolve();
|
|
16
16
|
return patchEsm().then(() => {
|
|
17
|
-
return index.bootstrapLazy([["twintag-preview.cjs",[[1,"twintag-preview",{"item":[1],"initial":[16],"smoothExtinction":[2,"smooth-extinction"],"extension":[1],"showButtons":[4,"show-buttons"],"previewableItem":[32],"type":[32]}]]],["twintag-auth-callback.cjs",[[1,"twintag-auth-callback"]]],["twintag-auth-logout.cjs",[[1,"twintag-auth-logout"]]],["twintag-media.cjs",[[1,"twintag-media",{"first":[1],"middle":[1],"last":[1]}]]],["twintag-ocr-scanner.cjs",[[1,"twintag-ocr-scanner",{"stream":[1040],"mode":[1],"cropX":[2,"crop-x"],"cropY":[2,"crop-y"],"devices":[32]},[[0,"updateZoom","updateZoom"],[2,"recognize","ocrHandler"]]]]],["twintag-offline-actions.cjs",[[1,"twintag-offline-actions",{"enableSingleRetry":[4,"enable-single-retry"],"header":[1],"showTimestamp":[4,"show-timestamp"],"showDescription":[4,"show-description"],"closeText":[1,"close-text"],"retryText":[1,"retry-text"],"noPendingActionsText":[1,"no-pending-actions-text"],"pendingOfflineRequests":[32],"processing":[32]},[[8,"offlineRequestsChanged","offlineRequestsChangedHandler"]]]]],["twintag-offline-state.cjs",[[1,"twintag-offline-state",{"onlineState":[32],"pendingRequests":[32]},[[8,"onlineChanged","onlineChangedHandler"],[8,"offlineRequestsChanged","offlineRequestsChangedHandler"]]]]],["twintag-offline-support.cjs",[[1,"twintag-offline-support",{"autoSync":[4,"auto-sync"],"forceOffline":[4,"force-offline"],"config":[16]}]]],["twintag-qr-scanner.cjs",[[1,"twintag-qr-scanner",{"stream":[1040],"mode":[1],"format":[1],"crop":[514]},[[
|
|
17
|
+
return index.bootstrapLazy([["twintag-preview.cjs",[[1,"twintag-preview",{"item":[1],"initial":[16],"smoothExtinction":[2,"smooth-extinction"],"extension":[1],"showButtons":[4,"show-buttons"],"previewableItem":[32],"type":[32]}]]],["twintag-auth-callback.cjs",[[1,"twintag-auth-callback"]]],["twintag-auth-logout.cjs",[[1,"twintag-auth-logout"]]],["twintag-media.cjs",[[1,"twintag-media",{"first":[1],"middle":[1],"last":[1]}]]],["twintag-ocr-scanner.cjs",[[1,"twintag-ocr-scanner",{"stream":[1040],"mode":[1],"cropX":[2,"crop-x"],"cropY":[2,"crop-y"],"devices":[32]},[[0,"updateZoom","updateZoom"],[2,"recognize","ocrHandler"]]]]],["twintag-offline-actions.cjs",[[1,"twintag-offline-actions",{"enableSingleRetry":[4,"enable-single-retry"],"header":[1],"showTimestamp":[4,"show-timestamp"],"showDescription":[4,"show-description"],"closeText":[1,"close-text"],"retryText":[1,"retry-text"],"noPendingActionsText":[1,"no-pending-actions-text"],"pendingOfflineRequests":[32],"processing":[32]},[[8,"offlineRequestsChanged","offlineRequestsChangedHandler"]]]]],["twintag-offline-state.cjs",[[1,"twintag-offline-state",{"onlineState":[32],"pendingRequests":[32]},[[8,"onlineChanged","onlineChangedHandler"],[8,"offlineRequestsChanged","offlineRequestsChangedHandler"]]]]],["twintag-offline-support.cjs",[[1,"twintag-offline-support",{"autoSync":[4,"auto-sync"],"forceOffline":[4,"force-offline"],"config":[16]}]]],["twintag-qr-scanner.cjs",[[1,"twintag-qr-scanner",{"stream":[1040],"mode":[1],"format":[1],"crop":[514],"devices":[32],"decoderIsBusy":[32]},[[0,"updateZoom","updateZoom"]]]]],["twintag-share.cjs",[[1,"twintag-share",{"url":[1],"modalTitle":[1,"modal-title"],"modalSubtitle":[1,"modal-subtitle"],"closeBtn":[1,"close-btn"],"copyClipboardBtn":[1,"copy-clipboard-btn"],"open":[1540]},[[0,"keydown","handleKeyDown"]]]]],["twintag-spinner.cjs",[[1,"twintag-spinner",{"color":[513],"duration":[2],"name":[1]}]]],["twintag-pdf-viewer.cjs",[[0,"twintag-pdf-viewer",{"src":[1],"fileName":[1,"file-name"],"file":[32],"fileURL":[32]}]]]], options);
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
20
|
|
|
@@ -15,5 +15,5 @@ const patchBrowser = () => {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
patchBrowser().then(options => {
|
|
18
|
-
return index.bootstrapLazy([["twintag-preview.cjs",[[1,"twintag-preview",{"item":[1],"initial":[16],"smoothExtinction":[2,"smooth-extinction"],"extension":[1],"showButtons":[4,"show-buttons"],"previewableItem":[32],"type":[32]}]]],["twintag-auth-callback.cjs",[[1,"twintag-auth-callback"]]],["twintag-auth-logout.cjs",[[1,"twintag-auth-logout"]]],["twintag-media.cjs",[[1,"twintag-media",{"first":[1],"middle":[1],"last":[1]}]]],["twintag-ocr-scanner.cjs",[[1,"twintag-ocr-scanner",{"stream":[1040],"mode":[1],"cropX":[2,"crop-x"],"cropY":[2,"crop-y"],"devices":[32]},[[0,"updateZoom","updateZoom"],[2,"recognize","ocrHandler"]]]]],["twintag-offline-actions.cjs",[[1,"twintag-offline-actions",{"enableSingleRetry":[4,"enable-single-retry"],"header":[1],"showTimestamp":[4,"show-timestamp"],"showDescription":[4,"show-description"],"closeText":[1,"close-text"],"retryText":[1,"retry-text"],"noPendingActionsText":[1,"no-pending-actions-text"],"pendingOfflineRequests":[32],"processing":[32]},[[8,"offlineRequestsChanged","offlineRequestsChangedHandler"]]]]],["twintag-offline-state.cjs",[[1,"twintag-offline-state",{"onlineState":[32],"pendingRequests":[32]},[[8,"onlineChanged","onlineChangedHandler"],[8,"offlineRequestsChanged","offlineRequestsChangedHandler"]]]]],["twintag-offline-support.cjs",[[1,"twintag-offline-support",{"autoSync":[4,"auto-sync"],"forceOffline":[4,"force-offline"],"config":[16]}]]],["twintag-qr-scanner.cjs",[[1,"twintag-qr-scanner",{"stream":[1040],"mode":[1],"format":[1],"crop":[514]},[[
|
|
18
|
+
return index.bootstrapLazy([["twintag-preview.cjs",[[1,"twintag-preview",{"item":[1],"initial":[16],"smoothExtinction":[2,"smooth-extinction"],"extension":[1],"showButtons":[4,"show-buttons"],"previewableItem":[32],"type":[32]}]]],["twintag-auth-callback.cjs",[[1,"twintag-auth-callback"]]],["twintag-auth-logout.cjs",[[1,"twintag-auth-logout"]]],["twintag-media.cjs",[[1,"twintag-media",{"first":[1],"middle":[1],"last":[1]}]]],["twintag-ocr-scanner.cjs",[[1,"twintag-ocr-scanner",{"stream":[1040],"mode":[1],"cropX":[2,"crop-x"],"cropY":[2,"crop-y"],"devices":[32]},[[0,"updateZoom","updateZoom"],[2,"recognize","ocrHandler"]]]]],["twintag-offline-actions.cjs",[[1,"twintag-offline-actions",{"enableSingleRetry":[4,"enable-single-retry"],"header":[1],"showTimestamp":[4,"show-timestamp"],"showDescription":[4,"show-description"],"closeText":[1,"close-text"],"retryText":[1,"retry-text"],"noPendingActionsText":[1,"no-pending-actions-text"],"pendingOfflineRequests":[32],"processing":[32]},[[8,"offlineRequestsChanged","offlineRequestsChangedHandler"]]]]],["twintag-offline-state.cjs",[[1,"twintag-offline-state",{"onlineState":[32],"pendingRequests":[32]},[[8,"onlineChanged","onlineChangedHandler"],[8,"offlineRequestsChanged","offlineRequestsChangedHandler"]]]]],["twintag-offline-support.cjs",[[1,"twintag-offline-support",{"autoSync":[4,"auto-sync"],"forceOffline":[4,"force-offline"],"config":[16]}]]],["twintag-qr-scanner.cjs",[[1,"twintag-qr-scanner",{"stream":[1040],"mode":[1],"format":[1],"crop":[514],"devices":[32],"decoderIsBusy":[32]},[[0,"updateZoom","updateZoom"]]]]],["twintag-share.cjs",[[1,"twintag-share",{"url":[1],"modalTitle":[1,"modal-title"],"modalSubtitle":[1,"modal-subtitle"],"closeBtn":[1,"close-btn"],"copyClipboardBtn":[1,"copy-clipboard-btn"],"open":[1540]},[[0,"keydown","handleKeyDown"]]]]],["twintag-spinner.cjs",[[1,"twintag-spinner",{"color":[513],"duration":[2],"name":[1]}]]],["twintag-pdf-viewer.cjs",[[0,"twintag-pdf-viewer",{"src":[1],"fileName":[1,"file-name"],"file":[32],"fileURL":[32]}]]]], options);
|
|
19
19
|
});
|
|
@@ -3,14 +3,205 @@
|
|
|
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-6877046e.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
|
|
13
|
+
const appendToMap = (map, propName, value) => {
|
|
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({
|
|
14
205
|
docs: new Map(),
|
|
15
206
|
});
|
|
16
207
|
|