filesbox/web/dist/js/xmind-embed-viewer.js
2024-07-26 14:10:54 +08:00

2 lines
6.4 KiB
JavaScript

(function(y,v){typeof exports=="object"&&typeof module=="object"?module.exports=v():typeof define=="function"&&define.amd?define([],v):typeof exports=="object"?exports.XMindEmbedViewer=v():y.XMindEmbedViewer=v()})(self,function(){return(()=>{"use strict";var y={61:function(b,l){var h=this&&this.__awaiter||function(u,n,t,o){return new(t||(t=Promise))(function(e,a){function i(s){try{f(o.next(s))}catch(r){a(r)}}function c(s){try{f(o.throw(s))}catch(r){a(r)}}function f(s){var r;s.done?e(s.value):(r=s.value,r instanceof t?r:new t(function(d){d(r)})).then(i,c)}f((o=o.apply(u,n||[])).next())})},m=this&&this.__generator||function(u,n){var t,o,e,a,i={label:0,sent:function(){if(1&e[0])throw e[1];return e[1]},trys:[],ops:[]};return a={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function c(f){return function(s){return function(r){if(t)throw new TypeError("Generator is already executing.");for(;i;)try{if(t=1,o&&(e=2&r[0]?o.return:r[0]?o.throw||((e=o.return)&&e.call(o),0):o.next)&&!(e=e.call(o,r[1])).done)return e;switch(o=0,e&&(r=[2&r[0],e.value]),r[0]){case 0:case 1:e=r;break;case 4:return i.label++,{value:r[1],done:!1};case 5:i.label++,o=r[1],r=[0];continue;case 7:r=i.ops.pop(),i.trys.pop();continue;default:if(!((e=(e=i.trys).length>0&&e[e.length-1])||r[0]!==6&&r[0]!==2)){i=0;continue}if(r[0]===3&&(!e||r[1]>e[0]&&r[1]<e[3])){i.label=r[1];break}if(r[0]===6&&i.label<e[1]){i.label=e[1],e=r;break}if(e&&i.label<e[2]){i.label=e[2],i.ops.push(r);break}e[2]&&i.ops.pop(),i.trys.pop();continue}r=n.call(u,i)}catch(d){r=[6,d],o=0}finally{t=e=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([f,s])}}};Object.defineProperty(l,"__esModule",{value:!0}),l.IframeEventChannelController=void 0;var p=function(){function u(n,t){t===void 0&&(t="*"),this.channel=new MessageChannel,this.eventIndex=0,this.handlers={};var o=n.getIframe();if(o.hasAttribute("data-event-channel-setup"))throw new Error("An embed viewer instance already initialized on the iframe!");o.setAttribute("data-event-channel-setup","true"),this.channelSetupPromise=h(this,void 0,void 0,function(){var e=this;return m(this,function(a){switch(a.label){case 0:return[4,new Promise(function(i){o.addEventListener("load",function(){var c;e.channel.port1.start();var f=function(s){s.data[0]==="channel-ready"&&(s.preventDefault(),e.channel.port1.removeEventListener("message",f),e.channel.port1.addEventListener("message",e.eventDispatcher.bind(e)),i(void 0))};e.channel.port1.addEventListener("message",f),(c=o.contentWindow)===null||c===void 0||c.postMessage(["setup-channel",{port:e.channel.port2}],t||"*",[e.channel.port2])})})];case 1:return a.sent(),[2]}})})}return u.prototype.eventDispatcher=function(n){var t=n.data||[],o=t[0],e=t[1],a=t[2];o==="event"&&e&&this.handlers[e]&&this.handlers[e].forEach(function(i){return i(a)})},u.prototype.addEventListener=function(n,t){this.handlers[n]=this.handlers[n]||[],this.handlers[n].includes(t)||this.handlers[n].push(t)},u.prototype.removeEventListener=function(n,t){if(this.handlers[n]){var o=this.handlers[n].findIndex(function(e){return e===t});this.handlers[n].splice(o,1)}},u.prototype.emit=function(n,t){return h(this,void 0,void 0,function(){var o,e=this;return m(this,function(a){switch(a.label){case 0:return[4,this.channelSetupPromise];case 1:return a.sent(),o="xmind-embed-viewer#"+this.eventIndex++,[4,new Promise(function(i){var c=function(f){var s=f.data,r=s[0],d=s[1];r===o&&(e.channel.port1.removeEventListener("message",c),i(d))};e.channel.port1.addEventListener("message",c),e.channel.port1.postMessage([n,t,o])})];case 2:return a.sent(),[2]}})})},u}();l.IframeEventChannelController=p},860:(b,l)=>{Object.defineProperty(l,"__esModule",{value:!0}),l.IframeController=void 0;var h=function(){function m(p,u){var n,t=typeof p=="string"?document.querySelector(p):p;if(t===null)throw new Error("IFrame or mount element not found by selector "+p);t instanceof HTMLIFrameElement?n=t:(n=document.createElement("iframe"),t.appendChild(n)),n.setAttribute("frameborder","0"),n.setAttribute("scrolling","no"),n.setAttribute("allowfullscreen","true"),n.setAttribute("allow","allowfullscreen"),n.setAttribute("crossorigin","anonymous"),n.setAttribute("src",u),this.iframe=n}return m.prototype.getIframe=function(){return this.iframe},m.prototype.setStyles=function(p){for(var u=this.getIframe(),n=0,t=Object.entries(p);n<t.length;n++){var o=t[n],e=o[0],a=o[1];u.style[e]=a}},m}();l.IframeController=h},341:(b,l,h)=>{l.XMindEmbedViewer=void 0;var m=h(61),p=h(860),u=function(){function n(t){var o=this;this.internalState={sheets:[],zoomScale:100,currentSheetId:""};var e=t.file,a=t.el,i=t.styles,c=i===void 0?{height:"350px",width:"750px"}:i,f=t.isPitchModeDisabled,s=new p.IframeController(a,"https://www.xmind.app/embed-viewer"+(f?"?pitch-mode=disabled":"")),r=new m.IframeEventChannelController(s,"https://www.xmind.app");this.iframeController=s,this.iframeEventChannelController=r,r.addEventListener("sheet-switch",function(d){return o.internalState.currentSheetId=d}),r.addEventListener("zoom-change",function(d){return o.internalState.zoomScale=d}),r.addEventListener("sheets-load",function(d){return o.internalState.sheets=d}),this.iframeController.setStyles(c),e&&this.load(e)}return n.prototype.addEventListener=function(t,o){this.iframeEventChannelController.addEventListener(t,o)},n.prototype.removeEventListener=function(t,o){this.iframeEventChannelController.removeEventListener(t,o)},n.prototype.setStyles=function(t){this.iframeController.setStyles(t)},n.prototype.load=function(t){this.iframeEventChannelController.emit("open-file",t)},n.prototype.setZoomScale=function(t){this.iframeEventChannelController.emit("zoom",t)},n.prototype.setFitMap=function(){this.iframeEventChannelController.emit("fit-map")},n.prototype.switchSheet=function(t){this.iframeEventChannelController.emit("switch-sheet",t)},Object.defineProperty(n.prototype,"zoom",{get:function(){return this.internalState.zoomScale},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"sheets",{get:function(){return JSON.parse(JSON.stringify(this.internalState.sheets))},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"currentSheetId",{get:function(){return this.internalState.currentSheetId},enumerable:!1,configurable:!0}),n}();l.XMindEmbedViewer=u}},v={};return function b(l){if(v[l])return v[l].exports;var h=v[l]={exports:{}};return y[l].call(h.exports,h,h.exports,b),h.exports}(341)})().XMindEmbedViewer});