@trimjs/web-app 0.2.0 → 0.2.2
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/index.cjs +1 -3
- package/dist/index.iife.js +1 -3
- package/dist/index.js +1 -1051
- package/dist/index.umd.cjs +1 -3
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -1,1051 +1 @@
|
|
|
1
|
-
var Ae = Object.defineProperty, Se = Object.defineProperties;
|
|
2
|
-
var $e = Object.getOwnPropertyDescriptors;
|
|
3
|
-
var Z = Object.getOwnPropertySymbols;
|
|
4
|
-
var Pe = Object.prototype.hasOwnProperty, Me = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var B = (r, e, t) => e in r ? Ae(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, I = (r, e) => {
|
|
6
|
-
for (var t in e || (e = {}))
|
|
7
|
-
Pe.call(e, t) && B(r, t, e[t]);
|
|
8
|
-
if (Z)
|
|
9
|
-
for (var t of Z(e))
|
|
10
|
-
Me.call(e, t) && B(r, t, e[t]);
|
|
11
|
-
return r;
|
|
12
|
-
}, W = (r, e) => Se(r, $e(e));
|
|
13
|
-
var $ = (r, e, t) => B(r, typeof e != "symbol" ? e + "" : e, t);
|
|
14
|
-
var w = (r, e, t) => new Promise((n, i) => {
|
|
15
|
-
var o = (a) => {
|
|
16
|
-
try {
|
|
17
|
-
c(t.next(a));
|
|
18
|
-
} catch (h) {
|
|
19
|
-
i(h);
|
|
20
|
-
}
|
|
21
|
-
}, s = (a) => {
|
|
22
|
-
try {
|
|
23
|
-
c(t.throw(a));
|
|
24
|
-
} catch (h) {
|
|
25
|
-
i(h);
|
|
26
|
-
}
|
|
27
|
-
}, c = (a) => a.done ? n(a.value) : Promise.resolve(a.value).then(o, s);
|
|
28
|
-
c((t = t.apply(r, e)).next());
|
|
29
|
-
});
|
|
30
|
-
class Oe {
|
|
31
|
-
constructor() {
|
|
32
|
-
$(this, "debug", !1);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* 设置 debug 模式
|
|
36
|
-
* @param enabled 是否启用 debug
|
|
37
|
-
*/
|
|
38
|
-
setDebug(e) {
|
|
39
|
-
this.debug = e;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* 获取当前 debug 状态
|
|
43
|
-
*/
|
|
44
|
-
isDebug() {
|
|
45
|
-
return this.debug;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* 输出日志(只在 debug 模式下)
|
|
49
|
-
* @param args 日志参数
|
|
50
|
-
*/
|
|
51
|
-
log() {
|
|
52
|
-
if (this.debug) {
|
|
53
|
-
for (var e = arguments.length, t = new Array(e), n = 0; n < e; n++)
|
|
54
|
-
t[n] = arguments[n];
|
|
55
|
-
console.log("[Trim App]", ...t);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* 输出警告日志(只在 debug 模式下)
|
|
60
|
-
* @param args 日志参数
|
|
61
|
-
*/
|
|
62
|
-
warn() {
|
|
63
|
-
if (this.debug) {
|
|
64
|
-
for (var e = arguments.length, t = new Array(e), n = 0; n < e; n++)
|
|
65
|
-
t[n] = arguments[n];
|
|
66
|
-
console.warn("[Trim App]", ...t);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* 输出错误日志(只在 debug 模式下)
|
|
71
|
-
* @param args 日志参数
|
|
72
|
-
*/
|
|
73
|
-
error() {
|
|
74
|
-
if (this.debug) {
|
|
75
|
-
for (var e = arguments.length, t = new Array(e), n = 0; n < e; n++)
|
|
76
|
-
t[n] = arguments[n];
|
|
77
|
-
console.error("[Trim App]", ...t);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* 输出信息日志(只在 debug 模式下)
|
|
82
|
-
* @param args 日志参数
|
|
83
|
-
*/
|
|
84
|
-
info() {
|
|
85
|
-
if (this.debug) {
|
|
86
|
-
for (var e = arguments.length, t = new Array(e), n = 0; n < e; n++)
|
|
87
|
-
t[n] = arguments[n];
|
|
88
|
-
console.info("[Trim App]", ...t);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
const d = new Oe();
|
|
93
|
-
function Ce(r) {
|
|
94
|
-
const e = /FNOS\/([\d.]+)|FNAppType\/(\w+)|FNAppVer\/([\d.]+)/g, t = {};
|
|
95
|
-
let n;
|
|
96
|
-
for (; (n = e.exec(r)) !== null; )
|
|
97
|
-
n[1] && (t.fnOSVersion = n[1]), n[2] && (t.fnAppType = n[2]), n[3] && (t.fnAppVersion = n[3]);
|
|
98
|
-
return t;
|
|
99
|
-
}
|
|
100
|
-
const fe = () => Ce(navigator.userAgent).fnAppVersion;
|
|
101
|
-
let pe = !1;
|
|
102
|
-
window.addEventListener("flutterInAppWebViewPlatformReady", () => {
|
|
103
|
-
pe = !0;
|
|
104
|
-
});
|
|
105
|
-
const _e = () => new Promise((r) => {
|
|
106
|
-
var e;
|
|
107
|
-
pe || (e = window.flutter_inappwebview) != null && e._platformReady ? (d.log("flutter_inappwebview is ready"), r(window.flutter_inappwebview)) : window.addEventListener("flutterInAppWebViewPlatformReady", () => {
|
|
108
|
-
d.log("flutter_inappwebview is ready"), r(window.flutter_inappwebview);
|
|
109
|
-
});
|
|
110
|
-
}), Te = (r, e, t) => w(null, null, function* () {
|
|
111
|
-
d.log(`callHandler: ${e}, params: ${t}`);
|
|
112
|
-
const n = yield r.callHandler(e, t);
|
|
113
|
-
if (n)
|
|
114
|
-
try {
|
|
115
|
-
const i = JSON.parse(n);
|
|
116
|
-
d.log(`messageData: ${JSON.stringify(i)}`);
|
|
117
|
-
const o = JSON.parse(i.result);
|
|
118
|
-
return d.log(`appMessage: ${JSON.stringify(o)}`), o;
|
|
119
|
-
} catch (i) {
|
|
120
|
-
return d.error(`error: ${i}`), null;
|
|
121
|
-
}
|
|
122
|
-
return null;
|
|
123
|
-
}), ee = /* @__PURE__ */ new Map();
|
|
124
|
-
function Fe() {
|
|
125
|
-
window.fnAppMessage = (r) => {
|
|
126
|
-
d.log("app-message", r);
|
|
127
|
-
const e = JSON.parse(r), t = ee.get(e.reqId);
|
|
128
|
-
t && (t(e), ee.delete(e.reqId));
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
fe() && Fe();
|
|
132
|
-
var F = /* @__PURE__ */ ((r) => (r.Call = "call", r.Reply = "reply", r.Syn = "syn", r.SynAck = "synAck", r.Ack = "ack", r))(F || {}), D = /* @__PURE__ */ ((r) => (r.Fulfilled = "fulfilled", r.Rejected = "rejected", r))(D || {}), G = /* @__PURE__ */ ((r) => (r.ConnectionDestroyed = "ConnectionDestroyed", r.ConnectionTimeout = "ConnectionTimeout", r.NoIframeSrc = "NoIframeSrc", r))(G || {}), de = /* @__PURE__ */ ((r) => (r.DataCloneError = "DataCloneError", r))(de || {}), N = /* @__PURE__ */ ((r) => (r.Message = "message", r))(N || {});
|
|
133
|
-
const Re = (r, e) => {
|
|
134
|
-
const t = [];
|
|
135
|
-
let n = !1;
|
|
136
|
-
return {
|
|
137
|
-
destroy(i) {
|
|
138
|
-
n || (n = !0, e(`${r}: Destroying connection`), t.forEach((o) => {
|
|
139
|
-
o(i);
|
|
140
|
-
}));
|
|
141
|
-
},
|
|
142
|
-
onDestroy(i) {
|
|
143
|
-
n ? i() : t.push(i);
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
}, xe = (r) => (...e) => {
|
|
147
|
-
r && console.log("[Penpal]", ...e);
|
|
148
|
-
}, te = ({
|
|
149
|
-
name: r,
|
|
150
|
-
message: e,
|
|
151
|
-
stack: t
|
|
152
|
-
}) => ({
|
|
153
|
-
name: r,
|
|
154
|
-
message: e,
|
|
155
|
-
stack: t
|
|
156
|
-
}), Ie = (r) => {
|
|
157
|
-
const e = new Error();
|
|
158
|
-
return Object.keys(r).forEach((t) => e[t] = r[t]), e;
|
|
159
|
-
}, Ne = (r, e, t) => {
|
|
160
|
-
const {
|
|
161
|
-
localName: n,
|
|
162
|
-
local: i,
|
|
163
|
-
remote: o,
|
|
164
|
-
originForSending: s,
|
|
165
|
-
originForReceiving: c
|
|
166
|
-
} = r;
|
|
167
|
-
let a = !1;
|
|
168
|
-
const h = (v) => {
|
|
169
|
-
if (v.source !== o || v.data.penpal !== F.Call)
|
|
170
|
-
return;
|
|
171
|
-
if (c !== "*" && v.origin !== c) {
|
|
172
|
-
t(
|
|
173
|
-
`${n} received message from origin ${v.origin} which did not match expected origin ${c}`
|
|
174
|
-
);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
const A = v.data, { methodName: g, args: p, id: m } = A;
|
|
178
|
-
t(`${n}: Received ${g}() call`);
|
|
179
|
-
const l = (y) => (S) => {
|
|
180
|
-
if (t(`${n}: Sending ${g}() reply`), a) {
|
|
181
|
-
t(
|
|
182
|
-
`${n}: Unable to send ${g}() reply due to destroyed connection`
|
|
183
|
-
);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
const P = {
|
|
187
|
-
penpal: F.Reply,
|
|
188
|
-
id: m,
|
|
189
|
-
resolution: y,
|
|
190
|
-
returnValue: S
|
|
191
|
-
};
|
|
192
|
-
y === D.Rejected && S instanceof Error && (P.returnValue = te(S), P.returnValueIsError = !0);
|
|
193
|
-
try {
|
|
194
|
-
o.postMessage(P, s);
|
|
195
|
-
} catch (M) {
|
|
196
|
-
if (M.name === de.DataCloneError) {
|
|
197
|
-
const O = {
|
|
198
|
-
penpal: F.Reply,
|
|
199
|
-
id: m,
|
|
200
|
-
resolution: D.Rejected,
|
|
201
|
-
returnValue: te(M),
|
|
202
|
-
returnValueIsError: !0
|
|
203
|
-
};
|
|
204
|
-
o.postMessage(O, s);
|
|
205
|
-
}
|
|
206
|
-
throw M;
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
new Promise(
|
|
210
|
-
(y) => y(e[g].apply(e, p))
|
|
211
|
-
).then(
|
|
212
|
-
l(D.Fulfilled),
|
|
213
|
-
l(D.Rejected)
|
|
214
|
-
);
|
|
215
|
-
};
|
|
216
|
-
return i.addEventListener(N.Message, h), () => {
|
|
217
|
-
a = !0, i.removeEventListener(N.Message, h);
|
|
218
|
-
};
|
|
219
|
-
};
|
|
220
|
-
let Ve = 0;
|
|
221
|
-
const We = () => ++Ve, he = ".", ge = (r) => r ? r.split(he) : [], qe = (r) => r.join(he), De = (r, e) => {
|
|
222
|
-
const t = ge(e || "");
|
|
223
|
-
return t.push(r), qe(t);
|
|
224
|
-
}, Le = (r, e, t) => {
|
|
225
|
-
const n = ge(e);
|
|
226
|
-
return n.reduce((i, o, s) => (typeof i[o] == "undefined" && (i[o] = {}), s === n.length - 1 && (i[o] = t), i[o]), r), r;
|
|
227
|
-
}, ye = (r, e) => {
|
|
228
|
-
const t = {};
|
|
229
|
-
return Object.keys(r).forEach((n) => {
|
|
230
|
-
const i = r[n], o = De(n, e);
|
|
231
|
-
typeof i == "object" && Object.assign(t, ye(i, o)), typeof i == "function" && (t[o] = i);
|
|
232
|
-
}), t;
|
|
233
|
-
}, je = (r) => {
|
|
234
|
-
const e = {};
|
|
235
|
-
for (const t in r)
|
|
236
|
-
Le(e, t, r[t]);
|
|
237
|
-
return e;
|
|
238
|
-
}, He = (r, e, t, n, i) => {
|
|
239
|
-
const {
|
|
240
|
-
localName: o,
|
|
241
|
-
local: s,
|
|
242
|
-
remote: c,
|
|
243
|
-
originForSending: a,
|
|
244
|
-
originForReceiving: h
|
|
245
|
-
} = e;
|
|
246
|
-
let v = !1;
|
|
247
|
-
i(`${o}: Connecting call sender`);
|
|
248
|
-
const A = (p) => (...m) => {
|
|
249
|
-
i(`${o}: Sending ${p}() call`);
|
|
250
|
-
let l;
|
|
251
|
-
try {
|
|
252
|
-
c.closed && (l = !0);
|
|
253
|
-
} catch (y) {
|
|
254
|
-
l = !0;
|
|
255
|
-
}
|
|
256
|
-
if (l && n(), v) {
|
|
257
|
-
const y = new Error(
|
|
258
|
-
`Unable to send ${p}() call due to destroyed connection`
|
|
259
|
-
);
|
|
260
|
-
throw y.code = G.ConnectionDestroyed, y;
|
|
261
|
-
}
|
|
262
|
-
return new Promise((y, S) => {
|
|
263
|
-
const P = We(), M = (C) => {
|
|
264
|
-
if (C.source !== c || C.data.penpal !== F.Reply || C.data.id !== P)
|
|
265
|
-
return;
|
|
266
|
-
if (h !== "*" && C.origin !== h) {
|
|
267
|
-
i(
|
|
268
|
-
`${o} received message from origin ${C.origin} which did not match expected origin ${h}`
|
|
269
|
-
);
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
const L = C.data;
|
|
273
|
-
i(`${o}: Received ${p}() reply`), s.removeEventListener(
|
|
274
|
-
N.Message,
|
|
275
|
-
M
|
|
276
|
-
);
|
|
277
|
-
let j = L.returnValue;
|
|
278
|
-
L.returnValueIsError && (j = Ie(j)), (L.resolution === D.Fulfilled ? y : S)(
|
|
279
|
-
j
|
|
280
|
-
);
|
|
281
|
-
};
|
|
282
|
-
s.addEventListener(N.Message, M);
|
|
283
|
-
const O = {
|
|
284
|
-
penpal: F.Call,
|
|
285
|
-
id: P,
|
|
286
|
-
methodName: p,
|
|
287
|
-
args: m
|
|
288
|
-
};
|
|
289
|
-
c.postMessage(O, a);
|
|
290
|
-
});
|
|
291
|
-
}, g = t.reduce((p, m) => (p[m] = A(m), p), {});
|
|
292
|
-
return Object.assign(r, je(g)), () => {
|
|
293
|
-
v = !0;
|
|
294
|
-
};
|
|
295
|
-
}, ke = (r, e) => {
|
|
296
|
-
let t;
|
|
297
|
-
return r !== void 0 && (t = window.setTimeout(() => {
|
|
298
|
-
const n = new Error(
|
|
299
|
-
`Connection timed out after ${r}ms`
|
|
300
|
-
);
|
|
301
|
-
n.code = G.ConnectionTimeout, e(n);
|
|
302
|
-
}, r)), () => {
|
|
303
|
-
clearTimeout(t);
|
|
304
|
-
};
|
|
305
|
-
}, Ue = "0.1.2", Be = {
|
|
306
|
-
version: Ue
|
|
307
|
-
}, Je = (r, e, t, n, i) => {
|
|
308
|
-
const { destroy: o, onDestroy: s } = n;
|
|
309
|
-
return (c) => {
|
|
310
|
-
if (!(r instanceof RegExp ? r.test(c.origin) : r === "*" || r === c.origin)) {
|
|
311
|
-
i(
|
|
312
|
-
`Child: Handshake - Received SYN-ACK from origin ${c.origin} which did not match expected origin ${r}`
|
|
313
|
-
);
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
i("Child: Handshake - Received SYN-ACK, responding with ACK");
|
|
317
|
-
const h = c.origin === "null" ? "*" : c.origin, v = {
|
|
318
|
-
penpal: F.Ack,
|
|
319
|
-
methodNames: Object.keys(e),
|
|
320
|
-
config: t
|
|
321
|
-
};
|
|
322
|
-
window.parent.postMessage(v, h);
|
|
323
|
-
const A = {
|
|
324
|
-
localName: "Child",
|
|
325
|
-
local: window,
|
|
326
|
-
remote: window.parent,
|
|
327
|
-
originForSending: h,
|
|
328
|
-
originForReceiving: c.origin
|
|
329
|
-
}, g = Ne(
|
|
330
|
-
A,
|
|
331
|
-
e,
|
|
332
|
-
i
|
|
333
|
-
);
|
|
334
|
-
s(g);
|
|
335
|
-
const p = {}, m = He(
|
|
336
|
-
p,
|
|
337
|
-
A,
|
|
338
|
-
c.data.methodNames,
|
|
339
|
-
o,
|
|
340
|
-
i
|
|
341
|
-
);
|
|
342
|
-
return s(m), p;
|
|
343
|
-
};
|
|
344
|
-
};
|
|
345
|
-
function re(r, e) {
|
|
346
|
-
console == null || console.warn(`[fnApp warn]: ${r}`, e);
|
|
347
|
-
}
|
|
348
|
-
function ne(r, e) {
|
|
349
|
-
console == null || console.error(`[fnApp error]: ${r}`, e);
|
|
350
|
-
}
|
|
351
|
-
const q = "_fn_all_event", ie = "事件订阅数量为空", H = window.__POWERED_BY_FNAPP__ ? window.__FNAPP.inject.appEventObjMap : /* @__PURE__ */ new Map();
|
|
352
|
-
class oe {
|
|
353
|
-
constructor(e, t) {
|
|
354
|
-
$(this, "id");
|
|
355
|
-
$(this, "appName");
|
|
356
|
-
$(this, "eventObj");
|
|
357
|
-
$(this, "getEventCallBackLength", (e) => {
|
|
358
|
-
var t;
|
|
359
|
-
return ((t = this.eventObj[e]) == null ? void 0 : t.length) || 0;
|
|
360
|
-
});
|
|
361
|
-
this.id = e, this.appName = t, this.$clear(), H.get(this.id) || H.set(this.id, {}), this.eventObj = H.get(this.id);
|
|
362
|
-
}
|
|
363
|
-
// 监听事件
|
|
364
|
-
$on(e, t) {
|
|
365
|
-
const n = this.eventObj[e];
|
|
366
|
-
return n ? (n.includes(t) || n.push(t), this) : (this.eventObj[e] = [t], this);
|
|
367
|
-
}
|
|
368
|
-
/** 任何$emit都会导致监听函数触发,第一个参数为事件名,后续的参数为$emit的参数 */
|
|
369
|
-
$onAll(e) {
|
|
370
|
-
return this.$on(q, e);
|
|
371
|
-
}
|
|
372
|
-
// 一次性监听事件
|
|
373
|
-
$once(e, t) {
|
|
374
|
-
t.$__once = !0, this.$on(e, t);
|
|
375
|
-
}
|
|
376
|
-
// 取消监听
|
|
377
|
-
$off(e, t) {
|
|
378
|
-
const n = this.eventObj[e];
|
|
379
|
-
if (!e || !n || !n.length)
|
|
380
|
-
return re(`${e} ${ie}`), this;
|
|
381
|
-
let i, o = n.length;
|
|
382
|
-
for (; o--; )
|
|
383
|
-
if (i = n[o], i === t) {
|
|
384
|
-
n.splice(o, 1);
|
|
385
|
-
break;
|
|
386
|
-
}
|
|
387
|
-
return this;
|
|
388
|
-
}
|
|
389
|
-
// 取消监听$onAll
|
|
390
|
-
$offAll(e) {
|
|
391
|
-
return this.$off(q, e);
|
|
392
|
-
}
|
|
393
|
-
// 发送事件
|
|
394
|
-
$emit(e, ...t) {
|
|
395
|
-
return e = `${this.appName}/${e}`, this.$pureEmit(e, ...t);
|
|
396
|
-
}
|
|
397
|
-
// 发送事件
|
|
398
|
-
$pureEmit(e, ...t) {
|
|
399
|
-
let n = 0, i = 0;
|
|
400
|
-
return H.forEach((o) => {
|
|
401
|
-
if (o[e])
|
|
402
|
-
for (let s = o[e].length - 1; s >= 0; s--) {
|
|
403
|
-
n++;
|
|
404
|
-
const c = o[e][s];
|
|
405
|
-
c.$__once && o[e].splice(s, 1);
|
|
406
|
-
try {
|
|
407
|
-
c(...t);
|
|
408
|
-
} catch (a) {
|
|
409
|
-
ne(a);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
if (o[q])
|
|
413
|
-
for (let s = o[q].length - 1; s >= 0; s--) {
|
|
414
|
-
n++;
|
|
415
|
-
const c = o[q][s];
|
|
416
|
-
c.$__once && o[q].splice(s, 1);
|
|
417
|
-
try {
|
|
418
|
-
c(...t);
|
|
419
|
-
} catch (a) {
|
|
420
|
-
ne(a);
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}), (!e || n === 0 && i === 0) && re(`${e} ${ie}`), this;
|
|
424
|
-
}
|
|
425
|
-
// 清空当前所有的监听事件
|
|
426
|
-
$clear() {
|
|
427
|
-
const e = H.get(this.id) || {};
|
|
428
|
-
return Object.keys(e).forEach((n) => delete e[n]), this;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
var Y = function(r, e) {
|
|
432
|
-
return Y = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, n) {
|
|
433
|
-
t.__proto__ = n;
|
|
434
|
-
} || function(t, n) {
|
|
435
|
-
for (var i in n) Object.prototype.hasOwnProperty.call(n, i) && (t[i] = n[i]);
|
|
436
|
-
}, Y(r, e);
|
|
437
|
-
};
|
|
438
|
-
function me(r, e) {
|
|
439
|
-
if (typeof e != "function" && e !== null)
|
|
440
|
-
throw new TypeError("Class extends value " + String(e) + " is not a constructor or null");
|
|
441
|
-
Y(r, e);
|
|
442
|
-
function t() {
|
|
443
|
-
this.constructor = r;
|
|
444
|
-
}
|
|
445
|
-
r.prototype = e === null ? Object.create(e) : (t.prototype = e.prototype, new t());
|
|
446
|
-
}
|
|
447
|
-
function se(r) {
|
|
448
|
-
var e = typeof Symbol == "function" && Symbol.iterator, t = e && r[e], n = 0;
|
|
449
|
-
if (t) return t.call(r);
|
|
450
|
-
if (r && typeof r.length == "number") return {
|
|
451
|
-
next: function() {
|
|
452
|
-
return r && n >= r.length && (r = void 0), { value: r && r[n++], done: !r };
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
throw new TypeError(e ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
456
|
-
}
|
|
457
|
-
function z(r, e) {
|
|
458
|
-
var t = typeof Symbol == "function" && r[Symbol.iterator];
|
|
459
|
-
if (!t) return r;
|
|
460
|
-
var n = t.call(r), i, o = [], s;
|
|
461
|
-
try {
|
|
462
|
-
for (; (e === void 0 || e-- > 0) && !(i = n.next()).done; ) o.push(i.value);
|
|
463
|
-
} catch (c) {
|
|
464
|
-
s = { error: c };
|
|
465
|
-
} finally {
|
|
466
|
-
try {
|
|
467
|
-
i && !i.done && (t = n.return) && t.call(n);
|
|
468
|
-
} finally {
|
|
469
|
-
if (s) throw s.error;
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
return o;
|
|
473
|
-
}
|
|
474
|
-
function K(r, e, t) {
|
|
475
|
-
if (t || arguments.length === 2) for (var n = 0, i = e.length, o; n < i; n++)
|
|
476
|
-
(o || !(n in e)) && (o || (o = Array.prototype.slice.call(e, 0, n)), o[n] = e[n]);
|
|
477
|
-
return r.concat(o || Array.prototype.slice.call(e));
|
|
478
|
-
}
|
|
479
|
-
function R(r) {
|
|
480
|
-
return typeof r == "function";
|
|
481
|
-
}
|
|
482
|
-
function Ye(r) {
|
|
483
|
-
var e = function(n) {
|
|
484
|
-
Error.call(n), n.stack = new Error().stack;
|
|
485
|
-
}, t = r(e);
|
|
486
|
-
return t.prototype = Object.create(Error.prototype), t.prototype.constructor = t, t;
|
|
487
|
-
}
|
|
488
|
-
var J = Ye(function(r) {
|
|
489
|
-
return function(t) {
|
|
490
|
-
r(this), this.message = t ? t.length + ` errors occurred during unsubscription:
|
|
491
|
-
` + t.map(function(n, i) {
|
|
492
|
-
return i + 1 + ") " + n.toString();
|
|
493
|
-
}).join(`
|
|
494
|
-
`) : "", this.name = "UnsubscriptionError", this.errors = t;
|
|
495
|
-
};
|
|
496
|
-
});
|
|
497
|
-
function ce(r, e) {
|
|
498
|
-
if (r) {
|
|
499
|
-
var t = r.indexOf(e);
|
|
500
|
-
0 <= t && r.splice(t, 1);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
var X = (function() {
|
|
504
|
-
function r(e) {
|
|
505
|
-
this.initialTeardown = e, this.closed = !1, this._parentage = null, this._finalizers = null;
|
|
506
|
-
}
|
|
507
|
-
return r.prototype.unsubscribe = function() {
|
|
508
|
-
var e, t, n, i, o;
|
|
509
|
-
if (!this.closed) {
|
|
510
|
-
this.closed = !0;
|
|
511
|
-
var s = this._parentage;
|
|
512
|
-
if (s)
|
|
513
|
-
if (this._parentage = null, Array.isArray(s))
|
|
514
|
-
try {
|
|
515
|
-
for (var c = se(s), a = c.next(); !a.done; a = c.next()) {
|
|
516
|
-
var h = a.value;
|
|
517
|
-
h.remove(this);
|
|
518
|
-
}
|
|
519
|
-
} catch (l) {
|
|
520
|
-
e = { error: l };
|
|
521
|
-
} finally {
|
|
522
|
-
try {
|
|
523
|
-
a && !a.done && (t = c.return) && t.call(c);
|
|
524
|
-
} finally {
|
|
525
|
-
if (e) throw e.error;
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
else
|
|
529
|
-
s.remove(this);
|
|
530
|
-
var v = this.initialTeardown;
|
|
531
|
-
if (R(v))
|
|
532
|
-
try {
|
|
533
|
-
v();
|
|
534
|
-
} catch (l) {
|
|
535
|
-
o = l instanceof J ? l.errors : [l];
|
|
536
|
-
}
|
|
537
|
-
var A = this._finalizers;
|
|
538
|
-
if (A) {
|
|
539
|
-
this._finalizers = null;
|
|
540
|
-
try {
|
|
541
|
-
for (var g = se(A), p = g.next(); !p.done; p = g.next()) {
|
|
542
|
-
var m = p.value;
|
|
543
|
-
try {
|
|
544
|
-
ae(m);
|
|
545
|
-
} catch (l) {
|
|
546
|
-
o = o != null ? o : [], l instanceof J ? o = K(K([], z(o)), z(l.errors)) : o.push(l);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
} catch (l) {
|
|
550
|
-
n = { error: l };
|
|
551
|
-
} finally {
|
|
552
|
-
try {
|
|
553
|
-
p && !p.done && (i = g.return) && i.call(g);
|
|
554
|
-
} finally {
|
|
555
|
-
if (n) throw n.error;
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
if (o)
|
|
560
|
-
throw new J(o);
|
|
561
|
-
}
|
|
562
|
-
}, r.prototype.add = function(e) {
|
|
563
|
-
var t;
|
|
564
|
-
if (e && e !== this)
|
|
565
|
-
if (this.closed)
|
|
566
|
-
ae(e);
|
|
567
|
-
else {
|
|
568
|
-
if (e instanceof r) {
|
|
569
|
-
if (e.closed || e._hasParent(this))
|
|
570
|
-
return;
|
|
571
|
-
e._addParent(this);
|
|
572
|
-
}
|
|
573
|
-
(this._finalizers = (t = this._finalizers) !== null && t !== void 0 ? t : []).push(e);
|
|
574
|
-
}
|
|
575
|
-
}, r.prototype._hasParent = function(e) {
|
|
576
|
-
var t = this._parentage;
|
|
577
|
-
return t === e || Array.isArray(t) && t.includes(e);
|
|
578
|
-
}, r.prototype._addParent = function(e) {
|
|
579
|
-
var t = this._parentage;
|
|
580
|
-
this._parentage = Array.isArray(t) ? (t.push(e), t) : t ? [t, e] : e;
|
|
581
|
-
}, r.prototype._removeParent = function(e) {
|
|
582
|
-
var t = this._parentage;
|
|
583
|
-
t === e ? this._parentage = null : Array.isArray(t) && ce(t, e);
|
|
584
|
-
}, r.prototype.remove = function(e) {
|
|
585
|
-
var t = this._finalizers;
|
|
586
|
-
t && ce(t, e), e instanceof r && e._removeParent(this);
|
|
587
|
-
}, r.EMPTY = (function() {
|
|
588
|
-
var e = new r();
|
|
589
|
-
return e.closed = !0, e;
|
|
590
|
-
})(), r;
|
|
591
|
-
})();
|
|
592
|
-
X.EMPTY;
|
|
593
|
-
function be(r) {
|
|
594
|
-
return r instanceof X || r && "closed" in r && R(r.remove) && R(r.add) && R(r.unsubscribe);
|
|
595
|
-
}
|
|
596
|
-
function ae(r) {
|
|
597
|
-
R(r) ? r() : r.unsubscribe();
|
|
598
|
-
}
|
|
599
|
-
var ze = {
|
|
600
|
-
Promise: void 0
|
|
601
|
-
}, Ke = {
|
|
602
|
-
setTimeout: function(r, e) {
|
|
603
|
-
for (var t = [], n = 2; n < arguments.length; n++)
|
|
604
|
-
t[n - 2] = arguments[n];
|
|
605
|
-
return setTimeout.apply(void 0, K([r, e], z(t)));
|
|
606
|
-
},
|
|
607
|
-
clearTimeout: function(r) {
|
|
608
|
-
return clearTimeout(r);
|
|
609
|
-
},
|
|
610
|
-
delegate: void 0
|
|
611
|
-
};
|
|
612
|
-
function Qe(r) {
|
|
613
|
-
Ke.setTimeout(function() {
|
|
614
|
-
throw r;
|
|
615
|
-
});
|
|
616
|
-
}
|
|
617
|
-
function le() {
|
|
618
|
-
}
|
|
619
|
-
function Ge(r) {
|
|
620
|
-
r();
|
|
621
|
-
}
|
|
622
|
-
var we = (function(r) {
|
|
623
|
-
me(e, r);
|
|
624
|
-
function e(t) {
|
|
625
|
-
var n = r.call(this) || this;
|
|
626
|
-
return n.isStopped = !1, t ? (n.destination = t, be(t) && t.add(n)) : n.destination = et, n;
|
|
627
|
-
}
|
|
628
|
-
return e.create = function(t, n, i) {
|
|
629
|
-
return new Q(t, n, i);
|
|
630
|
-
}, e.prototype.next = function(t) {
|
|
631
|
-
this.isStopped || this._next(t);
|
|
632
|
-
}, e.prototype.error = function(t) {
|
|
633
|
-
this.isStopped || (this.isStopped = !0, this._error(t));
|
|
634
|
-
}, e.prototype.complete = function() {
|
|
635
|
-
this.isStopped || (this.isStopped = !0, this._complete());
|
|
636
|
-
}, e.prototype.unsubscribe = function() {
|
|
637
|
-
this.closed || (this.isStopped = !0, r.prototype.unsubscribe.call(this), this.destination = null);
|
|
638
|
-
}, e.prototype._next = function(t) {
|
|
639
|
-
this.destination.next(t);
|
|
640
|
-
}, e.prototype._error = function(t) {
|
|
641
|
-
try {
|
|
642
|
-
this.destination.error(t);
|
|
643
|
-
} finally {
|
|
644
|
-
this.unsubscribe();
|
|
645
|
-
}
|
|
646
|
-
}, e.prototype._complete = function() {
|
|
647
|
-
try {
|
|
648
|
-
this.destination.complete();
|
|
649
|
-
} finally {
|
|
650
|
-
this.unsubscribe();
|
|
651
|
-
}
|
|
652
|
-
}, e;
|
|
653
|
-
})(X), Xe = (function() {
|
|
654
|
-
function r(e) {
|
|
655
|
-
this.partialObserver = e;
|
|
656
|
-
}
|
|
657
|
-
return r.prototype.next = function(e) {
|
|
658
|
-
var t = this.partialObserver;
|
|
659
|
-
if (t.next)
|
|
660
|
-
try {
|
|
661
|
-
t.next(e);
|
|
662
|
-
} catch (n) {
|
|
663
|
-
U(n);
|
|
664
|
-
}
|
|
665
|
-
}, r.prototype.error = function(e) {
|
|
666
|
-
var t = this.partialObserver;
|
|
667
|
-
if (t.error)
|
|
668
|
-
try {
|
|
669
|
-
t.error(e);
|
|
670
|
-
} catch (n) {
|
|
671
|
-
U(n);
|
|
672
|
-
}
|
|
673
|
-
else
|
|
674
|
-
U(e);
|
|
675
|
-
}, r.prototype.complete = function() {
|
|
676
|
-
var e = this.partialObserver;
|
|
677
|
-
if (e.complete)
|
|
678
|
-
try {
|
|
679
|
-
e.complete();
|
|
680
|
-
} catch (t) {
|
|
681
|
-
U(t);
|
|
682
|
-
}
|
|
683
|
-
}, r;
|
|
684
|
-
})(), Q = (function(r) {
|
|
685
|
-
me(e, r);
|
|
686
|
-
function e(t, n, i) {
|
|
687
|
-
var o = r.call(this) || this, s;
|
|
688
|
-
return R(t) || !t ? s = {
|
|
689
|
-
next: t != null ? t : void 0,
|
|
690
|
-
error: n != null ? n : void 0,
|
|
691
|
-
complete: i != null ? i : void 0
|
|
692
|
-
} : s = t, o.destination = new Xe(s), o;
|
|
693
|
-
}
|
|
694
|
-
return e;
|
|
695
|
-
})(we);
|
|
696
|
-
function U(r) {
|
|
697
|
-
Qe(r);
|
|
698
|
-
}
|
|
699
|
-
function Ze(r) {
|
|
700
|
-
throw r;
|
|
701
|
-
}
|
|
702
|
-
var et = {
|
|
703
|
-
closed: !0,
|
|
704
|
-
next: le,
|
|
705
|
-
error: Ze,
|
|
706
|
-
complete: le
|
|
707
|
-
}, tt = (function() {
|
|
708
|
-
return typeof Symbol == "function" && Symbol.observable || "@@observable";
|
|
709
|
-
})();
|
|
710
|
-
function rt(r) {
|
|
711
|
-
return r;
|
|
712
|
-
}
|
|
713
|
-
function nt(r) {
|
|
714
|
-
return r.length === 0 ? rt : r.length === 1 ? r[0] : function(t) {
|
|
715
|
-
return r.reduce(function(n, i) {
|
|
716
|
-
return i(n);
|
|
717
|
-
}, t);
|
|
718
|
-
};
|
|
719
|
-
}
|
|
720
|
-
var it = (function() {
|
|
721
|
-
function r(e) {
|
|
722
|
-
e && (this._subscribe = e);
|
|
723
|
-
}
|
|
724
|
-
return r.prototype.lift = function(e) {
|
|
725
|
-
var t = new r();
|
|
726
|
-
return t.source = this, t.operator = e, t;
|
|
727
|
-
}, r.prototype.subscribe = function(e, t, n) {
|
|
728
|
-
var i = this, o = st(e) ? e : new Q(e, t, n);
|
|
729
|
-
return Ge(function() {
|
|
730
|
-
var s = i, c = s.operator, a = s.source;
|
|
731
|
-
o.add(c ? c.call(o, a) : a ? i._subscribe(o) : i._trySubscribe(o));
|
|
732
|
-
}), o;
|
|
733
|
-
}, r.prototype._trySubscribe = function(e) {
|
|
734
|
-
try {
|
|
735
|
-
return this._subscribe(e);
|
|
736
|
-
} catch (t) {
|
|
737
|
-
e.error(t);
|
|
738
|
-
}
|
|
739
|
-
}, r.prototype.forEach = function(e, t) {
|
|
740
|
-
var n = this;
|
|
741
|
-
return t = ue(t), new t(function(i, o) {
|
|
742
|
-
var s = new Q({
|
|
743
|
-
next: function(c) {
|
|
744
|
-
try {
|
|
745
|
-
e(c);
|
|
746
|
-
} catch (a) {
|
|
747
|
-
o(a), s.unsubscribe();
|
|
748
|
-
}
|
|
749
|
-
},
|
|
750
|
-
error: o,
|
|
751
|
-
complete: i
|
|
752
|
-
});
|
|
753
|
-
n.subscribe(s);
|
|
754
|
-
});
|
|
755
|
-
}, r.prototype._subscribe = function(e) {
|
|
756
|
-
var t;
|
|
757
|
-
return (t = this.source) === null || t === void 0 ? void 0 : t.subscribe(e);
|
|
758
|
-
}, r.prototype[tt] = function() {
|
|
759
|
-
return this;
|
|
760
|
-
}, r.prototype.pipe = function() {
|
|
761
|
-
for (var e = [], t = 0; t < arguments.length; t++)
|
|
762
|
-
e[t] = arguments[t];
|
|
763
|
-
return nt(e)(this);
|
|
764
|
-
}, r.prototype.toPromise = function(e) {
|
|
765
|
-
var t = this;
|
|
766
|
-
return e = ue(e), new e(function(n, i) {
|
|
767
|
-
var o;
|
|
768
|
-
t.subscribe(function(s) {
|
|
769
|
-
return o = s;
|
|
770
|
-
}, function(s) {
|
|
771
|
-
return i(s);
|
|
772
|
-
}, function() {
|
|
773
|
-
return n(o);
|
|
774
|
-
});
|
|
775
|
-
});
|
|
776
|
-
}, r.create = function(e) {
|
|
777
|
-
return new r(e);
|
|
778
|
-
}, r;
|
|
779
|
-
})();
|
|
780
|
-
function ue(r) {
|
|
781
|
-
var e;
|
|
782
|
-
return (e = r != null ? r : ze.Promise) !== null && e !== void 0 ? e : Promise;
|
|
783
|
-
}
|
|
784
|
-
function ot(r) {
|
|
785
|
-
return r && R(r.next) && R(r.error) && R(r.complete);
|
|
786
|
-
}
|
|
787
|
-
function st(r) {
|
|
788
|
-
return r && r instanceof we || ot(r) && be(r);
|
|
789
|
-
}
|
|
790
|
-
const ct = () => {
|
|
791
|
-
try {
|
|
792
|
-
clearTimeout(void 0);
|
|
793
|
-
} catch (r) {
|
|
794
|
-
return !1;
|
|
795
|
-
}
|
|
796
|
-
return !0;
|
|
797
|
-
}, at = (r = {}) => {
|
|
798
|
-
const { parentOrigin: e = "*", timeout: t, debug: n = !1, config: i = {} } = r, o = xe(n), s = Re("App", o), { destroy: c, onDestroy: a } = s, h = () => {
|
|
799
|
-
o("Child: Handshake - Sending SYN");
|
|
800
|
-
const A = { penpal: F.Syn }, g = e instanceof RegExp ? "*" : e;
|
|
801
|
-
window.parent.postMessage(A, g);
|
|
802
|
-
};
|
|
803
|
-
return {
|
|
804
|
-
promise: new Promise(
|
|
805
|
-
(A, g) => {
|
|
806
|
-
const p = ke(t, c), m = (l) => {
|
|
807
|
-
if (ct() && !(l.source !== parent || !l.data) && l.data.penpal === F.SynAck) {
|
|
808
|
-
const y = l.data, S = new oe(y.id, y.appName), P = new oe(y.id + "/api", y.appName), M = y.id, O = {}, C = (u) => "api/" + u, L = {
|
|
809
|
-
$emit: (u, ...f) => {
|
|
810
|
-
S.getEventCallBackLength(u) > 0 ? S.$pureEmit(u, ...f) : O == null || O.$off(u, () => {
|
|
811
|
-
}, !0);
|
|
812
|
-
},
|
|
813
|
-
onQueryResult: (u) => {
|
|
814
|
-
P.$pureEmit(C(u.reqid), u);
|
|
815
|
-
},
|
|
816
|
-
onOsNotify: (u) => {
|
|
817
|
-
}
|
|
818
|
-
}, j = (u) => function(b) {
|
|
819
|
-
const x = C(u);
|
|
820
|
-
P.$on(x, function T(E) {
|
|
821
|
-
b.next(E), E.reqid && E.result === "succ" && (b.complete(), P.$off(x, T));
|
|
822
|
-
});
|
|
823
|
-
}, ve = ye(L), V = Je(
|
|
824
|
-
e,
|
|
825
|
-
ve,
|
|
826
|
-
W(I({}, i), {
|
|
827
|
-
postmateVersion: Be.version
|
|
828
|
-
}),
|
|
829
|
-
s,
|
|
830
|
-
o
|
|
831
|
-
)(
|
|
832
|
-
l
|
|
833
|
-
), _ = {}, k = V.bus;
|
|
834
|
-
if (k) {
|
|
835
|
-
const u = (f, b, x) => {
|
|
836
|
-
x ? (b.$__once = !0, S.$once(f, b)) : S.$on(f, b), _[f] ? _[f].push(b) : (_[f] = [b], k.$on(f, M));
|
|
837
|
-
};
|
|
838
|
-
Object.assign(O, k, {
|
|
839
|
-
$on: u,
|
|
840
|
-
$off: (f, b, x) => {
|
|
841
|
-
var T;
|
|
842
|
-
if (_[f]) {
|
|
843
|
-
const E = _[f].indexOf(b);
|
|
844
|
-
E > -1 && (_[f].splice(E, 1), S.$off(f, b));
|
|
845
|
-
}
|
|
846
|
-
x && delete _[f], (T = _[f]) != null && T.length || (k.$off(f, M), delete _[f]);
|
|
847
|
-
},
|
|
848
|
-
$once: (f, b) => {
|
|
849
|
-
u(f, b, !0);
|
|
850
|
-
}
|
|
851
|
-
});
|
|
852
|
-
}
|
|
853
|
-
const Ee = W(I({}, V), {
|
|
854
|
-
bus: O,
|
|
855
|
-
query: (u, f) => w(null, null, function* () {
|
|
856
|
-
const b = (u == null ? void 0 : u.reqid) || (yield V.genReqId());
|
|
857
|
-
return new Promise((x, T) => {
|
|
858
|
-
V.query(
|
|
859
|
-
W(I({}, u), {
|
|
860
|
-
reqid: b
|
|
861
|
-
}),
|
|
862
|
-
f
|
|
863
|
-
).then((E) => {
|
|
864
|
-
(E == null ? void 0 : E.result) === "succ" ? x(E) : T(E);
|
|
865
|
-
});
|
|
866
|
-
});
|
|
867
|
-
}),
|
|
868
|
-
createObservableQuery: (b, ...x) => w(null, [b, ...x], function* (u, f = {}) {
|
|
869
|
-
const T = (u == null ? void 0 : u.reqid) || (yield V.genReqId()), E = new it(
|
|
870
|
-
j(T)
|
|
871
|
-
);
|
|
872
|
-
return V.query(
|
|
873
|
-
W(I({}, u), {
|
|
874
|
-
reqid: T
|
|
875
|
-
}),
|
|
876
|
-
W(I({}, f), {
|
|
877
|
-
observable: !0
|
|
878
|
-
})
|
|
879
|
-
), E;
|
|
880
|
-
})
|
|
881
|
-
});
|
|
882
|
-
V && (window.removeEventListener(N.Message, m), p(), A({
|
|
883
|
-
methods: Ee,
|
|
884
|
-
config: l.data.config
|
|
885
|
-
}));
|
|
886
|
-
}
|
|
887
|
-
};
|
|
888
|
-
window.addEventListener(N.Message, m), h(), a((l) => {
|
|
889
|
-
window.removeEventListener(N.Message, m), l && g(l);
|
|
890
|
-
});
|
|
891
|
-
}
|
|
892
|
-
),
|
|
893
|
-
destroy() {
|
|
894
|
-
c();
|
|
895
|
-
}
|
|
896
|
-
};
|
|
897
|
-
}, lt = (r) => at({
|
|
898
|
-
debug: r == null ? void 0 : r.debug
|
|
899
|
-
}).promise;
|
|
900
|
-
class pt {
|
|
901
|
-
constructor() {
|
|
902
|
-
$(this, "options");
|
|
903
|
-
$(this, "flutterInAppWebView", null);
|
|
904
|
-
$(this, "osConnector", null);
|
|
905
|
-
$(this, "initPromise");
|
|
906
|
-
$(this, "isWeb", !0);
|
|
907
|
-
let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
908
|
-
this.options = e, e.debug && (d.setDebug(!0), d.log("Trim App initialized with debug mode")), d.log("Options:", e), this.initPromise = this.init();
|
|
909
|
-
}
|
|
910
|
-
init() {
|
|
911
|
-
return w(this, null, function* () {
|
|
912
|
-
return d.log("Starting initialization..."), new Promise((e) => {
|
|
913
|
-
fe() ? (this.isWeb = !1, d.log("Initializing mobile platform..."), _e().then((t) => {
|
|
914
|
-
this.flutterInAppWebView = t, d.log("Mobile platform initialized"), e();
|
|
915
|
-
})) : (this.isWeb = !0, d.log("Initializing web platform..."), lt().then((t) => {
|
|
916
|
-
this.osConnector = t, d.log("Web platform initialized"), e();
|
|
917
|
-
}));
|
|
918
|
-
});
|
|
919
|
-
});
|
|
920
|
-
}
|
|
921
|
-
callAppMethod(e, t) {
|
|
922
|
-
return w(this, null, function* () {
|
|
923
|
-
return this.flutterInAppWebView ? Te(this.flutterInAppWebView, e, t) : null;
|
|
924
|
-
});
|
|
925
|
-
}
|
|
926
|
-
/**
|
|
927
|
-
* 等待初始化完成
|
|
928
|
-
* @returns Promise
|
|
929
|
-
*/
|
|
930
|
-
ready() {
|
|
931
|
-
return w(this, null, function* () {
|
|
932
|
-
return this.initPromise;
|
|
933
|
-
});
|
|
934
|
-
}
|
|
935
|
-
/**
|
|
936
|
-
* 获取配置
|
|
937
|
-
*/
|
|
938
|
-
getOptions() {
|
|
939
|
-
return this.options;
|
|
940
|
-
}
|
|
941
|
-
/**
|
|
942
|
-
* 更新配置
|
|
943
|
-
*/
|
|
944
|
-
setOptions(e) {
|
|
945
|
-
this.options = I(I({}, this.options), e), e.debug !== void 0 && d.setDebug(e.debug), d.log("Options updated:", this.options);
|
|
946
|
-
}
|
|
947
|
-
// 调用 app 的方法
|
|
948
|
-
/**
|
|
949
|
-
* 获取平台配置
|
|
950
|
-
*/
|
|
951
|
-
getPlatformConfig() {
|
|
952
|
-
return w(this, null, function* () {
|
|
953
|
-
var e;
|
|
954
|
-
if (yield this.initPromise, this.isWeb) {
|
|
955
|
-
const t = yield (e = this.osConnector) == null ? void 0 : e.methods.getPlatformConfig();
|
|
956
|
-
if (!t)
|
|
957
|
-
throw new Error("Failed to get platform config");
|
|
958
|
-
return t;
|
|
959
|
-
} else {
|
|
960
|
-
const t = yield this.callAppMethod("getAppMessage");
|
|
961
|
-
if (!t)
|
|
962
|
-
throw new Error("Failed to get platform config");
|
|
963
|
-
return {
|
|
964
|
-
theme: t.nightMode,
|
|
965
|
-
language: t.language,
|
|
966
|
-
appVersion: t.appVersion,
|
|
967
|
-
systemVersion: t.systemVersion,
|
|
968
|
-
format: {
|
|
969
|
-
date: t.dateFormat,
|
|
970
|
-
time: t.timeFormat
|
|
971
|
-
}
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
});
|
|
975
|
-
}
|
|
976
|
-
/**
|
|
977
|
-
* setTitle - 设置标题
|
|
978
|
-
* @param title 标题文本
|
|
979
|
-
*/
|
|
980
|
-
setTitle(e) {
|
|
981
|
-
return w(this, null, function* () {
|
|
982
|
-
var t;
|
|
983
|
-
return yield this.initPromise, d.log("Setting title:", e), this.isWeb ? (t = this.osConnector) == null ? void 0 : t.methods.setTitle(e) : this.callAppMethod("updateTitle", e);
|
|
984
|
-
});
|
|
985
|
-
}
|
|
986
|
-
/**
|
|
987
|
-
* setExitPageTips - 设置退出页面提示
|
|
988
|
-
* @param params 提示参数
|
|
989
|
-
*/
|
|
990
|
-
setExitPageTips(e) {
|
|
991
|
-
return w(this, null, function* () {
|
|
992
|
-
var t;
|
|
993
|
-
return yield this.initPromise, this.isWeb ? (t = this.osConnector) == null ? void 0 : t.methods.setExitPageTips(e) : this.callAppMethod("setExitPageTips", e ? JSON.stringify(e) : "");
|
|
994
|
-
});
|
|
995
|
-
}
|
|
996
|
-
/**
|
|
997
|
-
* 通过应用打开某个文件
|
|
998
|
-
*/
|
|
999
|
-
openFile(e) {
|
|
1000
|
-
return w(this, null, function* () {
|
|
1001
|
-
var t;
|
|
1002
|
-
return yield this.initPromise, d.log("Opening file:", e), this.isWeb ? (t = this.osConnector) == null ? void 0 : t.methods.openFile(e) : this.callAppMethod("openFile", e);
|
|
1003
|
-
});
|
|
1004
|
-
}
|
|
1005
|
-
/**
|
|
1006
|
-
* 打开文件管理器
|
|
1007
|
-
*/
|
|
1008
|
-
openFileManager(e) {
|
|
1009
|
-
return w(this, null, function* () {
|
|
1010
|
-
var t;
|
|
1011
|
-
return yield this.initPromise, d.log("Opening file manager:", e), this.isWeb ? (t = this.osConnector) == null ? void 0 : t.methods.openFileManagerApp(e) : this.callAppMethod("openFileManager", e);
|
|
1012
|
-
});
|
|
1013
|
-
}
|
|
1014
|
-
/**
|
|
1015
|
-
* 关闭应用
|
|
1016
|
-
*/
|
|
1017
|
-
close() {
|
|
1018
|
-
return w(this, null, function* () {
|
|
1019
|
-
var e;
|
|
1020
|
-
return yield this.initPromise, this.isWeb ? (e = this.osConnector) == null ? void 0 : e.methods.close() : this.callAppMethod("exitPage");
|
|
1021
|
-
});
|
|
1022
|
-
}
|
|
1023
|
-
/**
|
|
1024
|
-
* 请求接口
|
|
1025
|
-
*/
|
|
1026
|
-
query(e, t) {
|
|
1027
|
-
return w(this, null, function* () {
|
|
1028
|
-
var n;
|
|
1029
|
-
if (yield this.initPromise, this.isWeb) {
|
|
1030
|
-
const i = yield (n = this.osConnector) == null ? void 0 : n.methods.query(e, t);
|
|
1031
|
-
if (!i)
|
|
1032
|
-
throw new Error("Failed to query");
|
|
1033
|
-
return i;
|
|
1034
|
-
} else
|
|
1035
|
-
throw new Error("query is not supported on mobile platform");
|
|
1036
|
-
});
|
|
1037
|
-
}
|
|
1038
|
-
/**
|
|
1039
|
-
* 选择文件
|
|
1040
|
-
*/
|
|
1041
|
-
pickFile(e) {
|
|
1042
|
-
return w(this, null, function* () {
|
|
1043
|
-
var t;
|
|
1044
|
-
return yield this.initPromise, this.isWeb ? (t = this.osConnector) == null ? void 0 : t.methods.pickFile(e) : this.callAppMethod("openFolder", JSON.stringify(e));
|
|
1045
|
-
});
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
export {
|
|
1049
|
-
pt as TrimApp,
|
|
1050
|
-
pt as default
|
|
1051
|
-
};
|
|
1
|
+
var e=Object.defineProperty,t=Object.defineProperties,n=Object.getOwnPropertyDescriptors,r=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,s=(t,n,r)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[n]=r,l=(e,t)=>{for(var n in t||(t={}))o.call(t,n)&&s(e,n,t[n]);if(r)for(var n of r(t))i.call(t,n)&&s(e,n,t[n]);return e},a=(e,r)=>t(e,n(r)),c=(e,t,n)=>s(e,"symbol"!=typeof t?t+"":t,n),u=(e,t,n)=>new Promise((r,o)=>{var i=e=>{try{l(n.next(e))}catch(t){o(t)}},s=e=>{try{l(n.throw(e))}catch(t){o(t)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(i,s);l((n=n.apply(e,t)).next())});const p=new class{constructor(){c(this,"debug",!1)}setDebug(e){this.debug=e}isDebug(){return this.debug}log(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.log("[Trim App]",...t)}}warn(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.warn("[Trim App]",...t)}}error(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.error("[Trim App]",...t)}}info(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.info("[Trim App]",...t)}}};const d=()=>function(e){const t=/FNOS\/([\d.]+)|FNAppType\/(\w+)|FNAppVer\/([\d.]+)/g,n={};let r;for(;null!==(r=t.exec(e));)r[1]&&(n.fnOSVersion=r[1]),r[2]&&(n.fnAppType=r[2]),r[3]&&(n.fnAppVersion=r[3]);return n}(navigator.userAgent).fnAppVersion;let f=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{f=!0});const h=/* @__PURE__ */new Map;d()&&(window.fnAppMessage=e=>{p.log("app-message",e);const t=JSON.parse(e),n=h.get(t.reqId);n&&(n(t),h.delete(t.reqId))});var g=/* @__PURE__ */(e=>(e.Call="call",e.Reply="reply",e.Syn="syn",e.SynAck="synAck",e.Ack="ack",e))(g||{}),y=/* @__PURE__ */(e=>(e.Fulfilled="fulfilled",e.Rejected="rejected",e))(y||{}),v=/* @__PURE__ */(e=>(e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NoIframeSrc="NoIframeSrc",e))(v||{}),m=/* @__PURE__ */(e=>(e.DataCloneError="DataCloneError",e))(m||{}),b=/* @__PURE__ */(e=>(e.Message="message",e))(b||{});const w=({name:e,message:t,stack:n})=>({name:e,message:t,stack:n});let $=0;const _=e=>e?e.split("."):[],A=(e,t,n)=>{const r=_(t);return r.reduce((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===r.length-1&&(e[t]=n),e[t]),e),e},O=(e,t)=>{const n={};return Object.keys(e).forEach(r=>{const o=e[r],i=((e,t)=>{const n=_(t||"");return n.push(e),(e=>e.join("."))(n)})(r,t);"object"==typeof o&&Object.assign(n,O(o,i)),"function"==typeof o&&(n[i]=o)}),n},E=(e,t,n,r,o)=>{const{localName:i,local:s,remote:l,originForSending:a,originForReceiving:c}=t;let u=!1;o(`${i}: Connecting call sender`);const p=e=>(...t)=>{let n;o(`${i}: Sending ${e}() call`);try{l.closed&&(n=!0)}catch(p){n=!0}if(n&&r(),u){const t=new Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=v.ConnectionDestroyed,t}return new Promise((n,r)=>{const u=++$,p=t=>{if(t.source!==l||t.data.penpal!==g.Reply||t.data.id!==u)return;if("*"!==c&&t.origin!==c)return void o(`${i} received message from origin ${t.origin} which did not match expected origin ${c}`);const a=t.data;o(`${i}: Received ${e}() reply`),s.removeEventListener(b.Message,p);let d=a.returnValue;a.returnValueIsError&&(d=(e=>{const t=new Error;return Object.keys(e).forEach(n=>t[n]=e[n]),t})(d)),(a.resolution===y.Fulfilled?n:r)(d)};s.addEventListener(b.Message,p);const d={penpal:g.Call,id:u,methodName:e,args:t};l.postMessage(d,a)})},d=n.reduce((e,t)=>(e[t]=p(t),e),{});return Object.assign(e,(e=>{const t={};for(const n in e)A(t,n,e[n]);return t})(d)),()=>{u=!0}},P="0.1.2",S=(e,t,n,r,o)=>{const{destroy:i,onDestroy:s}=r;return r=>{if(!(e instanceof RegExp?e.test(r.origin):"*"===e||e===r.origin))return void o(`Child: Handshake - Received SYN-ACK from origin ${r.origin} which did not match expected origin ${e}`);o("Child: Handshake - Received SYN-ACK, responding with ACK");const l="null"===r.origin?"*":r.origin,a={penpal:g.Ack,methodNames:Object.keys(t),config:n};window.parent.postMessage(a,l);const c={localName:"Child",local:window,remote:window.parent,originForSending:l,originForReceiving:r.origin},u=((e,t,n)=>{const{localName:r,local:o,remote:i,originForSending:s,originForReceiving:l}=e;let a=!1;const c=e=>{if(e.source!==i||e.data.penpal!==g.Call)return;if("*"!==l&&e.origin!==l)return void n(`${r} received message from origin ${e.origin} which did not match expected origin ${l}`);const o=e.data,{methodName:c,args:u,id:p}=o;n(`${r}: Received ${c}() call`);const d=e=>t=>{if(n(`${r}: Sending ${c}() reply`),a)return void n(`${r}: Unable to send ${c}() reply due to destroyed connection`);const o={penpal:g.Reply,id:p,resolution:e,returnValue:t};e===y.Rejected&&t instanceof Error&&(o.returnValue=w(t),o.returnValueIsError=!0);try{i.postMessage(o,s)}catch(l){if(l.name===m.DataCloneError){const e={penpal:g.Reply,id:p,resolution:y.Rejected,returnValue:w(l),returnValueIsError:!0};i.postMessage(e,s)}throw l}};new Promise(e=>e(t[c].apply(t,u))).then(d(y.Fulfilled),d(y.Rejected))};return o.addEventListener(b.Message,c),()=>{a=!0,o.removeEventListener(b.Message,c)}})(c,t,o);s(u);const p={},d=E(p,c,r.data.methodNames,i,o);return s(d),p}};function C(e,t){null==console||console.warn(`[fnApp warn]: ${e}`,t)}function j(e,t){null==console||console.error(`[fnApp error]: ${e}`,t)}const x="_fn_all_event",M="事件订阅数量为空",N=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:/* @__PURE__ */new Map;class F{constructor(e,t){c(this,"id"),c(this,"appName"),c(this,"eventObj"),c(this,"getEventCallBackLength",e=>{var t;return(null==(t=this.eventObj[e])?void 0:t.length)||0}),this.id=e,this.appName=t,this.$clear(),N.get(this.id)||N.set(this.id,{}),this.eventObj=N.get(this.id)}$on(e,t){const n=this.eventObj[e];return n?(n.includes(t)||n.push(t),this):(this.eventObj[e]=[t],this)}$onAll(e){return this.$on(x,e)}$once(e,t){t.$__once=!0,this.$on(e,t)}$off(e,t){const n=this.eventObj[e];if(!e||!n||!n.length)return C(`${e} ${M}`),this;let r,o=n.length;for(;o--;)if(r=n[o],r===t){n.splice(o,1);break}return this}$offAll(e){return this.$off(x,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let n=0;return N.forEach(r=>{if(r[e])for(let i=r[e].length-1;i>=0;i--){n++;const s=r[e][i];s.$__once&&r[e].splice(i,1);try{s(...t)}catch(o){j(o)}}if(r[x])for(let e=r[x].length-1;e>=0;e--){n++;const i=r[x][e];i.$__once&&r[x].splice(e,1);try{i(...t)}catch(o){j(o)}}}),e&&0!==n||C(`${e} ${M}`),this}$clear(){const e=N.get(this.id)||{};return Object.keys(e).forEach(t=>delete e[t]),this}}var T=function(e,t){return(T=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function R(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}T(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function k(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function V(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(l){o={error:l}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function W(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}function I(e){return"function"==typeof e}"function"==typeof SuppressedError&&SuppressedError;var q,D=((q=function(e){return function(t){e(this),this.message=t?t.length+" errors occurred during unsubscription:\n"+t.map(function(e,t){return t+1+") "+e.toString()}).join("\n "):"",this.name="UnsubscriptionError",this.errors=t}}(function(e){Error.call(e),e.stack=(new Error).stack})).prototype=Object.create(Error.prototype),q.prototype.constructor=q,q);function z(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var L=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}var t;return e.prototype.unsubscribe=function(){var e,t,n,r,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var s=k(i),l=s.next();!l.done;l=s.next()){l.value.remove(this)}}catch(f){e={error:f}}finally{try{l&&!l.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else i.remove(this);var a=this.initialTeardown;if(I(a))try{a()}catch(h){o=h instanceof D?h.errors:[h]}var c=this._finalizers;if(c){this._finalizers=null;try{for(var u=k(c),p=u.next();!p.done;p=u.next()){var d=p.value;try{Y(d)}catch(g){o=null!=o?o:[],g instanceof D?o=W(W([],V(o)),V(g.errors)):o.push(g)}}}catch(y){n={error:y}}finally{try{p&&!p.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}}if(o)throw new D(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)Y(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null!==(n=this._finalizers)&&void 0!==n?n:[]).push(t)}},e.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},e.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},e.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&z(t,e)},e.prototype.remove=function(t){var n=this._finalizers;n&&z(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=((t=new e).closed=!0,t),e}();function J(e){return e instanceof L||e&&"closed"in e&&I(e.remove)&&I(e.add)&&I(e.unsubscribe)}function Y(e){I(e)?e():e.unsubscribe()}L.EMPTY;var H=void 0,B=function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setTimeout.apply(void 0,W([e,t],V(n)))};function K(){}var U=function(e){function t(t){var n=e.call(this)||this;return n.isStopped=!1,t?(n.destination=t,J(t)&&t.add(n)):n.destination=Z,n}return R(t,e),t.create=function(e,t,n){return new G(e,t,n)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(L),Q=function(){function e(e){this.partialObserver=e}return e.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(n){X(n)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(n){X(n)}else X(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){X(t)}},e}(),G=function(e){function t(t,n,r){var o,i=e.call(this)||this;return o=I(t)||!t?{next:null!=t?t:void 0,error:null!=n?n:void 0,complete:null!=r?r:void 0}:t,i.destination=new Q(o),i}return R(t,e),t}(U);function X(e){var t;t=e,B(function(){throw t})}var Z={closed:!0,next:K,error:function(e){throw e},complete:K},ee="function"==typeof Symbol&&Symbol.observable||"@@observable";function te(e){return e}var ne=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(e,t,n){var r,o=this,i=(r=e)&&r instanceof U||function(e){return e&&I(e.next)&&I(e.error)&&I(e.complete)}(r)&&J(r)?e:new G(e,t,n);return function(){var e=o,t=e.operator,n=e.source;i.add(t?t.call(i,n):n?o._subscribe(i):o._trySubscribe(i))}(),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},e.prototype.forEach=function(e,t){var n=this;return new(t=re(t))(function(t,r){var o=new G({next:function(t){try{e(t)}catch(n){r(n),o.unsubscribe()}},error:r,complete:t});n.subscribe(o)})},e.prototype._subscribe=function(e){var t;return null===(t=this.source)||void 0===t?void 0:t.subscribe(e)},e.prototype[ee]=function(){return this},e.prototype.pipe=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return(0===(e=t).length?te:1===e.length?e[0]:function(t){return e.reduce(function(e,t){return t(e)},t)})(this)},e.prototype.toPromise=function(e){var t=this;return new(e=re(e))(function(e,n){var r;t.subscribe(function(e){return r=e},function(e){return n(e)},function(){return e(r)})})},e.create=function(t){return new e(t)},e}();function re(e){var t;return null!==(t=null!=e?e:H)&&void 0!==t?t:Promise}const oe=(e={})=>{const{parentOrigin:t="*",timeout:n,debug:r=!1,config:o={}}=e,i=(e=>(...t)=>{e&&console.log("[Penpal]",...t)})(r),s=((e,t)=>{const n=[];let r=!1;return{destroy(o){r||(r=!0,t(`${e}: Destroying connection`),n.forEach(e=>{e(o)}))},onDestroy(e){r?e():n.push(e)}}})("App",i),{destroy:c,onDestroy:p}=s,d=new Promise((e,r)=>{const d=((e,t)=>{let n;return void 0!==e&&(n=window.setTimeout(()=>{const n=new Error(`Connection timed out after ${e}ms`);n.code=v.ConnectionTimeout,t(n)},e)),()=>{clearTimeout(n)}})(n,c),f=n=>{if((()=>{try{clearTimeout(void 0)}catch(e){return!1}return!0})()&&n.source===parent&&n.data&&n.data.penpal===g.SynAck){const r=n.data,c=new F(r.id,r.appName),p=new F(r.id+"/api",r.appName),h=r.id,g={},y=e=>"api/"+e,v=e=>function(t){const n=y(e);p.$on(n,function e(r){t.next(r),r.reqid&&"succ"===r.result&&(t.complete(),p.$off(n,e))})},m=O({$emit:(e,...t)=>{c.getEventCallBackLength(e)>0?c.$pureEmit(e,...t):null==g||g.$off(e,()=>{},!0)},onQueryResult:e=>{p.$pureEmit(y(e.reqid),e)},onOsNotify:e=>{}}),w=S(t,m,a(l({},o),{postmateVersion:P}),s,i)(n),$={},_=w.bus;if(_){const e=(e,t,n)=>{n?(t.$__once=!0,c.$once(e,t)):c.$on(e,t),$[e]?$[e].push(t):($[e]=[t],_.$on(e,h))};Object.assign(g,_,{$on:e,$off:(e,t,n)=>{var r;if($[e]){const n=$[e].indexOf(t);n>-1&&($[e].splice(n,1),c.$off(e,t))}n&&delete $[e],(null==(r=$[e])?void 0:r.length)||(_.$off(e,h),delete $[e])},$once:(t,n)=>{e(t,n,!0)}})}const A=a(l({},w),{bus:g,query:(e,t)=>u(null,null,function*(){const n=(null==e?void 0:e.reqid)||(yield w.genReqId());return new Promise((r,o)=>{w.query(a(l({},e),{reqid:n}),t).then(e=>{"succ"===(null==e?void 0:e.result)?r(e):o(e)})})}),createObservableQuery:(e,...t)=>u(null,[e,...t],function*(e,t={}){const n=(null==e?void 0:e.reqid)||(yield w.genReqId()),r=new ne(v(n));return w.query(a(l({},e),{reqid:n}),a(l({},t),{observable:!0})),r})});w&&(window.removeEventListener(b.Message,f),d(),e({methods:A,config:n.data.config}))}};window.addEventListener(b.Message,f),(()=>{i("Child: Handshake - Sending SYN");const e={penpal:g.Syn},n=t instanceof RegExp?"*":t;window.parent.postMessage(e,n)})(),p(e=>{window.removeEventListener(b.Message,f),e&&r(e)})});return{promise:d,destroy(){c()}}};let ie=null;class se{constructor(){c(this,"options"),c(this,"flutterInAppWebView",null),c(this,"osConnector",null),c(this,"initPromise"),c(this,"isWeb",!0);let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,e.debug&&(p.setDebug(!0),p.log("Trim App initialized with debug mode")),p.log("Options:",e),this.initPromise=this.init()}init(){return u(this,null,function*(){return p.log("Starting initialization..."),new Promise(e=>{var t;d()?(this.isWeb=!1,p.log("Initializing mobile platform..."),new Promise(e=>{var t;f||(null==(t=window.flutter_inappwebview)?void 0:t._platformReady)?(p.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)):window.addEventListener("flutterInAppWebViewPlatformReady",()=>{p.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)})}).then(t=>{this.flutterInAppWebView=t,p.log("Mobile platform initialized"),e()})):(this.isWeb=!0,p.log("Initializing web platform..."),(ie||(ie=oe({debug:null==t?void 0:t.debug})),ie.promise).then(t=>{this.osConnector=t,p.log("Web platform initialized"),e()}))})})}callAppMethod(e,t){return u(this,null,function*(){return this.flutterInAppWebView?((e,t,n)=>u(null,null,function*(){p.log(`callHandler: ${t}, params: ${n}`);const r=yield e.callHandler(t,n);if(r)try{const e=JSON.parse(r);p.log(`messageData: ${JSON.stringify(e)}`);const t=JSON.parse(e.result);return p.log(`appMessage: ${JSON.stringify(t)}`),t}catch(o){return p.error(`error: ${o}`),null}return null}))(this.flutterInAppWebView,e,t):null})}ready(){return u(this,null,function*(){return this.initPromise})}getOptions(){return this.options}setOptions(e){this.options=l(l({},this.options),e),void 0!==e.debug&&p.setDebug(e.debug),p.log("Options updated:",this.options)}getPlatformConfig(){return u(this,null,function*(){var e;if(yield this.initPromise,this.isWeb){const t=yield null==(e=this.osConnector)?void 0:e.methods.getPlatformConfig();if(!t)throw new Error("Failed to get platform config");return t}{const e=yield this.callAppMethod("getAppMessage");if(!e)throw new Error("Failed to get platform config");return{theme:e.nightMode,language:e.language,appVersion:e.appVersion,systemVersion:e.systemVersion,format:{date:e.dateFormat,time:e.timeFormat}}}})}setTitle(e){return u(this,null,function*(){var t;return yield this.initPromise,p.log("Setting title:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.setTitle(e):this.callAppMethod("updateTitle",e)})}setExitPageTips(e){return u(this,null,function*(){var t;return yield this.initPromise,this.isWeb?null==(t=this.osConnector)?void 0:t.methods.setExitPageTips(e):this.callAppMethod("setExitPageTips",e?JSON.stringify(e):"")})}openFile(e){return u(this,null,function*(){var t;return yield this.initPromise,p.log("Opening file:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.openFile(e):this.callAppMethod("openFile",e)})}openFileManager(e){return u(this,null,function*(){var t;return yield this.initPromise,p.log("Opening file manager:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.openFileManagerApp(e):this.callAppMethod("openFileManager",e)})}close(){return u(this,null,function*(){var e;return yield this.initPromise,this.isWeb?null==(e=this.osConnector)?void 0:e.methods.close():this.callAppMethod("exitPage")})}query(e,t){return u(this,null,function*(){var n;if(yield this.initPromise,this.isWeb){const r=yield null==(n=this.osConnector)?void 0:n.methods.query(e,t);if(!r)throw new Error("Failed to query");return r}throw new Error("query is not supported on mobile platform")})}pickFile(e){return u(this,null,function*(){var t;return yield this.initPromise,this.isWeb?null==(t=this.osConnector)?void 0:t.methods.pickFile(e):this.callAppMethod("openFolder",JSON.stringify(e))})}}export{se as TrimApp,se as default};
|