@trimjs/web-app 0.0.1

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