mazey-wechat-launch-app 2.4.3 → 2.6.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018-2023 Cheng
3
+ Copyright (c) 2018-2026 Cheng
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,5 +1,3 @@
1
- <!-- omit from toc -->
2
-
3
1
  # mazey-wechat-launch-app
4
2
 
5
3
  [![NPM version][npm-image]][npm-url]
@@ -31,10 +29,8 @@
31
29
 
32
30
  ## Install
33
31
 
34
- 使用 [npm](https://www.npmjs.com/package/mazey-wechat-launch-app) 安装 mazey-wechat-launch-app:
35
-
36
32
  ```bash
37
- npm install mazey-wechat-launch-app --save
33
+ npm install mazey-wechat-launch-app
38
34
  ```
39
35
 
40
36
  ## Usage
@@ -100,8 +96,6 @@ app.start({});
100
96
  </script>
101
97
  ```
102
98
 
103
- 提示:如果项目里面已经使用了 jQuery、js-sha1、mazey 依赖库,可以使用体积更小的版本 [`v2.1.4`](https://cdn.jsdelivr.net/npm/mazey-wechat-launch-app@2.1.4/lib/launch-app.min.js)。
104
-
105
99
  ## API
106
100
 
107
101
  ### 参数
@@ -124,6 +118,38 @@ app.start({});
124
118
  | `update` | 更新 | function |
125
119
  | `destroy` | 销毁 | function |
126
120
 
121
+ ### 分享配置与更新
122
+
123
+ 好友分享使用 `updateAppMessageShareDataOptions`,类型为 `UpdateAppMessageShareDataOptions`,包含 `title`、`desc`、`link` 和 `imgUrl`。朋友圈分享使用 `updateTimelineShareDataOptions`,类型为 `UpdateTimelineShareDataOptions`,包含 `title`、`link` 和 `imgUrl`。两种配置都支持可选的 `success` 回调。
124
+
125
+ `success` 表示分享数据设置成功,不表示用户已完成分享。分享链接需符合微信 JS 安全域名要求。
126
+
127
+ `onMenuShareAppMessageOptions`、`onMenuShareTimelineOptions` 和对应旧类型继续兼容,但已标记为 deprecated。每个渠道的新配置不为 `undefined` 时,采用完整的新配置,不合并旧配置字段。旧参数中的 `type`、`dataUrl` 和 `cancel` 不会传给新接口。
128
+
129
+ ```typescript
130
+ const app = LAUNCH_APP({
131
+ weixinJsSdkTicket: 'valid-ticket',
132
+ serviceAccountAppId: 'wx-service',
133
+ updateAppMessageShareDataOptions: {
134
+ title: '分享标题',
135
+ desc: '分享描述',
136
+ link: 'https://example.com/',
137
+ imgUrl: 'https://example.com/icon.png',
138
+ },
139
+ });
140
+
141
+ app.LAUNCH_APP_SHARE_TIMELINE({
142
+ title: '朋友圈标题',
143
+ link: 'https://example.com/',
144
+ imgUrl: 'https://example.com/icon.png',
145
+ });
146
+ app.start({});
147
+ ```
148
+
149
+ 返回值中的 `LAUNCH_APP_SHARE_APP_MESSAGE` 和 `LAUNCH_APP_SHARE_TIMELINE`,与对应的 `window.LAUNCH_APP_*` 属性引用相同函数。工厂创建后即可调用;仍需调用 `start()` 初始化 SDK。ready 前每个渠道只保留最新配置,方法调用优先于工厂初始配置。ready 后调用方法会立即更新分享数据,无需提供 `openPlatformMobileAppId`。未配置的渠道不主动调用 SDK。
150
+
151
+ 参考:[微信 JS-SDK 文档](https://developers.weixin.qq.com/doc/service/guide/h5/jssdk.html)。
152
+
127
153
  ## FAQ
128
154
 
129
155
  **1\. 为什么微信里面通过分享卡片能唤起,直接打开链接却无法唤起的?**
@@ -163,43 +189,13 @@ lockfile for reproducible builds.
163
189
 
164
190
  ### Scripts
165
191
 
166
- Install Dependencies:
192
+ Run `npm install`, then use:
167
193
 
168
- ```bash
169
- npm install
170
- # or: pnpm install
171
- # or: yarn install
172
- ```
173
-
174
- Development:
175
-
176
- ```bash
177
- npm run dev
178
- ```
179
-
180
- Build:
181
-
182
- ```bash
183
- npm run build
184
- ```
185
-
186
- Lint:
187
-
188
- ```bash
189
- npm run lint
190
- ```
191
-
192
- Test:
193
-
194
- ```bash
195
- npm test
196
- ```
197
-
198
- Build and validate the GitHub Pages artifact:
199
-
200
- ```bash
201
- npm run docs
202
- ```
194
+ - `npm run dev` to start the development server.
195
+ - `npm run build` to build the package.
196
+ - `npm run lint` to lint the source.
197
+ - `npm test` to run the tests.
198
+ - `npm run docs` to build and validate the GitHub Pages artifact.
203
199
 
204
200
  ## License
205
201
 
package/lib/index.cjs.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * mazey-wechat-launch-app v2.4.3 https://www.npmjs.com/package/mazey-wechat-launch-app
2
+ * mazey-wechat-launch-app v2.6.0 https://www.npmjs.com/package/mazey-wechat-launch-app
3
3
  * (c) 2018-2026 Cheng
4
4
  * Released under the MIT License.
5
5
  */
6
- "use strict";require("core-js/modules/es.array.concat.js"),require("core-js/modules/es.array.iterator.js"),require("core-js/modules/es.object.assign.js"),require("core-js/modules/es.object.to-string.js"),require("core-js/modules/es.promise.js"),require("core-js/modules/es.string.iterator.js"),require("core-js/modules/web.dom-collections.iterator.js");var e=require("mazey"),n=require("jquery"),a=require("js-sha1"),o=function(){return o=Object.assign||function(e){for(var n,a=1,o=arguments.length;a<o;a++)for(var t in n=arguments[a])Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t]);return e},o.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var t={weixinJsSdkTicket:"",launchContainerQuery:".mazey-launch-app-selector",launchShowWeixinToBrowserImgUrl:"",canShowWeixinToBrowser:!1,extInfo:"",serviceAccountAppId:"",wexinServiceAccountAppId:"",openPlatformMobileAppId:"",genTagPrefixStr:"mazey-launch-app-btn-prefix-",launchShowWeixinToBrowserClassName:"mazey-launch-app-wx-to-browser",launchBtnClassName:"mazey-launch-app-inner-btn",launchBtnStyle:"",launchBtnText:"Launch App <br /><br /><br />",launchErrorLink:"",canContinuousUpdating:!1,onMenuShareTimelineOptions:void 0,onMenuShareAppMessageOptions:void 0,isConClosed:!0,isWxDebug:!1,openTagList:["wx-open-launch-app"],canLaunchApp:function(){return!0},canFireErrorLinkDirectly:function(){return!1},launchBtnClick:function(){},launchReady:function(){}};module.exports=function(r){void 0===r&&(r=t);var i=Object.assign(t,r),c=i.weixinJsSdkTicket,l=i.launchContainerQuery,s=i.genTagPrefixStr,p=i.launchShowWeixinToBrowserImgUrl,u=i.canShowWeixinToBrowser,d=i.launchShowWeixinToBrowserClassName,h=i.launchBtnClassName,g=i.launchBtnStyle,A=i.launchBtnText,f=i.launchErrorLink,w=i.wexinServiceAccountAppId,m=i.openPlatformMobileAppId,_=i.canContinuousUpdating,E=i.onMenuShareTimelineOptions,P=i.onMenuShareAppMessageOptions,v=i.isConClosed,S=i.isWxDebug,y=i.openTagList,x=i.canLaunchApp,L=i.canFireErrorLinkDirectly,k=i.launchBtnClick,I=i.launchReady,C=i.serviceAccountAppId,N=i.extInfo,T=e.genCustomConsole("LaunchCon:",{isClosed:v}),b=window.wx;b||console.error("Launch App: wx is not found");var H=function(){};T.log("Launch App");var U={title:"",link:"",imgUrl:"",success:function(){},cancel:function(){}},O={title:"",desc:"",link:"",imgUrl:"",type:"",dataUrl:"",success:function(){},cancel:function(){}},M={title:document.title,link:location.href};U=o(o({},U),M),O=o(o({},O),M);var R=function(e,n,a){return void 0===e&&(e=""),void 0===n&&(n=""),void 0===a&&(a="button"),"<style>.".concat(h,"{")+"opacity: 0;width: 100%;height: 100%;backgroud: transparent;color: #300f54;border: none;box-sizing: border-box;text-align: center;vertical-align: middle;"+g+n+"}</style>"+"<".concat(a,' class="').concat(h,'"')+(e&&"button"===a?' onclick="'.concat(e,'"'):"")+(e&&"a"===a?' target="_self" href="'.concat(e,'"'):"")+">"+A+"</".concat(a,">")},W=R();function B(){e.addStyle('.mazey-launch-app-mask{position:fixed;top:0;right:0;bottom:0;left:0;background-color:rgba(0, 0, 0, .5);text-align:right;font-size:0;white-space:nowrap;overflow:auto;z-index:999;}.mazey-launch-app-img{display:inline-block;vertical-align:middle;text-align:left;font-size:14px;white-space:normal;width:50vw;margin:0.5rem 0.5rem 0 0;}.mazey-launch-app-img:after{content:"";display:inline-block;height:100%;vertical-align:middle;}',{id:"mazey-launch-app-mask-style"}),window.LAUNCH_APP_HIDE_WEIXIN_BROWSER||(window.LAUNCH_APP_HIDE_WEIXIN_BROWSER=function(){n(".mazey-launch-app-mask").hide()}),0===n(".mazey-launch-app-mask").length?n("body").append("<div class='mazey-launch-app-mask' onclick='window.LAUNCH_APP_HIDE_WEIXIN_BROWSER()'><img "+"class='mazey-launch-app-img ".concat(d,"' ")+"src='".concat(p,"' ")+"alt='Launch App' /></div>"):n(".mazey-launch-app-mask").show()}function j(){T.log("renderWeixinLaunchTemplate"),!C&&w&&(console.warn("wexinServiceAccountAppId will be deprecated, use serviceAccountAppId instead."),C=w),function(t,r){void 0===t&&(t=""),void 0===r&&(r=""),T.log("renderWXOpenLaunchApp"),Promise.all([Promise.resolve(c||window.LAUNCH_APP_WEIXIN_JS_SDK_TICKET||e.getQueryParam("weixinJsSdkTicket")||""),Promise.resolve(a)]).then(function(a){T.log("allRes",a);var i=a[0];if(i){var c=a[1];if(c){var p=e.generateRndNum(7),d=i,h=(new Date).getTime(),g=c("jsapi_ticket="+d+"&noncestr="+p+"&timestamp="+h+"&url="+location.href);return b.config({debug:S,appId:t,timestamp:h,nonceStr:p,signature:g,jsApiList:["showOptionMenu","onMenuShareTimeline","onMenuShareAppMessage"],openTagList:y}),b.ready(function(){if(P&&(T.log("onMenuShareAppMessageOptions",P),b.onMenuShareAppMessage(P)),window.LAUNCH_APP_SHARE_APP_MESSAGE=function(e){e=o(o({},O),e),T.log("window LAUNCH_APP_SHARE_APP_MESSAGE",e),b.onMenuShareAppMessage(e)},E&&(T.log("onMenuShareTimelineOptions",E),b.onMenuShareTimeline(E)),window.LAUNCH_APP_SHARE_TIMELINE=function(e){e=o(o({},U),e),T.log("window LAUNCH_APP_SHARE_TIMELINE",e),b.onMenuShareTimeline(e)},r){window.LAUNCH_APP_READY=!0,I&&I();var e=function(){var e=n(l);T.log("containers",l,e,e.length),e.length>0&&e.each(function(e,a){var o=n(a).attr("data-launch-app-key");if(!o){var t=n(a).parents("[data-launch-app-key]:eq(0)");t.length>0&&(o=t.attr("data-launch-app-key"),T.log("keyEle",t,o))}o||(o=String(e));var i="mazey-launch-app-tag-".concat(o),c=n(".".concat(i," wx-open-launch-app")),l=n(a).attr("data-launch-app-ext-info");if(!l){var p=n(a).parents("[data-launch-app-ext-info]:eq(0)");p.length>0&&(l=p.attr("data-launch-app-ext-info"),T.log("eleExtInfoEle parents",p,l))}l&&(N=l);var d=n(a).attr("data-launch-app-error-link");if(!d){var h=n(a).parents("[data-launch-app-error-link]:eq(0)");h.length>0&&(d=h.attr("data-launch-app-error-link"),T.log("eleErrorLinkEle parents",h,d))}var g=f;d&&(g=d),0===c.length&&(n(a).addClass(i),T.log("success:",i),function(e){var a=s,o=a+e,t="<wx-open-launch-app id='"+o+"' appid='"+r+"' extinfo='".concat(N)+"' style='z-index:99;position:absolute;width:100%;height:100%;opacity:1;background:transparent;overflow:hidden;left:0;'><script type='text/wxtag-template'>"+W+"<\/script></wx-open-launch-app>";n("."+e+":eq(0)").append(t);var i=document.getElementById(o);i&&(i.addEventListener("ready",function(e){T.log("ready event",e)}),i.addEventListener("launch",function(e){T.log("launch event",e),e.detail&&e.detail.extInfo&&T.log("launch extInfo",e.detail.extInfo)}),i.addEventListener("error",function(e){T.error(e.detail),n("[id^='"+a+"']").hide(),u&&B(),g&&(T.log("realErrorLink",g),location.href=g)}),i.addEventListener("click",function(e){T.log("click event",e),k&&k()}))}(i))})};e(),H=e}else T.log("openPlatformMobileAppId is required for weixin launch app")}),b.error(function(e){T.error(e)}),"success:launch_app"}T.error("sha1 is required")}else T.error("weixinJsSdkTicket is required")}).catch(function(e){T.error(e)})}(C,m)}function z(e){if(void 0===e&&(e={}),T.log("appUpdated",e),!window.LAUNCH_APP_LOAD&&x(e)&&(j(),window.LAUNCH_APP_LOAD=!0),_&&window.LAUNCH_APP_LOAD&&x(e)&&H(),L()){var a=n(l);a.length>0&&a.each(function(e,a){var o=n(a).children("."+h);if(!o||!o.length){var t=n(a).attr("data-launch-app-error-link");if(!t){var r=n(a).parents("[data-launch-app-error-link]:eq(0)");r.length>0&&(t=r.attr("data-launch-app-error-link"))}if(t&&"string"==typeof t&&t.length){var i=R(t,"position:absolute;left:0;z-index:999;","a");n(a).append(i)}}})}}function D(){T.log("appBeforeDestroy",D),window.LAUNCH_APP_LOAD=null,window.LAUNCH_APP_HIDE_WEIXIN_BROWSER=null}return window.LAUNCH_APP_UPDATE=z,window.LAUNCH_APP_BEFORE_DESTROY=D,window.LAUNCH_APP_SHOW_WEIXIN_TO_BROWSER=B,{LAUNCH_APP_UPDATE:z,LAUNCH_APP_BEFORE_DESTROY:D,LAUNCH_APP_SHOW_WEIXIN_TO_BROWSER:B,LAUNCH_APP_SHARE_TIMELINE:function(e){T.log("opt",e)},LAUNCH_APP_SHARE_APP_MESSAGE:function(e){T.log("opt",e)},start:z,update:z,destroy:D}};
6
+ "use strict";require("core-js/modules/es.array.concat.js"),require("core-js/modules/es.array.iterator.js"),require("core-js/modules/es.object.assign.js"),require("core-js/modules/es.object.to-string.js"),require("core-js/modules/es.promise.js"),require("core-js/modules/es.string.iterator.js"),require("core-js/modules/es.string.link.js"),require("core-js/modules/web.dom-collections.iterator.js");var e=require("mazey"),n=require("jquery"),t=require("js-sha1");function a(e,n,t){return(n=function(e){var n=function(e,n){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var a=t.call(e,n);if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==typeof n?n:n+""}(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function r(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);n&&(a=a.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),t.push.apply(t,a)}return t}function i(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?r(Object(t),!0).forEach(function(n){a(e,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):r(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))})}return e}var o={weixinJsSdkTicket:"",launchContainerQuery:".mazey-launch-app-selector",launchShowWeixinToBrowserImgUrl:"",canShowWeixinToBrowser:!1,extInfo:"",serviceAccountAppId:"",wexinServiceAccountAppId:"",openPlatformMobileAppId:"",genTagPrefixStr:"mazey-launch-app-btn-prefix-",launchShowWeixinToBrowserClassName:"mazey-launch-app-wx-to-browser",launchBtnClassName:"mazey-launch-app-inner-btn",launchBtnStyle:"",launchBtnText:"Launch App <br /><br /><br />",launchErrorLink:"",canContinuousUpdating:!1,onMenuShareTimelineOptions:void 0,onMenuShareAppMessageOptions:void 0,updateTimelineShareDataOptions:void 0,updateAppMessageShareDataOptions:void 0,isConClosed:!0,isWxDebug:!1,openTagList:["wx-open-launch-app"],canLaunchApp:function(){return!0},canFireErrorLinkDirectly:function(){return!1},launchBtnClick:function(){},launchReady:function(){}};module.exports=function(){var a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:o,r=Object.assign(o,a),c=r.weixinJsSdkTicket,l=r.launchContainerQuery,s=r.genTagPrefixStr,p=r.launchShowWeixinToBrowserImgUrl,u=r.canShowWeixinToBrowser,d=r.launchShowWeixinToBrowserClassName,h=r.launchBtnClassName,g=r.launchBtnStyle,f=r.launchBtnText,m=r.launchErrorLink,w=r.wexinServiceAccountAppId,A=r.openPlatformMobileAppId,v=r.canContinuousUpdating,_=r.onMenuShareTimelineOptions,y=r.onMenuShareAppMessageOptions,P=r.updateTimelineShareDataOptions,E=r.updateAppMessageShareDataOptions,b=r.isConClosed,S=r.isWxDebug,x=r.openTagList,k=r.canLaunchApp,L=r.canFireErrorLinkDirectly,O=r.launchBtnClick,I=r.launchReady,C=r.serviceAccountAppId,j=r.extInfo,T=e.genCustomConsole("LaunchCon:",{isClosed:b}),N=window.wx;N||console.error("Launch App: wx is not found");var D=function(){};T.log("Launch App");var U={title:document.title,link:location.href,imgUrl:""},H=i(i({},U),{},{desc:""}),R=!1,W=void 0!==P?P:_,B=void 0!==E?E:y,z=function(e){var n=e.title,t=e.link,a=e.imgUrl,r=e.success;N.updateTimelineShareData(i({title:n,link:t,imgUrl:a},void 0===r?{}:{success:r}))},q=function(e){var n=e.title,t=e.desc,a=e.link,r=e.imgUrl,o=e.success;N.updateAppMessageShareData(i({title:n,desc:t,link:a,imgUrl:r},void 0===o?{}:{success:o}))},M=function(e){W=i(i({},U),e),R&&z(W)},X=function(e){B=i(i({},H),e),R&&q(B)};window.LAUNCH_APP_SHARE_TIMELINE=M,window.LAUNCH_APP_SHARE_APP_MESSAGE=X;var J=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"button";return"<style>.".concat(h,"{")+"opacity: 0;width: 100%;height: 100%;backgroud: transparent;color: #300f54;border: none;box-sizing: border-box;text-align: center;vertical-align: middle;"+g+n+"}</style>"+"<".concat(t,' class="').concat(h,'"')+(e&&"button"===t?' onclick="'.concat(e,'"'):"")+(e&&"a"===t?' target="_self" href="'.concat(e,'"'):"")+">"+f+"</".concat(t,">")},F=J();function Q(){e.addStyle('.mazey-launch-app-mask{position:fixed;top:0;right:0;bottom:0;left:0;background-color:rgba(0, 0, 0, .5);text-align:right;font-size:0;white-space:nowrap;overflow:auto;z-index:999;}.mazey-launch-app-img{display:inline-block;vertical-align:middle;text-align:left;font-size:14px;white-space:normal;width:50vw;margin:0.5rem 0.5rem 0 0;}.mazey-launch-app-img:after{content:"";display:inline-block;height:100%;vertical-align:middle;}',{id:"mazey-launch-app-mask-style"}),window.LAUNCH_APP_HIDE_WEIXIN_BROWSER||(window.LAUNCH_APP_HIDE_WEIXIN_BROWSER=function(){n(".mazey-launch-app-mask").hide()}),0===n(".mazey-launch-app-mask").length?n("body").append("<div class='mazey-launch-app-mask' onclick='window.LAUNCH_APP_HIDE_WEIXIN_BROWSER()'><img "+"class='mazey-launch-app-img ".concat(d,"' ")+"src='".concat(p,"' ")+"alt='Launch App' /></div>"):n(".mazey-launch-app-mask").show()}function Y(){T.log("renderWeixinLaunchTemplate"),!C&&w&&(console.warn("wexinServiceAccountAppId will be deprecated, use serviceAccountAppId instead."),C=w),function(){var a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";T.log("renderWXOpenLaunchApp"),R=!1,Promise.all([Promise.resolve(c||window.LAUNCH_APP_WEIXIN_JS_SDK_TICKET||e.getQueryParam("weixinJsSdkTicket")||""),Promise.resolve(t)]).then(function(t){T.log("allRes",t);var i=t[0];if(i){var o=t[1];if(o){var c=e.generateRndNum(7),p=i,d=(new Date).getTime(),h=o("jsapi_ticket="+p+"&noncestr="+c+"&timestamp="+d+"&url="+location.href);return N.config({debug:S,appId:a,timestamp:d,nonceStr:c,signature:h,jsApiList:["showOptionMenu","updateTimelineShareData","updateAppMessageShareData"],openTagList:x}),N.ready(function(){if(R=!0,void 0!==B&&q(B),void 0!==W&&z(W),r){window.LAUNCH_APP_READY=!0,I&&I();var e=function(){var e=n(l);T.log("containers",l,e,e.length),e.length>0&&e.each(function(e,t){var a=n(t).attr("data-launch-app-key");if(!a){var i=n(t).parents("[data-launch-app-key]:eq(0)");i.length>0&&(a=i.attr("data-launch-app-key"),T.log("keyEle",i,a))}a||(a=String(e));var o="mazey-launch-app-tag-".concat(a),c=n(".".concat(o," wx-open-launch-app")),l=n(t).attr("data-launch-app-ext-info");if(!l){var p=n(t).parents("[data-launch-app-ext-info]:eq(0)");p.length>0&&(l=p.attr("data-launch-app-ext-info"),T.log("eleExtInfoEle parents",p,l))}l&&(j=l);var d=n(t).attr("data-launch-app-error-link");if(!d){var h=n(t).parents("[data-launch-app-error-link]:eq(0)");h.length>0&&(d=h.attr("data-launch-app-error-link"),T.log("eleErrorLinkEle parents",h,d))}var g=m;d&&(g=d),0===c.length&&(n(t).addClass(o),T.log("success:",o),function(e){var t=s,a=t+e,i="<wx-open-launch-app id='"+a+"' appid='"+r+"' extinfo='".concat(j)+"' style='z-index:99;position:absolute;width:100%;height:100%;opacity:1;background:transparent;overflow:hidden;left:0;'><script type='text/wxtag-template'>"+F+"<\/script></wx-open-launch-app>";n("."+e+":eq(0)").append(i);var o=document.getElementById(a);o&&(o.addEventListener("ready",function(e){T.log("ready event",e)}),o.addEventListener("launch",function(e){T.log("launch event",e),e.detail&&e.detail.extInfo&&T.log("launch extInfo",e.detail.extInfo)}),o.addEventListener("error",function(e){T.error(e.detail),n("[id^='"+t+"']").hide(),u&&Q(),g&&(T.log("realErrorLink",g),location.href=g)}),o.addEventListener("click",function(e){T.log("click event",e),O&&O()}))}(o))})};e(),D=e}else T.log("openPlatformMobileAppId is required for weixin launch app")}),N.error(function(e){T.error(e)}),"success:launch_app"}T.error("sha1 is required")}else T.error("weixinJsSdkTicket is required")}).catch(function(e){T.error(e)})}(C,A)}function G(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(T.log("appUpdated",e),!window.LAUNCH_APP_LOAD&&k(e)&&(Y(),window.LAUNCH_APP_LOAD=!0),v&&window.LAUNCH_APP_LOAD&&k(e)&&D(),L()){var t=n(l);t.length>0&&t.each(function(e,t){var a=n(t).children("."+h);if(!a||!a.length){var r=n(t).attr("data-launch-app-error-link");if(!r){var i=n(t).parents("[data-launch-app-error-link]:eq(0)");i.length>0&&(r=i.attr("data-launch-app-error-link"))}if(r&&"string"==typeof r&&r.length){var o=J(r,"position:absolute;left:0;z-index:999;","a");n(t).append(o)}}})}}function K(){T.log("appBeforeDestroy",K),window.LAUNCH_APP_LOAD=null,window.LAUNCH_APP_HIDE_WEIXIN_BROWSER=null}return window.LAUNCH_APP_UPDATE=G,window.LAUNCH_APP_BEFORE_DESTROY=K,window.LAUNCH_APP_SHOW_WEIXIN_TO_BROWSER=Q,{LAUNCH_APP_UPDATE:G,LAUNCH_APP_BEFORE_DESTROY:K,LAUNCH_APP_SHOW_WEIXIN_TO_BROWSER:Q,LAUNCH_APP_SHARE_TIMELINE:M,LAUNCH_APP_SHARE_APP_MESSAGE:X,start:G,update:G,destroy:K}};
package/lib/index.d.ts CHANGED
@@ -1,10 +1,23 @@
1
+ export interface UpdateTimelineShareDataOptions {
2
+ title: string;
3
+ link: string;
4
+ imgUrl: string;
5
+ /** Called when share data is configured, not when the user shares. */
6
+ success?: () => void;
7
+ }
8
+ export interface UpdateAppMessageShareDataOptions extends UpdateTimelineShareDataOptions {
9
+ desc: string;
10
+ }
11
+ /** @deprecated Use UpdateTimelineShareDataOptions. */
1
12
  export interface MenuShareTimelineOptions {
2
13
  title: string;
3
14
  link: string;
4
15
  imgUrl: string;
16
+ /** Called when share data is configured, not when the user shares. */
5
17
  success: () => void;
6
18
  cancel: () => void;
7
19
  }
20
+ /** @deprecated Use UpdateAppMessageShareDataOptions. */
8
21
  export interface MenuShareAppMessageOptions {
9
22
  title: string;
10
23
  desc: string;
@@ -12,11 +25,12 @@ export interface MenuShareAppMessageOptions {
12
25
  imgUrl: string;
13
26
  type: string;
14
27
  dataUrl: string;
28
+ /** Called when share data is configured, not when the user shares. */
15
29
  success: () => void;
16
30
  cancel: () => void;
17
31
  }
18
- export type LAUNCH_APP_SHARE_TIMELINE = (options: MenuShareTimelineOptions) => void;
19
- export type LAUNCH_APP_SHARE_APP_MESSAGE = (options: MenuShareAppMessageOptions) => void;
32
+ export type LAUNCH_APP_SHARE_TIMELINE = (options: UpdateTimelineShareDataOptions | MenuShareTimelineOptions) => void;
33
+ export type LAUNCH_APP_SHARE_APP_MESSAGE = (options: UpdateAppMessageShareDataOptions | MenuShareAppMessageOptions) => void;
20
34
  export interface retVal {
21
35
  LAUNCH_APP_UPDATE(data: any): void;
22
36
  LAUNCH_APP_BEFORE_DESTROY(): void;
@@ -27,12 +41,7 @@ export interface retVal {
27
41
  update(data: any): void;
28
42
  destroy(): void;
29
43
  }
30
- /**
31
- * Launch App
32
- *
33
- * @returns {void}
34
- */
35
- declare const _default: (options?: {
44
+ export interface LaunchAppOptions {
36
45
  weixinJsSdkTicket?: string;
37
46
  launchContainerQuery?: string;
38
47
  genTagPrefixStr?: string;
@@ -48,8 +57,12 @@ declare const _default: (options?: {
48
57
  wexinServiceAccountAppId?: string;
49
58
  openPlatformMobileAppId?: string;
50
59
  canContinuousUpdating?: boolean;
51
- onMenuShareTimelineOptions?: MenuShareTimelineOptions;
52
- onMenuShareAppMessageOptions?: MenuShareAppMessageOptions;
60
+ updateTimelineShareDataOptions?: UpdateTimelineShareDataOptions | undefined;
61
+ updateAppMessageShareDataOptions?: UpdateAppMessageShareDataOptions | undefined;
62
+ /** @deprecated Use updateTimelineShareDataOptions. */
63
+ onMenuShareTimelineOptions?: MenuShareTimelineOptions | undefined;
64
+ /** @deprecated Use updateAppMessageShareDataOptions. */
65
+ onMenuShareAppMessageOptions?: MenuShareAppMessageOptions | undefined;
53
66
  isConClosed?: boolean;
54
67
  isWxDebug?: boolean;
55
68
  openTagList?: string[];
@@ -57,6 +70,12 @@ declare const _default: (options?: {
57
70
  canFireErrorLinkDirectly?: () => boolean;
58
71
  launchBtnClick?: () => void;
59
72
  launchReady?: () => void;
60
- }) => retVal;
73
+ }
74
+ /**
75
+ * Launch App
76
+ *
77
+ * @returns Lifecycle and share-data methods.
78
+ */
79
+ declare const _default: (options?: LaunchAppOptions) => retVal;
61
80
  export default _default;
62
81
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE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M,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,8BAA8B,CAAC,EAAE,8BAA8B,GAAG,SAAS,CAAC;IAC5E,gCAAgC,CAAC,EAC/B,gCAAgC,GAAG,SAAS,CAAC;IAC/C,sDAAsD;IACtD,0BAA0B,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;IAClE,wDAAwD;IACxD,4BAA4B,CAAC,EAAE,0BAA0B,GAAG,SAAS,CAAC;IACtE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC;IACtC,wBAAwB,CAAC,EAAE,MAAM,OAAO,CAAC;IACzC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;CAC1B;AAkCD;;;;GAIG;yBACa,UAAS,gBAAiC,KAAG,MAAM;AAAnE,wBAmcE"}
package/lib/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * mazey-wechat-launch-app v2.4.3 https://www.npmjs.com/package/mazey-wechat-launch-app
2
+ * mazey-wechat-launch-app v2.6.0 https://www.npmjs.com/package/mazey-wechat-launch-app
3
3
  * (c) 2018-2026 Cheng
4
4
  * Released under the MIT License.
5
5
  */
6
- import"core-js/modules/es.array.concat.js";import"core-js/modules/es.array.iterator.js";import"core-js/modules/es.object.assign.js";import"core-js/modules/es.object.to-string.js";import"core-js/modules/es.promise.js";import"core-js/modules/es.string.iterator.js";import"core-js/modules/web.dom-collections.iterator.js";import{genCustomConsole as e,addStyle as n,generateRndNum as a,getQueryParam as o}from"mazey";import t from"jquery";import i from"js-sha1";var r=function(){return r=Object.assign||function(e){for(var n,a=1,o=arguments.length;a<o;a++)for(var t in n=arguments[a])Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t]);return e},r.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var c={weixinJsSdkTicket:"",launchContainerQuery:".mazey-launch-app-selector",launchShowWeixinToBrowserImgUrl:"",canShowWeixinToBrowser:!1,extInfo:"",serviceAccountAppId:"",wexinServiceAccountAppId:"",openPlatformMobileAppId:"",genTagPrefixStr:"mazey-launch-app-btn-prefix-",launchShowWeixinToBrowserClassName:"mazey-launch-app-wx-to-browser",launchBtnClassName:"mazey-launch-app-inner-btn",launchBtnStyle:"",launchBtnText:"Launch App <br /><br /><br />",launchErrorLink:"",canContinuousUpdating:!1,onMenuShareTimelineOptions:void 0,onMenuShareAppMessageOptions:void 0,isConClosed:!0,isWxDebug:!1,openTagList:["wx-open-launch-app"],canLaunchApp:function(){return!0},canFireErrorLinkDirectly:function(){return!1},launchBtnClick:function(){},launchReady:function(){}},l=function(l){void 0===l&&(l=c);var p=Object.assign(c,l),s=p.weixinJsSdkTicket,u=p.launchContainerQuery,d=p.genTagPrefixStr,h=p.launchShowWeixinToBrowserImgUrl,g=p.canShowWeixinToBrowser,A=p.launchShowWeixinToBrowserClassName,f=p.launchBtnClassName,m=p.launchBtnStyle,w=p.launchBtnText,_=p.launchErrorLink,E=p.wexinServiceAccountAppId,P=p.openPlatformMobileAppId,v=p.canContinuousUpdating,S=p.onMenuShareTimelineOptions,x=p.onMenuShareAppMessageOptions,y=p.isConClosed,L=p.isWxDebug,k=p.openTagList,I=p.canLaunchApp,C=p.canFireErrorLinkDirectly,N=p.launchBtnClick,T=p.launchReady,b=p.serviceAccountAppId,H=p.extInfo,U=e("LaunchCon:",{isClosed:y}),O=window.wx;O||console.error("Launch App: wx is not found");var M=function(){};U.log("Launch App");var R={title:"",link:"",imgUrl:"",success:function(){},cancel:function(){}},W={title:"",desc:"",link:"",imgUrl:"",type:"",dataUrl:"",success:function(){},cancel:function(){}},B={title:document.title,link:location.href};R=r(r({},R),B),W=r(r({},W),B);var j=function(e,n,a){return void 0===e&&(e=""),void 0===n&&(n=""),void 0===a&&(a="button"),"<style>.".concat(f,"{")+"opacity: 0;width: 100%;height: 100%;backgroud: transparent;color: #300f54;border: none;box-sizing: border-box;text-align: center;vertical-align: middle;"+m+n+"}</style>"+"<".concat(a,' class="').concat(f,'"')+(e&&"button"===a?' onclick="'.concat(e,'"'):"")+(e&&"a"===a?' target="_self" href="'.concat(e,'"'):"")+">"+w+"</".concat(a,">")},z=j();function D(){n('.mazey-launch-app-mask{position:fixed;top:0;right:0;bottom:0;left:0;background-color:rgba(0, 0, 0, .5);text-align:right;font-size:0;white-space:nowrap;overflow:auto;z-index:999;}.mazey-launch-app-img{display:inline-block;vertical-align:middle;text-align:left;font-size:14px;white-space:normal;width:50vw;margin:0.5rem 0.5rem 0 0;}.mazey-launch-app-img:after{content:"";display:inline-block;height:100%;vertical-align:middle;}',{id:"mazey-launch-app-mask-style"}),window.LAUNCH_APP_HIDE_WEIXIN_BROWSER||(window.LAUNCH_APP_HIDE_WEIXIN_BROWSER=function(){t(".mazey-launch-app-mask").hide()}),0===t(".mazey-launch-app-mask").length?t("body").append("<div class='mazey-launch-app-mask' onclick='window.LAUNCH_APP_HIDE_WEIXIN_BROWSER()'><img "+"class='mazey-launch-app-img ".concat(A,"' ")+"src='".concat(h,"' ")+"alt='Launch App' /></div>"):t(".mazey-launch-app-mask").show()}function q(){U.log("renderWeixinLaunchTemplate"),!b&&E&&(console.warn("wexinServiceAccountAppId will be deprecated, use serviceAccountAppId instead."),b=E),function(e,n){void 0===e&&(e=""),void 0===n&&(n=""),U.log("renderWXOpenLaunchApp"),Promise.all([Promise.resolve(s||window.LAUNCH_APP_WEIXIN_JS_SDK_TICKET||o("weixinJsSdkTicket")||""),Promise.resolve(i)]).then(function(o){U.log("allRes",o);var i=o[0];if(i){var c=o[1];if(c){var l=a(7),p=i,s=(new Date).getTime(),h=c("jsapi_ticket="+p+"&noncestr="+l+"&timestamp="+s+"&url="+location.href);return O.config({debug:L,appId:e,timestamp:s,nonceStr:l,signature:h,jsApiList:["showOptionMenu","onMenuShareTimeline","onMenuShareAppMessage"],openTagList:k}),O.ready(function(){if(x&&(U.log("onMenuShareAppMessageOptions",x),O.onMenuShareAppMessage(x)),window.LAUNCH_APP_SHARE_APP_MESSAGE=function(e){e=r(r({},W),e),U.log("window LAUNCH_APP_SHARE_APP_MESSAGE",e),O.onMenuShareAppMessage(e)},S&&(U.log("onMenuShareTimelineOptions",S),O.onMenuShareTimeline(S)),window.LAUNCH_APP_SHARE_TIMELINE=function(e){e=r(r({},R),e),U.log("window LAUNCH_APP_SHARE_TIMELINE",e),O.onMenuShareTimeline(e)},n){window.LAUNCH_APP_READY=!0,T&&T();var e=function(){var e=t(u);U.log("containers",u,e,e.length),e.length>0&&e.each(function(e,a){var o=t(a).attr("data-launch-app-key");if(!o){var i=t(a).parents("[data-launch-app-key]:eq(0)");i.length>0&&(o=i.attr("data-launch-app-key"),U.log("keyEle",i,o))}o||(o=String(e));var r="mazey-launch-app-tag-".concat(o),c=t(".".concat(r," wx-open-launch-app")),l=t(a).attr("data-launch-app-ext-info");if(!l){var p=t(a).parents("[data-launch-app-ext-info]:eq(0)");p.length>0&&(l=p.attr("data-launch-app-ext-info"),U.log("eleExtInfoEle parents",p,l))}l&&(H=l);var s=t(a).attr("data-launch-app-error-link");if(!s){var u=t(a).parents("[data-launch-app-error-link]:eq(0)");u.length>0&&(s=u.attr("data-launch-app-error-link"),U.log("eleErrorLinkEle parents",u,s))}var h=_;s&&(h=s),0===c.length&&(t(a).addClass(r),U.log("success:",r),function(e){var a=d,o=a+e,i="<wx-open-launch-app id='"+o+"' appid='"+n+"' extinfo='".concat(H)+"' style='z-index:99;position:absolute;width:100%;height:100%;opacity:1;background:transparent;overflow:hidden;left:0;'><script type='text/wxtag-template'>"+z+"<\/script></wx-open-launch-app>";t("."+e+":eq(0)").append(i);var r=document.getElementById(o);r&&(r.addEventListener("ready",function(e){U.log("ready event",e)}),r.addEventListener("launch",function(e){U.log("launch event",e),e.detail&&e.detail.extInfo&&U.log("launch extInfo",e.detail.extInfo)}),r.addEventListener("error",function(e){U.error(e.detail),t("[id^='"+a+"']").hide(),g&&D(),h&&(U.log("realErrorLink",h),location.href=h)}),r.addEventListener("click",function(e){U.log("click event",e),N&&N()}))}(r))})};e(),M=e}else U.log("openPlatformMobileAppId is required for weixin launch app")}),O.error(function(e){U.error(e)}),"success:launch_app"}U.error("sha1 is required")}else U.error("weixinJsSdkTicket is required")}).catch(function(e){U.error(e)})}(b,P)}function X(e){if(void 0===e&&(e={}),U.log("appUpdated",e),!window.LAUNCH_APP_LOAD&&I(e)&&(q(),window.LAUNCH_APP_LOAD=!0),v&&window.LAUNCH_APP_LOAD&&I(e)&&M(),C()){var n=t(u);n.length>0&&n.each(function(e,n){var a=t(n).children("."+f);if(!a||!a.length){var o=t(n).attr("data-launch-app-error-link");if(!o){var i=t(n).parents("[data-launch-app-error-link]:eq(0)");i.length>0&&(o=i.attr("data-launch-app-error-link"))}if(o&&"string"==typeof o&&o.length){var r=j(o,"position:absolute;left:0;z-index:999;","a");t(n).append(r)}}})}}function J(){U.log("appBeforeDestroy",J),window.LAUNCH_APP_LOAD=null,window.LAUNCH_APP_HIDE_WEIXIN_BROWSER=null}return window.LAUNCH_APP_UPDATE=X,window.LAUNCH_APP_BEFORE_DESTROY=J,window.LAUNCH_APP_SHOW_WEIXIN_TO_BROWSER=D,{LAUNCH_APP_UPDATE:X,LAUNCH_APP_BEFORE_DESTROY:J,LAUNCH_APP_SHOW_WEIXIN_TO_BROWSER:D,LAUNCH_APP_SHARE_TIMELINE:function(e){U.log("opt",e)},LAUNCH_APP_SHARE_APP_MESSAGE:function(e){U.log("opt",e)},start:X,update:X,destroy:J}};export{l as default};
6
+ import"core-js/modules/es.array.concat.js";import"core-js/modules/es.array.iterator.js";import"core-js/modules/es.object.assign.js";import"core-js/modules/es.object.to-string.js";import"core-js/modules/es.promise.js";import"core-js/modules/es.string.iterator.js";import"core-js/modules/es.string.link.js";import"core-js/modules/web.dom-collections.iterator.js";import{genCustomConsole as e,addStyle as n,generateRndNum as t,getQueryParam as a}from"mazey";import r from"jquery";import i from"js-sha1";function o(e,n,t){return(n=function(e){var n=function(e,n){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var a=t.call(e,n);if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==typeof n?n:n+""}(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function c(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);n&&(a=a.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),t.push.apply(t,a)}return t}function l(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?c(Object(t),!0).forEach(function(n){o(e,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):c(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))})}return e}var p={weixinJsSdkTicket:"",launchContainerQuery:".mazey-launch-app-selector",launchShowWeixinToBrowserImgUrl:"",canShowWeixinToBrowser:!1,extInfo:"",serviceAccountAppId:"",wexinServiceAccountAppId:"",openPlatformMobileAppId:"",genTagPrefixStr:"mazey-launch-app-btn-prefix-",launchShowWeixinToBrowserClassName:"mazey-launch-app-wx-to-browser",launchBtnClassName:"mazey-launch-app-inner-btn",launchBtnStyle:"",launchBtnText:"Launch App <br /><br /><br />",launchErrorLink:"",canContinuousUpdating:!1,onMenuShareTimelineOptions:void 0,onMenuShareAppMessageOptions:void 0,updateTimelineShareDataOptions:void 0,updateAppMessageShareDataOptions:void 0,isConClosed:!0,isWxDebug:!1,openTagList:["wx-open-launch-app"],canLaunchApp:function(){return!0},canFireErrorLinkDirectly:function(){return!1},launchBtnClick:function(){},launchReady:function(){}},s=function(){var o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:p,c=Object.assign(p,o),s=c.weixinJsSdkTicket,u=c.launchContainerQuery,d=c.genTagPrefixStr,h=c.launchShowWeixinToBrowserImgUrl,g=c.canShowWeixinToBrowser,f=c.launchShowWeixinToBrowserClassName,m=c.launchBtnClassName,w=c.launchBtnStyle,A=c.launchBtnText,v=c.launchErrorLink,_=c.wexinServiceAccountAppId,y=c.openPlatformMobileAppId,P=c.canContinuousUpdating,E=c.onMenuShareTimelineOptions,b=c.onMenuShareAppMessageOptions,S=c.updateTimelineShareDataOptions,x=c.updateAppMessageShareDataOptions,k=c.isConClosed,L=c.isWxDebug,O=c.openTagList,I=c.canLaunchApp,C=c.canFireErrorLinkDirectly,j=c.launchBtnClick,T=c.launchReady,N=c.serviceAccountAppId,D=c.extInfo,U=e("LaunchCon:",{isClosed:k}),H=window.wx;H||console.error("Launch App: wx is not found");var W=function(){};U.log("Launch App");var B={title:document.title,link:location.href,imgUrl:""},R=l(l({},B),{},{desc:""}),z=!1,M=void 0!==S?S:E,q=void 0!==x?x:b,X=function(e){var n=e.title,t=e.link,a=e.imgUrl,r=e.success;H.updateTimelineShareData(l({title:n,link:t,imgUrl:a},void 0===r?{}:{success:r}))},J=function(e){var n=e.title,t=e.desc,a=e.link,r=e.imgUrl,i=e.success;H.updateAppMessageShareData(l({title:n,desc:t,link:a,imgUrl:r},void 0===i?{}:{success:i}))},F=function(e){M=l(l({},B),e),z&&X(M)},Y=function(e){q=l(l({},R),e),z&&J(q)};window.LAUNCH_APP_SHARE_TIMELINE=F,window.LAUNCH_APP_SHARE_APP_MESSAGE=Y;var G=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"button";return"<style>.".concat(m,"{")+"opacity: 0;width: 100%;height: 100%;backgroud: transparent;color: #300f54;border: none;box-sizing: border-box;text-align: center;vertical-align: middle;"+w+n+"}</style>"+"<".concat(t,' class="').concat(m,'"')+(e&&"button"===t?' onclick="'.concat(e,'"'):"")+(e&&"a"===t?' target="_self" href="'.concat(e,'"'):"")+">"+A+"</".concat(t,">")},K=G();function Q(){n('.mazey-launch-app-mask{position:fixed;top:0;right:0;bottom:0;left:0;background-color:rgba(0, 0, 0, .5);text-align:right;font-size:0;white-space:nowrap;overflow:auto;z-index:999;}.mazey-launch-app-img{display:inline-block;vertical-align:middle;text-align:left;font-size:14px;white-space:normal;width:50vw;margin:0.5rem 0.5rem 0 0;}.mazey-launch-app-img:after{content:"";display:inline-block;height:100%;vertical-align:middle;}',{id:"mazey-launch-app-mask-style"}),window.LAUNCH_APP_HIDE_WEIXIN_BROWSER||(window.LAUNCH_APP_HIDE_WEIXIN_BROWSER=function(){r(".mazey-launch-app-mask").hide()}),0===r(".mazey-launch-app-mask").length?r("body").append("<div class='mazey-launch-app-mask' onclick='window.LAUNCH_APP_HIDE_WEIXIN_BROWSER()'><img "+"class='mazey-launch-app-img ".concat(f,"' ")+"src='".concat(h,"' ")+"alt='Launch App' /></div>"):r(".mazey-launch-app-mask").show()}function V(){U.log("renderWeixinLaunchTemplate"),!N&&_&&(console.warn("wexinServiceAccountAppId will be deprecated, use serviceAccountAppId instead."),N=_),function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";U.log("renderWXOpenLaunchApp"),z=!1,Promise.all([Promise.resolve(s||window.LAUNCH_APP_WEIXIN_JS_SDK_TICKET||a("weixinJsSdkTicket")||""),Promise.resolve(i)]).then(function(a){U.log("allRes",a);var i=a[0];if(i){var o=a[1];if(o){var c=t(7),l=i,p=(new Date).getTime(),s=o("jsapi_ticket="+l+"&noncestr="+c+"&timestamp="+p+"&url="+location.href);return H.config({debug:L,appId:e,timestamp:p,nonceStr:c,signature:s,jsApiList:["showOptionMenu","updateTimelineShareData","updateAppMessageShareData"],openTagList:O}),H.ready(function(){if(z=!0,void 0!==q&&J(q),void 0!==M&&X(M),n){window.LAUNCH_APP_READY=!0,T&&T();var e=function(){var e=r(u);U.log("containers",u,e,e.length),e.length>0&&e.each(function(e,t){var a=r(t).attr("data-launch-app-key");if(!a){var i=r(t).parents("[data-launch-app-key]:eq(0)");i.length>0&&(a=i.attr("data-launch-app-key"),U.log("keyEle",i,a))}a||(a=String(e));var o="mazey-launch-app-tag-".concat(a),c=r(".".concat(o," wx-open-launch-app")),l=r(t).attr("data-launch-app-ext-info");if(!l){var p=r(t).parents("[data-launch-app-ext-info]:eq(0)");p.length>0&&(l=p.attr("data-launch-app-ext-info"),U.log("eleExtInfoEle parents",p,l))}l&&(D=l);var s=r(t).attr("data-launch-app-error-link");if(!s){var u=r(t).parents("[data-launch-app-error-link]:eq(0)");u.length>0&&(s=u.attr("data-launch-app-error-link"),U.log("eleErrorLinkEle parents",u,s))}var h=v;s&&(h=s),0===c.length&&(r(t).addClass(o),U.log("success:",o),function(e){var t=d,a=t+e,i="<wx-open-launch-app id='"+a+"' appid='"+n+"' extinfo='".concat(D)+"' style='z-index:99;position:absolute;width:100%;height:100%;opacity:1;background:transparent;overflow:hidden;left:0;'><script type='text/wxtag-template'>"+K+"<\/script></wx-open-launch-app>";r("."+e+":eq(0)").append(i);var o=document.getElementById(a);o&&(o.addEventListener("ready",function(e){U.log("ready event",e)}),o.addEventListener("launch",function(e){U.log("launch event",e),e.detail&&e.detail.extInfo&&U.log("launch extInfo",e.detail.extInfo)}),o.addEventListener("error",function(e){U.error(e.detail),r("[id^='"+t+"']").hide(),g&&Q(),h&&(U.log("realErrorLink",h),location.href=h)}),o.addEventListener("click",function(e){U.log("click event",e),j&&j()}))}(o))})};e(),W=e}else U.log("openPlatformMobileAppId is required for weixin launch app")}),H.error(function(e){U.error(e)}),"success:launch_app"}U.error("sha1 is required")}else U.error("weixinJsSdkTicket is required")}).catch(function(e){U.error(e)})}(N,y)}function Z(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(U.log("appUpdated",e),!window.LAUNCH_APP_LOAD&&I(e)&&(V(),window.LAUNCH_APP_LOAD=!0),P&&window.LAUNCH_APP_LOAD&&I(e)&&W(),C()){var n=r(u);n.length>0&&n.each(function(e,n){var t=r(n).children("."+m);if(!t||!t.length){var a=r(n).attr("data-launch-app-error-link");if(!a){var i=r(n).parents("[data-launch-app-error-link]:eq(0)");i.length>0&&(a=i.attr("data-launch-app-error-link"))}if(a&&"string"==typeof a&&a.length){var o=G(a,"position:absolute;left:0;z-index:999;","a");r(n).append(o)}}})}}function $(){U.log("appBeforeDestroy",$),window.LAUNCH_APP_LOAD=null,window.LAUNCH_APP_HIDE_WEIXIN_BROWSER=null}return window.LAUNCH_APP_UPDATE=Z,window.LAUNCH_APP_BEFORE_DESTROY=$,window.LAUNCH_APP_SHOW_WEIXIN_TO_BROWSER=Q,{LAUNCH_APP_UPDATE:Z,LAUNCH_APP_BEFORE_DESTROY:$,LAUNCH_APP_SHOW_WEIXIN_TO_BROWSER:Q,LAUNCH_APP_SHARE_TIMELINE:F,LAUNCH_APP_SHARE_APP_MESSAGE:Y,start:Z,update:Z,destroy:$}};export{s as default};