1 line
19 KiB
JavaScript
1 line
19 KiB
JavaScript
|
|
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.dd=e():t.dd=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=5)}([function(t,e,n){"use strict";var r=n(2),o=n(3),i=n(1),u=n(4),c=new i,a=!1,s="",f=null,l=[".dingtalk.com","7ding.ai"],p={},h=/{.*}/;try{if(window.dd_bridge_config)var d=window.dd_bridge_config.match(h);else var d=window.name.match(h);if(d&&d[0])var p=JSON.parse(d[0])}catch(t){p={}}if(p.hostOrigin){var v=p.hostOrigin.split(":")[1];l.forEach(function(t){v.slice(0-t.length)===t&&p.containerId&&(a=!0,s=p.hostOrigin,f=p.containerId)})}var y={},_=new Promise(function(t,e){y._resolve=t,y._reject=e}),b={},g=null;window.top!==window?(g=p.corsIframe?window:window.top,y._resolve()):"object"==typeof dingtalk&&"object"==typeof dingtalk.platform&&"function"==typeof dingtalk.platform.invokeAPI&&(g=window,y._resolve()),b[u.SYS_INIT]=function(t){g=t.frameWindow,y._resolve(),t.respond({})},window.addEventListener("message",function(t){var e=t.data,n=t.origin;if(n===s)if("response"===e.type&&e.msgId){var r=e.msgId,i=c.getMsyById(r);i&&i.methodName!==u.SYS_EVENT&&i.receiveResponse(e.body,!e.success)}else if("event"===e.type&&e.msgId){var r=e.msgId,i=c.getMsyById(r);i&&i.receiveEvent(e.eventName,e.body)}else if("request"===e.type&&e.msgId){var i=new o(t.source,n,e);b[i.methodName]&&b[i.methodName](i)}}),e.invokeAPI=function(t,e){var n=new r(f,t,e);return a&&_.then(function(){g&&g.postMessage(n.getPayload(),s),c.addPending(n)}),n};var m=null;e.addEventListener=function(t,n){m||(m=e.invokeAPI(u.SYS_EVENT,{})),m.addEventListener(t,n)},e.removeEventListener=function(t,e){m&&m.removeEventListener(t,e)}},function(t,e,n){"use strict";var r=function(){this.pendingMsgs={}};r.prototype.addPending=function(t){this.pendingMsgs[t.id]=t;var e=function(){delete this.pendingMsgs[t.id],t.removeEventListener("_finish",e)}.bind(this);t.addEventListener("_finish",e)},r.prototype.getMsyById=function(t){return this.pendingMsgs[t]},t.exports=r},function(t,e,n){"use strict";var r=n(8),o=n(7),i=0,u=Math.floor(1e3*Math.random()),c=function(){return 1e3*(1e3*u+Math.floor(1e3*Math.random()))+ ++i%1e3},a={code:408,reason:"timeout"},s={TIMEOUT:"_timeout",FINISH:"_finish"},f={timeout:-1},l=function(t,e,n,r){this.id=c(),this.methodName=e,this.containerId=t,this.option=o({},f,r);var n=n||{};this._p={},this.result=new Promise(function(t,e){this._p._resolve=t,this._p._reject=e}.bind(this)),this.callbacks={},this.plainMsg=this._handleMsg(n),this._eventsHandle={},this._timeoutTimer=null,this._initTimeout(),this.isFinish=!1};l.prototype._initTimeout=function(){this._clearTimeout(),this.option.timeout>0&&(this._timeoutTimer=setTimeout(function(){this.receiveEvent(s.TIMEOUT),this.receiveResponse(a,!0)}.bind(this),this.option.timeout))},l.prototype._clearTimeout=function(){clearTimeout(this._timeoutTimer)},l.prototype._handleMsg=function(t){var e={};return Object.keys(t).forEach(function(n){var o=t[n];"function"==typeof o&&"on"===n.slice(0,2)?this.callbacks[n]=o:e[n]=r(o)}.bind(this)),e},l.prototype.getPayload=function(){return{msgId:this.id,containerId:this.containerId,methodName:this.methodName,body:this.plainMsg,type:"request"}},l.prototype.receiveEvent=function(t,e){if(this.isFinish&&t!==s.FINISH)return!1;t!==s.FINISH&&t!==s.TIMEOUT&&this._initTimeout(),Array.isArray(this._eventsHandle[t])&&this._eventsHandle[t].forEach(function(t){try{t(e)}catch(t){console.error(e)}});var n="on"+t.charAt(0).toUpperCase()+t.slice(1);return this.callbacks[n]&&this.callbacks[n](e),!0},l.prototype.addEventList
|