@polyv/utils 2.16.0 → 2.18.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 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,v=r.handler,_=r.callbackHandler;"function"==typeof _&&_(e,n),"once"===i&&o.off(t,v)}))},t.prototype.destroy=function(){this.__eventStore={}},t}();exports.EventEmitter=EventEmitter;
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;
@@ -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
- type ToPointMallFunc = (params: string) => unknown;
21
- declare global {
22
- interface Window {
23
- AndroidNative?: {
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
- otherLink: string;
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,21 @@ 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
+ jumpWay: LinkJumpWay;
132
+ openLink: (url: string, jumpWay: LinkJumpWay) => void;
133
+ }): void;
153
134
  /**
154
135
  * 格式化链接地址
155
136
  * @param url 需要格式化的链接地址
@@ -162,4 +143,3 @@ export declare function formatLink(url: string, getLinkParams?: (url: string) =>
162
143
  * @param options 跳转配置项
163
144
  */
164
145
  export declare function navigateToLink(options: NavigateToLinkOptions): void;
165
- export {};
@@ -1 +1 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(i,n,e,o){return new(e||(e=Promise))((function(t,r){function a(i){try{s(o.next(i))}catch(i){r(i)}}function l(i){try{s(o.throw(i))}catch(i){r(i)}}function s(i){var n;i.done?t(i.value):(n=i.value,n instanceof e?n:new e((function(i){i(n)}))).then(a,l)}s((o=o.apply(i,n||[])).next())}))},__generator=this&&this.__generator||function(i,n){var e,o,t,r,a={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return r={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function l(l){return function(s){return function(l){if(e)throw new TypeError("Generator is already executing.");for(;r&&(r=0,l[0]&&(a=0)),a;)try{if(e=1,o&&(t=2&l[0]?o.return:l[0]?o.throw||((t=o.return)&&t.call(o),0):o.next)&&!(t=t.call(o,l[1])).done)return t;switch(o=0,t&&(l=[2&l[0],t.value]),l[0]){case 0:case 1:t=l;break;case 4:return a.label++,{value:l[1],done:!1};case 5:a.label++,o=l[1],l=[0];continue;case 7:l=a.ops.pop(),a.trys.pop();continue;default:if(!(t=a.trys,(t=t.length>0&&t[t.length-1])||6!==l[0]&&2!==l[0])){a=0;continue}if(3===l[0]&&(!t||l[1]>t[0]&&l[1]<t[3])){a.label=l[1];break}if(6===l[0]&&a.label<t[1]){a.label=t[1],t=l;break}if(t&&a.label<t[2]){a.label=t[2],a.ops.push(l);break}t[2]&&a.ops.pop(),a.trys.pop();continue}l=n.call(i,a)}catch(i){l=[6,i],o=0}finally{e=t=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,s])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LinkJumpWay=exports.LinkType=exports.isIOS=exports.isAndroid=void 0,exports.formatLink=formatLink,exports.navigateToLink=navigateToLink;var LinkType,LinkJumpWay,ua_info_1=require("@just4/ua-info"),querystring_1=require("@just4/querystring"),uaInfo=(0,ua_info_1.getCurrentUAInfo)();function invokeNativePointMall(i){var n,e,o,t,r,a;exports.isAndroid?null===(e=null===(n=window.AndroidNative)||void 0===n?void 0:n.toPointMall)||void 0===e||e.call(n,i):exports.isIOS&&(null===(a=null===(r=null===(t=null===(o=window.webkit)||void 0===o?void 0:o.messageHandlers)||void 0===t?void 0:t.gotoPointsMall)||void 0===r?void 0:r.postMessage)||void 0===a||a.call(r,i))}function toNativeLink(i){var n,e,o,t,r=i.androidLink,a=i.iosLink,l=i.otherLink;if((null===(n=window.AndroidNative)||void 0===n?void 0:n.toPointMall)||(null===(t=null===(o=null===(e=window.webkit)||void 0===e?void 0:e.messageHandlers)||void 0===o?void 0:o.gotoPointsMall)||void 0===t?void 0:t.postMessage)){var s=exports.isAndroid?r:a,u=encodeURIComponent(location.href);s=(0,querystring_1.concat)(s,{plt_back_uri:u}),invokeNativePointMall(JSON.stringify({url:s}))}else window.open(l,"_blank","noopener=yes")}function toPlvWebviewBridge(i){return __awaiter(this,void 0,void 0,(function(){var n,e,o,t;return __generator(this,(function(r){switch(r.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(t=r.sent())?(t.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,t,r,a,l,s,u,d,v;return __generator(this,(function(k){switch(k.label){case 0:n=i.linkData,e=i.isWxMiniProgramEnv,o=i.toWxMiniProgram,t=i.openLink,r=i.getLinkParams,a=i.isMobile,l=n.wxMiniprogramLink,s=n.mobileLink,u=n.pcLink,d=(null==a?void 0:a())||!1,v=!1,k.label=1;case 1:return k.trys.push([1,3,,4]),[4,null==e?void 0:e()];case 2:return v=k.sent()||!1,[3,4];case 3:return k.sent(),v=!1,[3,4];case 4:return v&&l&&o?(o(formatLink(l,r)),[2]):d&&s?(t(formatLink(s,r),LinkJumpWay.NewWindow),[2]):(!d&&u&&t(formatLink(u,r),LinkJumpWay.NewWindow),[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.openLink,o=i.isPlvWebview,t=i.getPlvWebviewSmallWindowSize,r=i.getPlvWebviewBridge,a=i.isWxMiniProgramEnv,l=i.toWxMiniProgram,s=i.getLinkParams,u=i.isMobile,d=n.linkType,v=(null==o?void 0:o())||!1;if(d!==LinkType.Native){if(v){var k="",c=n.link,p=n.mobileLink,f=n.mobileAppLink,L=n.wxMiniprogramOriginalId,m=n.wxMiniprogramLink;switch(d){case LinkType.Normal:k=c;break;case LinkType.MultiPlatform:k=f||p}var w=null;return d!==LinkType.Normal&&(w={mobileLink:formatLink(p,s),wxMiniprogramOriginalId:L,wxMiniprogramLink:formatLink(m,s),mobileAppLink:formatLink(f,s)}),void toPlvWebviewBridge({link:formatLink(k,s),data:w,getPlvWebviewSmallWindowSize:t,getPlvWebviewBridge:r})}if(d!==LinkType.Normal)d===LinkType.MultiPlatform&&toMultiPlatformLink({linkData:n,getLinkParams:s,isWxMiniProgramEnv:a,toWxMiniProgram:l,openLink:e,isMobile:u});else{c=n.link;var g=n.jumpWay;e(formatLink(c,s),g)}}else toNativeLink({androidLink:formatLink(n.androidLink,s),iosLink:formatLink(n.iosLink,s),otherLink:formatLink(n.otherLink,s)})}exports.isAndroid=uaInfo.os.isAndroid,exports.isIOS=uaInfo.os.isIOS,function(i){i[i.Normal=10]="Normal",i[i.MultiPlatform=11]="MultiPlatform",i[i.Native=12]="Native"}(LinkType||(exports.LinkType=LinkType={})),function(i){i.PopUp="POP_UP",i.NewWindow="NEW_WINDOW",i.CurrentWindow="CURRENT_WINDOW"}(LinkJumpWay||(exports.LinkJumpWay=LinkJumpWay={}));
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(i,n,o,e){return new(o||(o=Promise))((function(r,t){function a(i){try{l(e.next(i))}catch(i){t(i)}}function s(i){try{l(e.throw(i))}catch(i){t(i)}}function l(i){var n;i.done?r(i.value):(n=i.value,n instanceof o?n:new o((function(i){i(n)}))).then(a,s)}l((e=e.apply(i,n||[])).next())}))},__generator=this&&this.__generator||function(i,n){var o,e,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(o)throw new TypeError("Generator is already executing.");for(;t&&(t=0,s[0]&&(a=0)),a;)try{if(o=1,e&&(r=2&s[0]?e.return:s[0]?e.throw||((r=e.return)&&r.call(e),0):e.next)&&!(r=r.call(e,s[1])).done)return r;switch(e=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++,e=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],e=0}finally{o=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,o=i.iosLink,e=i.androidLink,r=i.harmonyLink,t=i.fallbackUrl,a=i.jumpWay,s=i.openLink,l=Date.now(),u=!1,c=function(){u=!0,window.removeEventListener("blur",c)};if(window.addEventListener("blur",c),console.info("ios\uff1a".concat(exports.isIOS,"\uff0cAndroid\uff1a").concat(exports.isAndroid,"\uff0charmony\uff1a").concat(exports.isHarmony)),exports.isIOS?(console.info("iOSLink",o),n=o):exports.isAndroid?(console.info("Android link",e),n=e):exports.isHarmony&&(console.info("harmony link",r),n=r),!n)return console.info("\u6ca1\u6709\u914d\u7f6e\u591a\u5e73\u53f0\u94fe\u63a5\uff0c\u4f7f\u7528\u964d\u7ea7\u94fe\u63a5",t),void s(t,a);window.location.href=n,setTimeout((function(){console.info("\u8fdb\u5165\u5230\u964d\u7ea7\u903b\u8f91\u4e86"),window.removeEventListener("blur",c);var i=Date.now()-l;!u&&i<3700&&t&&(console.info("\u964d\u7ea7\u7684 url",t,a),s(t,a))}),3500)}function toPlvWebviewBridge(i){return __awaiter(this,void 0,void 0,(function(){var n,o,e,r;return __generator(this,(function(t){switch(t.label){case 0:return n=i.getPlvWebviewSmallWindowSize,o=i.getPlvWebviewBridge,e=(null==n?void 0:n())||{width:90,height:160},[4,null==o?void 0:o()];case 1:return(r=t.sent())?(r.sendData("clickProduct",{width:e.width,height:e.height,newPage:!0,link:i.link,data:i.data}),[2]):[2]}}))}))}function toMultiPlatformLink(i){return __awaiter(this,void 0,void 0,(function(){var n,o,e,r,t,a,s,l,u,c,p,f,k,d,v,m;return __generator(this,(function(w){switch(w.label){case 0:n=i.linkData,o=i.isWxMiniProgramEnv,e=i.toWxMiniProgram,r=i.openLink,t=i.getLinkParams,a=i.isMobile,s=n.wxMiniprogramLink,l=n.pcLink,u=n.iosLink,c=n.androidLink,p=n.harmonyLink,f=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),m=!1,w.label=1;case 1:return w.trys.push([1,3,,4]),[4,null==o?void 0:o()];case 2:return m=w.sent()||!1,[3,4];case 3:return w.sent(),m=!1,[3,4];case 4:return m&&e?(console.info("\u8fdb\u5165\u5230\u5c0f\u7a0b\u5e8f webview \u73af\u5883 wxMiniprogramLink & link",s,f),s?e(formatLink(s,t)):r(formatLink(f,t),k),[2]):v?uaInfo.client.isWx||uaInfo.client.isWxWork||uaInfo.client.isDing||uaInfo.client.isQQ||uaInfo.client.isWeibo||uaInfo.client.isBaiduApp?(r(formatLink(f,t),k),[2]):(openAppWithFallback({iosLink:u,androidLink:c,harmonyLink:p,fallbackUrl:formatLink(d||f,t),jumpWay:k,openLink:r}),[2]):(r(formatLink(l||f,t),k),[2])}}))}))}function formatLink(i,n){var o={};if(n){var e=n(i);o=Object.assign({},o,e)}return(0,querystring_1.concat)(i,o)}function navigateToLink(i){var n=i.linkData,o=i.usePlvWebviewBridge,e=i.openLink,r=i.isPlvWebview,t=i.getPlvWebviewSmallWindowSize,a=i.getPlvWebviewBridge,s=i.isWxMiniProgramEnv,l=i.toWxMiniProgram,u=i.getLinkParams,c=i.isMobile,p=(null==r?void 0:r())||!1;if(console.info("\u662f\u5426\u4fdd\u5229\u5a01 webview \u73af\u5883",p),p){var f=n.link,k=n.iosLink,d=n.androidLink,v=n.harmonyLink,m=n.mobileAppLink,w=n.wxMiniprogramOriginalId,L=n.wxMiniprogramLink,b=n.jumpWay,g=m||f;console.info("\u4fdd\u5229\u5a01 webview \u4e0b\u7684 mobileAppLink\uff0clink",m,f),console.info("\u4fdd\u5229\u5a01 webview \u4e0b usePlvWebviewBridge",o);var h={mobileLink:formatLink(f,u),wxMiniprogramOriginalId:w,wxMiniprogramLink:formatLink(L,u),mobileAppLink:formatLink(m,u)};return o?void toPlvWebviewBridge({link:formatLink(g,u),data:h,getPlvWebviewSmallWindowSize:t,getPlvWebviewBridge:a}):void openAppWithFallback({iosLink:k,androidLink:d,harmonyLink:v,fallbackUrl:formatLink(m||f,u),jumpWay:b,openLink:e})}toMultiPlatformLink({linkData:n,getLinkParams:u,isWxMiniProgramEnv:s,toWxMiniProgram:l,openLink:e,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:_,callbackHandler:s}=o;"function"==typeof s&&s(e,n),"once"===r&&this.off(t,_)}))}destroy(){this.__eventStore={}}}
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={}}}
@@ -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
- type ToPointMallFunc = (params: string) => unknown;
21
- declare global {
22
- interface Window {
23
- AndroidNative?: {
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
- otherLink: string;
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,21 @@ 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
+ jumpWay: LinkJumpWay;
132
+ openLink: (url: string, jumpWay: LinkJumpWay) => void;
133
+ }): void;
153
134
  /**
154
135
  * 格式化链接地址
155
136
  * @param url 需要格式化的链接地址
@@ -162,4 +143,3 @@ export declare function formatLink(url: string, getLinkParams?: (url: string) =>
162
143
  * @param options 跳转配置项
163
144
  */
164
145
  export declare function navigateToLink(options: NavigateToLinkOptions): void;
165
- export {};
@@ -1 +1 @@
1
- var __awaiter=this&&this.__awaiter||function(i,n,o,t){return new(o||(o=Promise))((function(e,a){function r(i){try{d(t.next(i))}catch(i){a(i)}}function l(i){try{d(t.throw(i))}catch(i){a(i)}}function d(i){var n;i.done?e(i.value):(n=i.value,n instanceof o?n:new o((function(i){i(n)}))).then(r,l)}d((t=t.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 var LinkType;!function(i){i[i.Normal=10]="Normal",i[i.MultiPlatform=11]="MultiPlatform",i[i.Native=12]="Native"}(LinkType||(LinkType={}));export var LinkJumpWay;function invokeNativePointMall(i){var n,o,t,e,a,r;isAndroid?null===(o=null===(n=window.AndroidNative)||void 0===n?void 0:n.toPointMall)||void 0===o||o.call(n,i):isIOS&&(null===(r=null===(a=null===(e=null===(t=window.webkit)||void 0===t?void 0:t.messageHandlers)||void 0===e?void 0:e.gotoPointsMall)||void 0===a?void 0:a.postMessage)||void 0===r||r.call(a,i))}function toNativeLink(i){var n,o,t,e;const{androidLink:a,iosLink:r,otherLink:l}=i;if(!(null===(n=window.AndroidNative)||void 0===n?void 0:n.toPointMall)&&!(null===(e=null===(t=null===(o=window.webkit)||void 0===o?void 0:o.messageHandlers)||void 0===t?void 0:t.gotoPointsMall)||void 0===e?void 0:e.postMessage))return void window.open(l,"_blank","noopener=yes");let d=isAndroid?a:r;const k=encodeURIComponent(location.href);d=concat(d,{plt_back_uri:k});invokeNativePointMall(JSON.stringify({url:d}))}function toPlvWebviewBridge(i){return __awaiter(this,void 0,void 0,(function*(){const{getPlvWebviewSmallWindowSize:n,getPlvWebviewBridge:o}=i,t=(null==n?void 0:n())||{width:90,height:160},e=yield null==o?void 0:o();e&&e.sendData("clickProduct",{width:t.width,height:t.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:t,openLink:e,getLinkParams:a,isMobile:r}=i,{wxMiniprogramLink:l,mobileLink:d,pcLink:k}=n,v=(null==r?void 0:r())||!1;let s=!1;try{s=(yield null==o?void 0:o())||!1}catch(i){s=!1}s&&l&&t?t(formatLink(l,a)):v&&d?e(formatLink(d,a),LinkJumpWay.NewWindow):!v&&k&&e(formatLink(k,a),LinkJumpWay.NewWindow)}))}!function(i){i.PopUp="POP_UP",i.NewWindow="NEW_WINDOW",i.CurrentWindow="CURRENT_WINDOW"}(LinkJumpWay||(LinkJumpWay={}));export function formatLink(i,n){let o={};if(n){const t=n(i);o=Object.assign({},o,t)}return concat(i,o)}export function navigateToLink(i){const{linkData:n,openLink:o,isPlvWebview:t,getPlvWebviewSmallWindowSize:e,getPlvWebviewBridge:a,isWxMiniProgramEnv:r,toWxMiniProgram:l,getLinkParams:d,isMobile:k}=i,{linkType:v}=n,s=(null==t?void 0:t())||!1;if(v!==LinkType.Native){if(s){let i="";const{link:o,mobileLink:t,mobileAppLink:r,wxMiniprogramOriginalId:l,wxMiniprogramLink:k}=n;switch(v){case LinkType.Normal:i=o;break;case LinkType.MultiPlatform:i=r||t}let s=null;return v!==LinkType.Normal&&(s={mobileLink:formatLink(t,d),wxMiniprogramOriginalId:l,wxMiniprogramLink:formatLink(k,d),mobileAppLink:formatLink(r,d)}),void toPlvWebviewBridge({link:formatLink(i,d),data:s,getPlvWebviewSmallWindowSize:e,getPlvWebviewBridge:a})}if(v!==LinkType.Normal)v===LinkType.MultiPlatform&&toMultiPlatformLink({linkData:n,getLinkParams:d,isWxMiniProgramEnv:r,toWxMiniProgram:l,openLink:o,isMobile:k});else{const{link:i,jumpWay:t}=n;o(formatLink(i,d),t)}}else toNativeLink({androidLink:formatLink(n.androidLink,d),iosLink:formatLink(n.iosLink,d),otherLink:formatLink(n.otherLink,d)})}
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,jumpWay:r,openLink:a}=i,l=Date.now();let s=!1;const c=()=>{s=!0,window.removeEventListener("blur",c)};let k;if(window.addEventListener("blur",c),console.info(`ios\uff1a${isIOS}\uff0cAndroid\uff1a${isAndroid}\uff0charmony\uff1a${isHarmony}`),isIOS?(console.info("iOSLink",n),k=n):isAndroid?(console.info("Android link",o),k=o):isHarmony&&(console.info("harmony link",e),k=e),!k)return console.info("\u6ca1\u6709\u914d\u7f6e\u591a\u5e73\u53f0\u94fe\u63a5\uff0c\u4f7f\u7528\u964d\u7ea7\u94fe\u63a5",t),void a(t,r);window.location.href=k,setTimeout((()=>{console.info("\u8fdb\u5165\u5230\u964d\u7ea7\u903b\u8f91\u4e86"),window.removeEventListener("blur",c);const i=Date.now()-l;!s&&i<3700&&t&&(console.info("\u964d\u7ea7\u7684 url",t,r),a(t,r))}),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:k,harmonyLink:u,link:d,jumpWay:f,mobileAppLink:m}=n,L=(null==a?void 0:a())||isPortable;console.info("\u8df3\u8f6c\u51fd\u6570\u6536\u5230\u7684\u6570\u636e",n);let p=!1;try{p=(yield null==o?void 0:o())||!1}catch(i){p=!1}if(p&&e)return console.info("\u8fdb\u5165\u5230\u5c0f\u7a0b\u5e8f webview \u73af\u5883 wxMiniprogramLink & link",l,d),void(l?e(formatLink(l,r)):t(formatLink(d,r),f));L?uaInfo.client.isWx||uaInfo.client.isWxWork||uaInfo.client.isDing||uaInfo.client.isQQ||uaInfo.client.isWeibo||uaInfo.client.isBaiduApp?t(formatLink(d,r),f):openAppWithFallback({iosLink:c,androidLink:k,harmonyLink:u,fallbackUrl:formatLink(m||d,r),jumpWay:f,openLink:t}):t(formatLink(s||d,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:k}=i,u=(null==t?void 0:t())||!1;if(console.info("\u662f\u5426\u4fdd\u5229\u5a01 webview \u73af\u5883",u),u){const{link:i,iosLink:t,androidLink:l,harmonyLink:s,mobileAppLink:k,wxMiniprogramOriginalId:u,wxMiniprogramLink:d,jumpWay:f}=n,m=k||i;console.info("\u4fdd\u5229\u5a01 webview \u4e0b\u7684 mobileAppLink\uff0clink",k,i),console.info("\u4fdd\u5229\u5a01 webview \u4e0b usePlvWebviewBridge",o);const L={mobileLink:formatLink(i,c),wxMiniprogramOriginalId:u,wxMiniprogramLink:formatLink(d,c),mobileAppLink:formatLink(k,c)};return o?void toPlvWebviewBridge({link:formatLink(m,c),data:L,getPlvWebviewSmallWindowSize:r,getPlvWebviewBridge:a}):void openAppWithFallback({iosLink:t,androidLink:l,harmonyLink:s,fallbackUrl:formatLink(k||i,c),jumpWay:f,openLink:e})}toMultiPlatformLink({linkData:n,getLinkParams:c,isWxMiniProgramEnv:l,toWxMiniProgram:s,openLink:e,isMobile:k})}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polyv/utils",
3
- "version": "2.16.0",
3
+ "version": "2.18.0",
4
4
  "description": "Utility functions of Polyv frontend development.",
5
5
  "keywords": [
6
6
  "polyv",