1 line
7.3 KiB
JavaScript
1 line
7.3 KiB
JavaScript
(()=>{"use strict";var e={208:function(e,t,n){var i,s,o,r,a,c=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(s,o){function r(e){try{c(i.next(e))}catch(e){o(e)}}function a(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}c((i=i.apply(e,t||[])).next())}))},u=this&&this.__classPrivateFieldGet||function(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)},l=this&&this.__classPrivateFieldSet||function(e,t,n,i,s){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?s.call(e,n):s?s.value=n:t.set(e,n),n};Object.defineProperty(t,"__esModule",{value:!0});const h=n(439);s=new WeakMap,o=new WeakMap,i=new WeakSet,r=function(){this.methodOutputTarget.ready=!1;const e=document.createElement("iframe");e.src=this.frameSrc,e.style.display="none",l(this,s,e,"f"),e.addEventListener("load",(()=>{if(!e.contentWindow)return!1;l(this,o,new h.CrossSiteWindowMessageChannel(e.contentWindow),"f"),u(this,o,"f").send("sync_method",void 0).then((e=>{var t,n;e.forEach((e=>{this.methodOutputTarget[e]=u(this,i,"m",a).call(this,e)})),this.methodOutputTarget.ready=!0,"function"==typeof this.methodOutputTarget.onReady&&(null===(n=(t=this.methodOutputTarget).onReady)||void 0===n||n.call(t))}))})),document.body.appendChild(e)},a=function(e){return t=>c(this,void 0,void 0,(function*(){if(!u(this,o,"f"))throw new Error("sdk not inited.");return yield u(this,o,"f").send("invoke",{apiName:e,args:t})}))},t.default=class{constructor(e,t){i.add(this),this.frameSrc=e,this.methodOutputTarget=t,s.set(this,void 0),o.set(this,void 0),u(this,i,"m",r).call(this)}}},576:function(e,t){var n,i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(s,o){function r(e){try{c(i.next(e))}catch(e){o(e)}}function a(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}c((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.waitAnimationFrame=t.waitTimeout=t.AsyncQueue=t.AsyncMutex=t.createAsyncRef=t.Waiting=t.AsyncValue=void 0,function(e){e[e.PENDING=0]="PENDING",e[e.RESOLVE=1]="RESOLVE",e[e.REJECT=2]="REJECT"}(n||(n={}));class s{constructor(){this.state=n.PENDING,this.resolvePending=null,this.rejectPending=null}get(){return i(this,void 0,void 0,(function*(){return this.state===n.RESOLVE?this.value:this.state===n.REJECT?Promise.reject(this.value):(this.pendingRequest||(this.pendingRequest=new Promise(((e,t)=>{this.resolvePending=e,this.rejectPending=t}))),this.pendingRequest)}))}getSync(){return this.state===n.PENDING?void 0:this.value}set(e,t=!1){if(this.state!==n.PENDING)throw new Error("forbidden: set value more than once");this.value=e,t?(this.state=n.REJECT,this.rejectPending&&this.rejectPending(this.value)):(this.state=n.RESOLVE,this.resolvePending&&this.resolvePending(this.value)),this.resolvePending=null,this.rejectPending=null,this.pendingRequest=null}isPending(){return this.state===n.PENDING}isResolved(){return this.state===n.RESOLVE}isRejected(){return this.state===n.REJECT}}t.AsyncValue=s,t.Waiting=class{constructor(){this.value=new s}waitUntil(e){return i(this,void 0,void 0,(function*(){const t=yield this.value.get();return"function"==typeof e&&(yield e(t)),t}))}done(e){this.value.set(e)}},t.createAsyncRef=function(){const e=new s;return{ref(t){null!=t&&t!==e.getSync()&&e.set(t)},get current(){return e.get()},get currentSync(){return e.getSync()}}},t.AsyncMutex=class{lock(){if(this._lockPromise)throw new Error("mutex is locked!");this._lockPromise=new Promise((e=>{this._resolveHandler=e}))}unlock(){this._resolveHandler(),this._lockPromise=void 0}waitUnlock(){return this._lockPromise}requestLock(){return i(this,void 0,void 0,(function*(){return yield this.waitUnlock(),this.lock()}))}},t.AsyncQueue=class{constructor(){this._queues=[]}requestTask(e){return i(this,void 0,void 0,(function*(){const t=this._queues.length>0?this._queues[this._queues.length-1]:void 0;let n;const i=new Promise((e=>{n=e})),s={resolveHandler:n,taskPromise:i};return this._queues.push(s),t&&(yield null==t?void 0:t.taskPromise),"number"==typeof e&&setTimeout((()=>{this._queues.includes(s)&&n()}),e),{done:()=>{console.assert(s===this._queues.shift()),n()}}}))}},t.waitTimeout=e=>new Promise((t=>{setTimeout(t,e)})),t.waitAnimationFrame=()=>new Promise((e=>{requestAnimationFrame(e)}))},315:function(e,t){var n=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(s,o){function r(e){try{c(i.next(e))}catch(e){o(e)}}function a(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}c((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.BaseWindowMessageChannel=void 0,t.BaseWindowMessageChannel=class{constructor(){this._callbacks={},this._id=String(Date.now())}send(e,t){return n(this,arguments,void 0,(function*(e,t,n={}){throw new Error("unimplented error")}))}on(e,t){this._callbacks[e]&&console.warn("already has "+e),console.debug(`channel received on listener[${e}]`),this._callbacks[e]=t}emit(e,t){if(this._callbacks[e])return this._callbacks[e](t);console.warn(`event ${e} haven't listeners!`,this)}}},439:function(e,t,n){var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(s,o){function r(e){try{c(i.next(e))}catch(e){o(e)}}function a(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}c((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.CrossSiteWindowMessageChannel=void 0;const s=n(576),o=n(315);let r=0;class a extends o.BaseWindowMessageChannel{constructor(e){super(),this.targetWindow=e,this._callbackPromises={},window.addEventListener("message",(e=>i(this,void 0,void 0,(function*(){var t;e.source===this.targetWindow&&("_callback"===e.data.name?(null===(t=this._callbackPromises[e.data._id])||void 0===t||t.set(e.data.content),delete this._callbackPromises[e.data._id]):this._sendCallback(e.data._id,yield this.emit(e.data.name,e.data.content)))}))))}_sendCallback(e,t){this.targetWindow.postMessage({name:"_callback",content:t,_id:e},"*")}static _processMessage(e){return JSON.parse(JSON.stringify(e))}send(e,t){const n=r++;let i={name:e,content:t,_id:n};i=a._processMessage(i),this.targetWindow.postMessage(i,"*");const o=new s.AsyncValue;return this._callbackPromises[n]=o,o.get()}}t.CrossSiteWindowMessageChannel=a},504:function(e,t,n){var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=i(n(208)),o={};window.wxopensdk=o,new s.default("https://open.weixin.qq.com/pcopensdk/frame",o)}},t={};!function n(i){var s=t[i];if(void 0!==s)return s.exports;var o=t[i]={exports:{}};return e[i].call(o.exports,o,o.exports,n),o.exports}(504)})(); |