@polyv/utils 2.16.0 → 2.17.0
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/cjs/event.js +1 -1
- package/cjs/external-link.d.ts +23 -45
- package/cjs/external-link.js +1 -1
- package/es/event.js +1 -1
- package/es/external-link.d.ts +23 -45
- package/es/external-link.js +1 -1
- package/package.json +1 -1
package/cjs/event.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.EventEmitter=void 0;var EventEmitter=function(){function t(){this.__eventStore={}}return t.prototype.__addOnEvent=function(t,e,n,o){if(e&&n){var r=this.__eventStore[e];r||(r=[]),r.push({type:t,handler:n,callbackHandler:n.bind(o)}),this.__eventStore[e]=r}},t.prototype.on=function(t,e,n){void 0===n&&(n=this),this.__addOnEvent("normal",t,e,n)},t.prototype.once=function(t,e,n){void 0===n&&(n=this),this.__addOnEvent("once",t,e,n)},t.prototype.off=function(t,e){var n=this.__eventStore[t];n&&(n=n.filter((function(t){return t.handler!==e})),this.__eventStore[t]=n)},t.prototype.emit=function(t,e,n){var o=this,r=this.__eventStore[t];r&&r.forEach((function(r){var i=r.type,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.EventEmitter=void 0;var EventEmitter=function(){function t(){this.__eventStore={}}return t.prototype.__addOnEvent=function(t,e,n,o){if(e&&n){var r=this.__eventStore[e];r||(r=[]),r.push({type:t,handler:n,callbackHandler:n.bind(o)}),this.__eventStore[e]=r}},t.prototype.on=function(t,e,n){void 0===n&&(n=this),this.__addOnEvent("normal",t,e,n)},t.prototype.once=function(t,e,n){void 0===n&&(n=this),this.__addOnEvent("once",t,e,n)},t.prototype.off=function(t,e){var n=this.__eventStore[t];n&&(n=n.filter((function(t){return t.handler!==e})),this.__eventStore[t]=n)},t.prototype.emit=function(t,e,n){var o=this,r=this.__eventStore[t];r&&r.forEach((function(r){try{var i=r.type,c=r.handler,v=r.callbackHandler;"function"==typeof v&&v(e,n),"once"===i&&o.off(t,c)}catch(t){console.error(t)}}))},t.prototype.destroy=function(){this.__eventStore={}},t}();exports.EventEmitter=EventEmitter;
|
package/cjs/external-link.d.ts
CHANGED
|
@@ -17,38 +17,10 @@ export interface WebViewBridge {
|
|
|
17
17
|
export declare const isAndroid: boolean;
|
|
18
18
|
/** 是否 iOS */
|
|
19
19
|
export declare const isIOS: boolean;
|
|
20
|
-
|
|
21
|
-
declare
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
toPointMall?: ToPointMallFunc;
|
|
25
|
-
};
|
|
26
|
-
webkit?: {
|
|
27
|
-
messageHandlers?: {
|
|
28
|
-
gotoPointsMall?: {
|
|
29
|
-
postMessage?: ToPointMallFunc;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* 链接类型
|
|
37
|
-
*/
|
|
38
|
-
export declare enum LinkType {
|
|
39
|
-
/**
|
|
40
|
-
* 通用链接
|
|
41
|
-
*/
|
|
42
|
-
Normal = 10,
|
|
43
|
-
/**
|
|
44
|
-
* 多平台链接
|
|
45
|
-
*/
|
|
46
|
-
MultiPlatform = 11,
|
|
47
|
-
/**
|
|
48
|
-
* 原生方法跳转
|
|
49
|
-
*/
|
|
50
|
-
Native = 12
|
|
51
|
-
}
|
|
20
|
+
/** 是否纯血鸿蒙 */
|
|
21
|
+
export declare const isHarmony: boolean;
|
|
22
|
+
/** 是否移动端 */
|
|
23
|
+
export declare const isPortable: boolean;
|
|
52
24
|
/**
|
|
53
25
|
* 外链跳转方式
|
|
54
26
|
*/
|
|
@@ -70,10 +42,6 @@ export declare enum LinkJumpWay {
|
|
|
70
42
|
* 链接数据接口
|
|
71
43
|
*/
|
|
72
44
|
export interface LinkData {
|
|
73
|
-
/**
|
|
74
|
-
* 链接类型
|
|
75
|
-
*/
|
|
76
|
-
linkType: LinkType;
|
|
77
45
|
/**
|
|
78
46
|
* 跳转方式
|
|
79
47
|
*/
|
|
@@ -86,10 +54,6 @@ export interface LinkData {
|
|
|
86
54
|
* PC 端跳转链接
|
|
87
55
|
*/
|
|
88
56
|
pcLink: string;
|
|
89
|
-
/**
|
|
90
|
-
* 移动端跳转链接
|
|
91
|
-
*/
|
|
92
|
-
mobileLink: string;
|
|
93
57
|
/**
|
|
94
58
|
* App 链接
|
|
95
59
|
*/
|
|
@@ -103,9 +67,9 @@ export interface LinkData {
|
|
|
103
67
|
*/
|
|
104
68
|
iosLink: string;
|
|
105
69
|
/**
|
|
106
|
-
*
|
|
70
|
+
* 鸿蒙 app 跳转链接
|
|
107
71
|
*/
|
|
108
|
-
|
|
72
|
+
harmonyLink: string;
|
|
109
73
|
/**
|
|
110
74
|
* 微信小程序原始 id
|
|
111
75
|
*/
|
|
@@ -129,16 +93,18 @@ export type GetLinkParams = (url: string) => Record<string, unknown>;
|
|
|
129
93
|
export interface NavigateToLinkOptions {
|
|
130
94
|
/** 链接数据 */
|
|
131
95
|
linkData: LinkData;
|
|
96
|
+
/** 是否使用保利威桥接器跳转链接 */
|
|
97
|
+
usePlvWebviewBridge?: boolean;
|
|
132
98
|
/**
|
|
133
99
|
* 获取链接参数
|
|
134
100
|
*/
|
|
135
101
|
getLinkParams?: GetLinkParams;
|
|
136
102
|
/** 通用链接打开处理器 */
|
|
137
103
|
openLink: (url: string, jumpWay: LinkJumpWay) => void;
|
|
138
|
-
/** 是否处于保利威 webview 中 */
|
|
139
|
-
isPlvWebview?: () => boolean;
|
|
140
104
|
/** 是否移动端 */
|
|
141
105
|
isMobile?: () => boolean;
|
|
106
|
+
/** 是否处于保利威 webview 中 */
|
|
107
|
+
isPlvWebview?: () => boolean;
|
|
142
108
|
/** 获取保利威 webview 桥接器 */
|
|
143
109
|
getPlvWebviewBridge?: () => Promise<WebViewBridge | undefined>;
|
|
144
110
|
/** 获取保利威 webview 小窗尺寸 */
|
|
@@ -150,6 +116,19 @@ export interface NavigateToLinkOptions {
|
|
|
150
116
|
/** 跳转微信小程序 */
|
|
151
117
|
toWxMiniProgram?: (link: string) => void;
|
|
152
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* 检测自定义环境 UA 配置
|
|
121
|
+
*/
|
|
122
|
+
export declare function isCustomUA(uaList: string[]): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* 通过 URL Scheme 打开 App,失败时跳转兜底链接
|
|
125
|
+
*/
|
|
126
|
+
export declare function openAppWithFallback(options: {
|
|
127
|
+
iosLink: string;
|
|
128
|
+
androidLink: string;
|
|
129
|
+
harmonyLink: string;
|
|
130
|
+
fallbackUrl: string;
|
|
131
|
+
}): void;
|
|
153
132
|
/**
|
|
154
133
|
* 格式化链接地址
|
|
155
134
|
* @param url 需要格式化的链接地址
|
|
@@ -162,4 +141,3 @@ export declare function formatLink(url: string, getLinkParams?: (url: string) =>
|
|
|
162
141
|
* @param options 跳转配置项
|
|
163
142
|
*/
|
|
164
143
|
export declare function navigateToLink(options: NavigateToLinkOptions): void;
|
|
165
|
-
export {};
|
package/cjs/external-link.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(i,n,e,o){return new(e||(e=Promise))((function(t
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(i,n,e,o){return new(e||(e=Promise))((function(r,t){function a(i){try{l(o.next(i))}catch(i){t(i)}}function s(i){try{l(o.throw(i))}catch(i){t(i)}}function l(i){var n;i.done?r(i.value):(n=i.value,n instanceof e?n:new e((function(i){i(n)}))).then(a,s)}l((o=o.apply(i,n||[])).next())}))},__generator=this&&this.__generator||function(i,n){var e,o,r,t,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return t={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function s(s){return function(l){return function(s){if(e)throw new TypeError("Generator is already executing.");for(;t&&(t=0,s[0]&&(a=0)),a;)try{if(e=1,o&&(r=2&s[0]?o.return:s[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,s[1])).done)return r;switch(o=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,o=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){a.label=s[1];break}if(6===s[0]&&a.label<r[1]){a.label=r[1],r=s;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(s);break}r[2]&&a.ops.pop(),a.trys.pop();continue}s=n.call(i,a)}catch(i){s=[6,i],o=0}finally{e=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LinkJumpWay=exports.isPortable=exports.isHarmony=exports.isIOS=exports.isAndroid=void 0,exports.isCustomUA=isCustomUA,exports.openAppWithFallback=openAppWithFallback,exports.formatLink=formatLink,exports.navigateToLink=navigateToLink;var LinkJumpWay,ua_info_1=require("@just4/ua-info"),querystring_1=require("@just4/querystring"),uaInfo=(0,ua_info_1.getCurrentUAInfo)();function isCustomUA(i){var n=navigator.userAgent.toLowerCase();return!!i.length&&i.some((function(i){return n.includes(i.toLowerCase())}))}function openAppWithFallback(i){var n,e=i.iosLink,o=i.androidLink,r=i.harmonyLink,t=i.fallbackUrl,a=Date.now(),s=!1,l=function(){s=!0,window.removeEventListener("blur",l)};window.addEventListener("blur",l),console.info("ios\uff1a".concat(exports.isIOS,"\uff0cAndroid\uff1a").concat(exports.isAndroid,"\uff0charmony\uff1a").concat(exports.isHarmony)),exports.isIOS?(console.info("iOSLink",e),n=e):exports.isAndroid?(console.info("Android link",o),n=o):exports.isHarmony&&(console.info("harmony link",r),n=r),n||(console.info("\u6ca1\u6709\u914d\u7f6e\u591a\u5e73\u53f0\u94fe\u63a5\uff0c\u4f7f\u7528\u964d\u7ea7\u94fe\u63a5",t),n=t),window.location.href=n,setTimeout((function(){window.removeEventListener("blur",l);var i=Date.now()-a;!s&&i<3700&&t&&(window.location.href=t)}),3500)}function toPlvWebviewBridge(i){return __awaiter(this,void 0,void 0,(function(){var n,e,o,r;return __generator(this,(function(t){switch(t.label){case 0:return n=i.getPlvWebviewSmallWindowSize,e=i.getPlvWebviewBridge,o=(null==n?void 0:n())||{width:90,height:160},[4,null==e?void 0:e()];case 1:return(r=t.sent())?(r.sendData("clickProduct",{width:o.width,height:o.height,newPage:!0,link:i.link,data:i.data}),[2]):[2]}}))}))}function toMultiPlatformLink(i){return __awaiter(this,void 0,void 0,(function(){var n,e,o,r,t,a,s,l,u,c,f,p,k,d,v,w;return __generator(this,(function(m){switch(m.label){case 0:n=i.linkData,e=i.isWxMiniProgramEnv,o=i.toWxMiniProgram,r=i.openLink,t=i.getLinkParams,a=i.isMobile,s=n.wxMiniprogramLink,l=n.pcLink,u=n.iosLink,c=n.androidLink,f=n.harmonyLink,p=n.link,k=n.jumpWay,d=n.mobileAppLink,v=(null==a?void 0:a())||exports.isPortable,console.info("\u8df3\u8f6c\u51fd\u6570\u6536\u5230\u7684\u6570\u636e",n),w=!1,m.label=1;case 1:return m.trys.push([1,3,,4]),[4,null==e?void 0:e()];case 2:return w=m.sent()||!1,[3,4];case 3:return m.sent(),w=!1,[3,4];case 4:return w&&o?(console.info("\u8fdb\u5165\u5230\u5c0f\u7a0b\u5e8f webview \u73af\u5883 wxMiniprogramLink & link",s,p),s?o(formatLink(s,t)):r(formatLink(p,t),LinkJumpWay.CurrentWindow),[2]):v?uaInfo.client.isWx||uaInfo.client.isWxWork||uaInfo.client.isDing||uaInfo.client.isQQ||uaInfo.client.isWeibo||uaInfo.client.isBaiduApp?(r(formatLink(p,t),k),[2]):(openAppWithFallback({iosLink:u,androidLink:c,harmonyLink:f,fallbackUrl:d||p}),[2]):(r(formatLink(l||p,t),k),[2])}}))}))}function formatLink(i,n){var e={};if(n){var o=n(i);e=Object.assign({},e,o)}return(0,querystring_1.concat)(i,e)}function navigateToLink(i){var n=i.linkData,e=i.usePlvWebviewBridge,o=i.openLink,r=i.isPlvWebview,t=i.getPlvWebviewSmallWindowSize,a=i.getPlvWebviewBridge,s=i.isWxMiniProgramEnv,l=i.toWxMiniProgram,u=i.getLinkParams,c=i.isMobile,f=(null==r?void 0:r())||!1;if(console.info("\u662f\u5426\u4fdd\u5229\u5a01 webview \u73af\u5883",f),f){var p=n.link,k=n.iosLink,d=n.androidLink,v=n.harmonyLink,w=n.mobileAppLink,m=n.wxMiniprogramOriginalId,L=n.wxMiniprogramLink,b=w||p;console.info("\u4fdd\u5229\u5a01 webview \u4e0b\u7684 mobileAppLink\uff0clink",w,p),console.info("\u4fdd\u5229\u5a01 webview \u4e0b usePlvWebviewBridge",e);var g={mobileLink:formatLink(p,u),wxMiniprogramOriginalId:m,wxMiniprogramLink:formatLink(L,u),mobileAppLink:formatLink(w,u)};return e?void toPlvWebviewBridge({link:formatLink(b,u),data:g,getPlvWebviewSmallWindowSize:t,getPlvWebviewBridge:a}):void openAppWithFallback({iosLink:k,androidLink:d,harmonyLink:v,fallbackUrl:w||p})}toMultiPlatformLink({linkData:n,getLinkParams:u,isWxMiniProgramEnv:s,toWxMiniProgram:l,openLink:o,isMobile:c})}exports.isAndroid=uaInfo.os.isAndroid,exports.isIOS=uaInfo.os.isIOS,exports.isHarmony=uaInfo.os.isOpenHarmony,exports.isPortable=uaInfo.isPortable,function(i){i.PopUp="POP_UP",i.NewWindow="NEW_WINDOW",i.CurrentWindow="CURRENT_WINDOW"}(LinkJumpWay||(exports.LinkJumpWay=LinkJumpWay={}));
|
package/es/event.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export class EventEmitter{constructor(){this.__eventStore={}}__addOnEvent(t,e,n,o){if(!e||!n)return;let r=this.__eventStore[e];r||(r=[]),r.push({type:t,handler:n,callbackHandler:n.bind(o)}),this.__eventStore[e]=r}on(t,e,n=this){this.__addOnEvent("normal",t,e,n)}once(t,e,n=this){this.__addOnEvent("once",t,e,n)}off(t,e){let n=this.__eventStore[t];n&&(n=n.filter((t=>t.handler!==e)),this.__eventStore[t]=n)}emit(t,e,n){const o=this.__eventStore[t];o&&o.forEach((o=>{const{type:r,handler:
|
|
1
|
+
export class EventEmitter{constructor(){this.__eventStore={}}__addOnEvent(t,e,n,o){if(!e||!n)return;let r=this.__eventStore[e];r||(r=[]),r.push({type:t,handler:n,callbackHandler:n.bind(o)}),this.__eventStore[e]=r}on(t,e,n=this){this.__addOnEvent("normal",t,e,n)}once(t,e,n=this){this.__addOnEvent("once",t,e,n)}off(t,e){let n=this.__eventStore[t];n&&(n=n.filter((t=>t.handler!==e)),this.__eventStore[t]=n)}emit(t,e,n){const o=this.__eventStore[t];o&&o.forEach((o=>{try{const{type:r,handler:s,callbackHandler:_}=o;"function"==typeof _&&_(e,n),"once"===r&&this.off(t,s)}catch(t){console.error(t)}}))}destroy(){this.__eventStore={}}}
|
package/es/external-link.d.ts
CHANGED
|
@@ -17,38 +17,10 @@ export interface WebViewBridge {
|
|
|
17
17
|
export declare const isAndroid: boolean;
|
|
18
18
|
/** 是否 iOS */
|
|
19
19
|
export declare const isIOS: boolean;
|
|
20
|
-
|
|
21
|
-
declare
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
toPointMall?: ToPointMallFunc;
|
|
25
|
-
};
|
|
26
|
-
webkit?: {
|
|
27
|
-
messageHandlers?: {
|
|
28
|
-
gotoPointsMall?: {
|
|
29
|
-
postMessage?: ToPointMallFunc;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* 链接类型
|
|
37
|
-
*/
|
|
38
|
-
export declare enum LinkType {
|
|
39
|
-
/**
|
|
40
|
-
* 通用链接
|
|
41
|
-
*/
|
|
42
|
-
Normal = 10,
|
|
43
|
-
/**
|
|
44
|
-
* 多平台链接
|
|
45
|
-
*/
|
|
46
|
-
MultiPlatform = 11,
|
|
47
|
-
/**
|
|
48
|
-
* 原生方法跳转
|
|
49
|
-
*/
|
|
50
|
-
Native = 12
|
|
51
|
-
}
|
|
20
|
+
/** 是否纯血鸿蒙 */
|
|
21
|
+
export declare const isHarmony: boolean;
|
|
22
|
+
/** 是否移动端 */
|
|
23
|
+
export declare const isPortable: boolean;
|
|
52
24
|
/**
|
|
53
25
|
* 外链跳转方式
|
|
54
26
|
*/
|
|
@@ -70,10 +42,6 @@ export declare enum LinkJumpWay {
|
|
|
70
42
|
* 链接数据接口
|
|
71
43
|
*/
|
|
72
44
|
export interface LinkData {
|
|
73
|
-
/**
|
|
74
|
-
* 链接类型
|
|
75
|
-
*/
|
|
76
|
-
linkType: LinkType;
|
|
77
45
|
/**
|
|
78
46
|
* 跳转方式
|
|
79
47
|
*/
|
|
@@ -86,10 +54,6 @@ export interface LinkData {
|
|
|
86
54
|
* PC 端跳转链接
|
|
87
55
|
*/
|
|
88
56
|
pcLink: string;
|
|
89
|
-
/**
|
|
90
|
-
* 移动端跳转链接
|
|
91
|
-
*/
|
|
92
|
-
mobileLink: string;
|
|
93
57
|
/**
|
|
94
58
|
* App 链接
|
|
95
59
|
*/
|
|
@@ -103,9 +67,9 @@ export interface LinkData {
|
|
|
103
67
|
*/
|
|
104
68
|
iosLink: string;
|
|
105
69
|
/**
|
|
106
|
-
*
|
|
70
|
+
* 鸿蒙 app 跳转链接
|
|
107
71
|
*/
|
|
108
|
-
|
|
72
|
+
harmonyLink: string;
|
|
109
73
|
/**
|
|
110
74
|
* 微信小程序原始 id
|
|
111
75
|
*/
|
|
@@ -129,16 +93,18 @@ export type GetLinkParams = (url: string) => Record<string, unknown>;
|
|
|
129
93
|
export interface NavigateToLinkOptions {
|
|
130
94
|
/** 链接数据 */
|
|
131
95
|
linkData: LinkData;
|
|
96
|
+
/** 是否使用保利威桥接器跳转链接 */
|
|
97
|
+
usePlvWebviewBridge?: boolean;
|
|
132
98
|
/**
|
|
133
99
|
* 获取链接参数
|
|
134
100
|
*/
|
|
135
101
|
getLinkParams?: GetLinkParams;
|
|
136
102
|
/** 通用链接打开处理器 */
|
|
137
103
|
openLink: (url: string, jumpWay: LinkJumpWay) => void;
|
|
138
|
-
/** 是否处于保利威 webview 中 */
|
|
139
|
-
isPlvWebview?: () => boolean;
|
|
140
104
|
/** 是否移动端 */
|
|
141
105
|
isMobile?: () => boolean;
|
|
106
|
+
/** 是否处于保利威 webview 中 */
|
|
107
|
+
isPlvWebview?: () => boolean;
|
|
142
108
|
/** 获取保利威 webview 桥接器 */
|
|
143
109
|
getPlvWebviewBridge?: () => Promise<WebViewBridge | undefined>;
|
|
144
110
|
/** 获取保利威 webview 小窗尺寸 */
|
|
@@ -150,6 +116,19 @@ export interface NavigateToLinkOptions {
|
|
|
150
116
|
/** 跳转微信小程序 */
|
|
151
117
|
toWxMiniProgram?: (link: string) => void;
|
|
152
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* 检测自定义环境 UA 配置
|
|
121
|
+
*/
|
|
122
|
+
export declare function isCustomUA(uaList: string[]): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* 通过 URL Scheme 打开 App,失败时跳转兜底链接
|
|
125
|
+
*/
|
|
126
|
+
export declare function openAppWithFallback(options: {
|
|
127
|
+
iosLink: string;
|
|
128
|
+
androidLink: string;
|
|
129
|
+
harmonyLink: string;
|
|
130
|
+
fallbackUrl: string;
|
|
131
|
+
}): void;
|
|
153
132
|
/**
|
|
154
133
|
* 格式化链接地址
|
|
155
134
|
* @param url 需要格式化的链接地址
|
|
@@ -162,4 +141,3 @@ export declare function formatLink(url: string, getLinkParams?: (url: string) =>
|
|
|
162
141
|
* @param options 跳转配置项
|
|
163
142
|
*/
|
|
164
143
|
export declare function navigateToLink(options: NavigateToLinkOptions): void;
|
|
165
|
-
export {};
|
package/es/external-link.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(i,n,o,
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(i,n,o,e){return new(o||(o=Promise))((function(t,r){function a(i){try{s(e.next(i))}catch(i){r(i)}}function l(i){try{s(e.throw(i))}catch(i){r(i)}}function s(i){var n;i.done?t(i.value):(n=i.value,n instanceof o?n:new o((function(i){i(n)}))).then(a,l)}s((e=e.apply(i,n||[])).next())}))};import{getCurrentUAInfo}from"@just4/ua-info";import{concat}from"@just4/querystring";const uaInfo=getCurrentUAInfo();export const isAndroid=uaInfo.os.isAndroid;export const isIOS=uaInfo.os.isIOS;export const isHarmony=uaInfo.os.isOpenHarmony;export const isPortable=uaInfo.isPortable;export var LinkJumpWay;!function(i){i.PopUp="POP_UP",i.NewWindow="NEW_WINDOW",i.CurrentWindow="CURRENT_WINDOW"}(LinkJumpWay||(LinkJumpWay={}));export function isCustomUA(i){const n=navigator.userAgent.toLowerCase();return!!i.length&&i.some((i=>n.includes(i.toLowerCase())))}export function openAppWithFallback(i){const{iosLink:n,androidLink:o,harmonyLink:e,fallbackUrl:t}=i,r=Date.now();let a=!1;const l=()=>{a=!0,window.removeEventListener("blur",l)};let s;window.addEventListener("blur",l),console.info(`ios\uff1a${isIOS}\uff0cAndroid\uff1a${isAndroid}\uff0charmony\uff1a${isHarmony}`),isIOS?(console.info("iOSLink",n),s=n):isAndroid?(console.info("Android link",o),s=o):isHarmony&&(console.info("harmony link",e),s=e),s||(console.info("\u6ca1\u6709\u914d\u7f6e\u591a\u5e73\u53f0\u94fe\u63a5\uff0c\u4f7f\u7528\u964d\u7ea7\u94fe\u63a5",t),s=t),window.location.href=s,setTimeout((()=>{window.removeEventListener("blur",l);const i=Date.now()-r;!a&&i<3700&&t&&(window.location.href=t)}),3500)}function toPlvWebviewBridge(i){return __awaiter(this,void 0,void 0,(function*(){const{getPlvWebviewSmallWindowSize:n,getPlvWebviewBridge:o}=i,e=(null==n?void 0:n())||{width:90,height:160},t=yield null==o?void 0:o();t&&t.sendData("clickProduct",{width:e.width,height:e.height,newPage:!0,link:i.link,data:i.data})}))}function toMultiPlatformLink(i){return __awaiter(this,void 0,void 0,(function*(){const{linkData:n,isWxMiniProgramEnv:o,toWxMiniProgram:e,openLink:t,getLinkParams:r,isMobile:a}=i,{wxMiniprogramLink:l,pcLink:s,iosLink:c,androidLink:d,harmonyLink:k,link:u,jumpWay:f,mobileAppLink:m}=n,w=(null==a?void 0:a())||isPortable;console.info("\u8df3\u8f6c\u51fd\u6570\u6536\u5230\u7684\u6570\u636e",n);let v=!1;try{v=(yield null==o?void 0:o())||!1}catch(i){v=!1}if(v&&e)return console.info("\u8fdb\u5165\u5230\u5c0f\u7a0b\u5e8f webview \u73af\u5883 wxMiniprogramLink & link",l,u),void(l?e(formatLink(l,r)):t(formatLink(u,r),LinkJumpWay.CurrentWindow));w?uaInfo.client.isWx||uaInfo.client.isWxWork||uaInfo.client.isDing||uaInfo.client.isQQ||uaInfo.client.isWeibo||uaInfo.client.isBaiduApp?t(formatLink(u,r),f):openAppWithFallback({iosLink:c,androidLink:d,harmonyLink:k,fallbackUrl:m||u}):t(formatLink(s||u,r),f)}))}export function formatLink(i,n){let o={};if(n){const e=n(i);o=Object.assign({},o,e)}return concat(i,o)}export function navigateToLink(i){const{linkData:n,usePlvWebviewBridge:o,openLink:e,isPlvWebview:t,getPlvWebviewSmallWindowSize:r,getPlvWebviewBridge:a,isWxMiniProgramEnv:l,toWxMiniProgram:s,getLinkParams:c,isMobile:d}=i,k=(null==t?void 0:t())||!1;if(console.info("\u662f\u5426\u4fdd\u5229\u5a01 webview \u73af\u5883",k),k){const{link:i,iosLink:e,androidLink:t,harmonyLink:l,mobileAppLink:s,wxMiniprogramOriginalId:d,wxMiniprogramLink:k}=n,u=s||i;console.info("\u4fdd\u5229\u5a01 webview \u4e0b\u7684 mobileAppLink\uff0clink",s,i),console.info("\u4fdd\u5229\u5a01 webview \u4e0b usePlvWebviewBridge",o);const f={mobileLink:formatLink(i,c),wxMiniprogramOriginalId:d,wxMiniprogramLink:formatLink(k,c),mobileAppLink:formatLink(s,c)};return o?void toPlvWebviewBridge({link:formatLink(u,c),data:f,getPlvWebviewSmallWindowSize:r,getPlvWebviewBridge:a}):void openAppWithFallback({iosLink:e,androidLink:t,harmonyLink:l,fallbackUrl:s||i})}toMultiPlatformLink({linkData:n,getLinkParams:c,isWxMiniProgramEnv:l,toWxMiniProgram:s,openLink:e,isMobile:d})}
|