@stacksjs/desktop 0.2.198 → 0.2.200
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/browser.js +1 -223
- package/dist/chunk-0954hbsb.js +315 -0
- package/dist/chunk-ts9f0mxv.js +3 -0
- package/dist/index.js +78 -2256
- package/dist/test-utils.js +1 -105
- package/package.json +1 -1
- package/dist/chunk-2mx7fq49.js +0 -4
- package/dist/chunk-ys4frvmj.js +0 -3960
package/dist/test-utils.js
CHANGED
|
@@ -1,106 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"./chunk-
|
|
3
|
-
|
|
4
|
-
// src/test-utils.ts
|
|
5
|
-
ensureWindowEventTarget();
|
|
6
|
-
function ensureWindowEventTarget() {
|
|
7
|
-
if (typeof window === "undefined")
|
|
8
|
-
return;
|
|
9
|
-
const w = window;
|
|
10
|
-
if (typeof w.addEventListener === "function" && typeof w.dispatchEvent === "function")
|
|
11
|
-
return;
|
|
12
|
-
const listeners = new Map;
|
|
13
|
-
w.addEventListener = (name, cb) => {
|
|
14
|
-
let set = listeners.get(name);
|
|
15
|
-
if (!set) {
|
|
16
|
-
set = new Set;
|
|
17
|
-
listeners.set(name, set);
|
|
18
|
-
}
|
|
19
|
-
set.add(cb);
|
|
20
|
-
};
|
|
21
|
-
w.removeEventListener = (name, cb) => {
|
|
22
|
-
listeners.get(name)?.delete(cb);
|
|
23
|
-
};
|
|
24
|
-
w.dispatchEvent = (event) => {
|
|
25
|
-
const set = listeners.get(event.type);
|
|
26
|
-
if (set) {
|
|
27
|
-
for (const fn of set) {
|
|
28
|
-
try {
|
|
29
|
-
fn(event);
|
|
30
|
-
} catch {}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return true;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function installMockBridge(initialNamespaces = []) {
|
|
37
|
-
const calls = [];
|
|
38
|
-
const responses = new Map;
|
|
39
|
-
const previousRaw = window.craft;
|
|
40
|
-
const previous = previousRaw && previousRaw.__craft_bridge_loaded ? undefined : previousRaw;
|
|
41
|
-
function makeMethod(ns, method) {
|
|
42
|
-
return (...args) => {
|
|
43
|
-
calls.push({ ns, method, args });
|
|
44
|
-
const key = `${ns}:${method}`;
|
|
45
|
-
if (responses.has(key)) {
|
|
46
|
-
const r = responses.get(key);
|
|
47
|
-
const resolved = typeof r === "function" ? r(...args) : r;
|
|
48
|
-
return Promise.resolve(resolved);
|
|
49
|
-
}
|
|
50
|
-
return Promise.resolve(undefined);
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function makeNamespace(ns) {
|
|
54
|
-
return new Proxy({}, {
|
|
55
|
-
get(_target, prop) {
|
|
56
|
-
if (typeof prop !== "string")
|
|
57
|
-
return;
|
|
58
|
-
if (responses.has(`${ns}:${prop}`)) {
|
|
59
|
-
const r = responses.get(`${ns}:${prop}`);
|
|
60
|
-
if (typeof r === "function" && r.length === 0) {
|
|
61
|
-
return () => {
|
|
62
|
-
calls.push({ ns, method: prop, args: [] });
|
|
63
|
-
return r();
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return makeMethod(ns, prop);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
const root = new Proxy({}, {
|
|
72
|
-
get(_target, prop) {
|
|
73
|
-
if (typeof prop !== "string")
|
|
74
|
-
return;
|
|
75
|
-
return makeNamespace(prop);
|
|
76
|
-
},
|
|
77
|
-
has(_target, prop) {
|
|
78
|
-
if (typeof prop !== "string")
|
|
79
|
-
return false;
|
|
80
|
-
if (initialNamespaces.length === 0)
|
|
81
|
-
return true;
|
|
82
|
-
return initialNamespaces.includes(prop);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
window.craft = root;
|
|
86
|
-
return {
|
|
87
|
-
calls,
|
|
88
|
-
whenCalled(ns, method, response) {
|
|
89
|
-
responses.set(`${ns}:${method}`, response);
|
|
90
|
-
},
|
|
91
|
-
uninstall() {
|
|
92
|
-
if (previous === undefined) {
|
|
93
|
-
delete window.craft;
|
|
94
|
-
} else {
|
|
95
|
-
window.craft = previous;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
function findCall(calls, ns, method) {
|
|
101
|
-
return calls.find((c) => c.ns === ns && c.method === method);
|
|
102
|
-
}
|
|
103
|
-
export {
|
|
104
|
-
installMockBridge,
|
|
105
|
-
findCall
|
|
106
|
-
};
|
|
2
|
+
import"./chunk-ts9f0mxv.js";O();function O(){if(typeof window>"u")return;let A=window;if(typeof A.addEventListener==="function"&&typeof A.dispatchEvent==="function")return;let B=new Map;A.addEventListener=(j,q)=>{let D=B.get(j);if(!D)D=new Set,B.set(j,D);D.add(q)},A.removeEventListener=(j,q)=>{B.get(j)?.delete(q)},A.dispatchEvent=(j)=>{let q=B.get(j.type);if(q)for(let D of q)try{D(j)}catch{}return!0}}function P(A=[]){let B=[],j=new Map,q=window.craft,D=q&&q.__craft_bridge_loaded?void 0:q;function I(x,z){return(...C)=>{B.push({ns:x,method:z,args:C});let F=`${x}:${z}`;if(j.has(F)){let G=j.get(F),L=typeof G==="function"?G(...C):G;return Promise.resolve(L)}return Promise.resolve(void 0)}}function J(x){return new Proxy({},{get(z,C){if(typeof C!=="string")return;if(j.has(`${x}:${C}`)){let F=j.get(`${x}:${C}`);if(typeof F==="function"&&F.length===0)return()=>{return B.push({ns:x,method:C,args:[]}),F()}}return I(x,C)}})}let K=new Proxy({},{get(x,z){if(typeof z!=="string")return;return J(z)},has(x,z){if(typeof z!=="string")return!1;if(A.length===0)return!0;return A.includes(z)}});return window.craft=K,{calls:B,whenCalled(x,z,C){j.set(`${x}:${z}`,C)},uninstall(){if(D===void 0)delete window.craft;else window.craft=D}}}function Q(A,B,j){return A.find((q)=>q.ns===B&&q.method===j)}export{P as installMockBridge,Q as findCall};
|
package/package.json
CHANGED
package/dist/chunk-2mx7fq49.js
DELETED