travel/admin/node_modules/tui-editor/dist/tui-editor-extScrollSync.mi...

7 lines
12 KiB
JavaScript

/*!
* tui-editor
* @version 1.3.3
* @author NHN Ent. FE Development Lab <dl_javascript@nhnent.com> (https://nhnent.github.io/tui.editor/)
* @license MIT
*/
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("jquery"),require("tui-code-snippet"),function(){try{return require("tui-editor")}catch(e){}}(),function(){try{return require("tui-editor/dist/tui-editor-Viewer")}catch(e){}}());else if("function"==typeof define&&define.amd)define(["jquery","tui-code-snippet","tui-editor","tui-editor/dist/tui-editor-Viewer"],t);else{var i="object"==typeof exports?t(require("jquery"),require("tui-code-snippet"),function(){try{return require("tui-editor")}catch(e){}}(),function(){try{return require("tui-editor/dist/tui-editor-Viewer")}catch(e){}}()):t(e.$,e.tui&&e.tui.util,e.tui&&e.tui.Editor,e.tui&&e.tui.Editor);for(var n in i)("object"==typeof exports?exports:e)[n]=i[n]}}("undefined"!=typeof self?self:this,function(e,t,i,n){return function(e){function t(n){if(i[n])return i[n].exports;var o=i[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var i={};return t.m=e,t.c=i,t.d=function(e,i,n){t.o(e,i)||Object.defineProperty(e,i,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var i=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(i,"a",i),i},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="dist/",t(t.s=46)}({0:function(t,i){t.exports=e},1:function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=void 0;try{n=i(4)}catch(e){}if(!n)try{n=i(5)}catch(e){}t.default=n},2:function(e,i){e.exports=t},4:function(e,t){if(void 0===i){var n=new Error('Cannot find module "undefined"');throw n.code="MODULE_NOT_FOUND",n}e.exports=i},46:function(e,t,i){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e){function t(){"vertical"===e.mdPreviewStyle&&"markdown"===e.currentMode?(d.$el.show(),h.show()):(d.$el.hide(),h.hide())}var i=e.i18n,n={active:i.get("Auto scroll enabled"),inactive:i.get("Auto scroll disabled")};if(!e.isViewer()){var o=e.getCodeMirror(),r=new f.default(o,e.preview),s=new u.default(r,o,e.preview.$el),l=!1,a=!0,d=void 0,h=void 0;if("default"===e.getUI().name){var v=e.getUI().getToolbar();v.addItem("divider"),v.addItem({type:"button",options:{className:"tui-scrollsync",command:"scrollSyncToggle",tooltip:n.active,$el:(0,c.default)('<button class="active tui-scrollsync" type="button"></button>')}});var p=v.getItems();h=p[p.length-2].$el,d=p[p.length-1],t(),e.on("changeMode",t),e.on("changePreviewStyle",t),e.addCommand("markdown",{name:"scrollSyncToggle",exec:function(){a=!a,d._onOut(),a?(d.$el.addClass("active"),d.setTooltip(n.active)):(d.$el.removeClass("active"),d.setTooltip(n.inactive)),d._onOver()}})}o.on("change",function(){l=!1,r.makeSectionList()}),e.on("previewRenderAfter",function(){r.sectionMatch(),a&&s.syncPreviewScrollTopToMarkdown(),l=!0}),e.eventManager.listen("scroll",function(t){a&&(l&&e.preview.isVisible()?"markdown"!==t.source||s.isMarkdownScrollEventBlocked?"preview"!==t.source||s.isPreviewScrollEventBlocked||s.syncMarkdownScrollTopToPreview():s.syncPreviewScrollTopToMarkdown():s.saveScrollInfo())})}}Object.defineProperty(t,"__esModule",{value:!0});var r=i(0),c=n(r),s=i(1),l=n(s),a=i(47),u=n(a),d=i(48),f=n(d);l.default.defineExtension("scrollSync",o),t.default=o},47:function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),t}}(),r=i(2),c=function(e){return e&&e.__esModule?e:{default:e}}(r),s=function(){function e(t,i,o){n(this,e),this.sectionManager=t,this.cm=i,this.$previewContainerEl=o,this.$contents=this.$previewContainerEl.find(".tui-editor-contents"),this.releaseTimer=null,this._currentTimeoutId=null,this._savedScrollInfo=null}return o(e,[{key:"_getEditorSectionHeight",value:function(e){var t=this.cm.heightAtLine(e.end,"local");return t-=this.cm.heightAtLine(e.start>0?e.start-1:0,"local")}},{key:"_getEditorLineHeightGapInSection",value:function(e,t){var i=this.cm.heightAtLine(t,"local");return i-=this.cm.heightAtLine(e.start>0?e.start-1:0,"local"),Math.max(i,0)}},{key:"_getEditorSectionScrollRatio",value:function(e,t){var i=e.end===e.start;return i?0:this._getEditorLineHeightGapInSection(e,t)/this._getEditorSectionHeight(e)}},{key:"_getScrollFactorsOfEditor",value:function(){var e=this.cm,t=e.getScrollInfo(),i=void 0,n=void 0,o=void 0,r=void 0;t=this._fallbackScrollInfoIfIncorrect(t);var c=t.height-t.top<=t.clientHeight;return c?r={isEditorBottom:c}:(i=e.coordsChar({left:t.left,top:t.top},"local").line,n=this.sectionManager.sectionByLine(i),o=this._getEditorSectionScrollRatio(n,i),r={section:n,sectionRatio:o}),r}},{key:"_getScrollInfoForMarkdown",value:function(){var e=this,t=this.sectionManager.getSectionList(),i=void 0;return c.default.forEachArray(t,function(t){var n=t.$previewSectionEl,o=n.parent().parent(),r=o[0].clientHeight-o.scrollTop()<=o[0].height,c=!0;return r?(i={isPreviewBottom:r},c=!1):e._isTopSection(o,n)&&(i={section:t,sectionRatio:e._getMarkdownEditorScrollRatio(o,n)},c=!1),c}),i}},{key:"_getMarkdownEditorScrollRatio",value:function(e,t){return(e.scrollTop()-t[0].offsetTop)/t.height()}},{key:"_getScrollTopForPreview",value:function(){var e=void 0,t=this._getScrollFactorsOfEditor(),i=t.section,n=t.sectionRatio;return t.isEditorBottom?e=this.$contents.height():i.$previewSectionEl&&(e=i.$previewSectionEl[0].offsetTop,e+=i.$previewSectionEl.height()*n-20),e=e&&Math.max(e,0)}},{key:"_getScrollTopForMarkdown",value:function(){var e=void 0,t=this._getScrollInfoForMarkdown(),i=t.sectionRatio;if(t.isPreviewBottom)e=this.cm.getScrollInfo().height;else if(t.section){var n=t.section,o=this.cm.charCoords({line:n.start,char:0},"local"),r=this.cm.charCoords({line:n.end,char:0},"local");e=o.top,e+=(r.top-o.top)*i}return e=e&&Math.max(e,0)}},{key:"syncPreviewScrollTopToMarkdown",value:function(){var e=this,t=this.$previewContainerEl,i=t.scrollTop(),n=this._getScrollTopForPreview();this.isPreviewScrollEventBlocked=!0,this._animateRun(i,n,function(i){clearTimeout(e.releaseTimer),t.scrollTop(i),e.releaseTimer=setTimeout(function(){e.isPreviewScrollEventBlocked=!1},15)})}},{key:"syncMarkdownScrollTopToPreview",value:function(){var e=this,t=this.cm,i=t.getScrollInfo(),n=i.top,o=this._getScrollTopForMarkdown();this.isMarkdownScrollEventBlocked=!0,this._animateRun(n,o,function(i){clearTimeout(e.releaseTimer),t.scrollTo(0,i),e.releaseTimer=setTimeout(function(){e.isMarkdownScrollEventBlocked=!1},15)})}},{key:"_animateRun",value:function(e,t,i){function n(){var s=Date.now(),l=(s-r)/200,a=void 0;l<1?(a=e+o*Math.cos((1-l)*Math.PI/2),i(Math.ceil(a)),c._currentTimeoutId=setTimeout(n,1)):(i(t),c._currentTimeoutId=null)}var o=t-e,r=Date.now(),c=this;this._currentTimeoutId&&clearTimeout(this._currentTimeoutId),n()}},{key:"_fallbackScrollInfoIfIncorrect",value:function(e){return e.height<0&&this._savedScrollInfo?this._savedScrollInfo:e}},{key:"saveScrollInfo",value:function(){this._savedScrollInfo=this.cm.getScrollInfo()}},{key:"_isTopSection",value:function(e,t){var i=e.scrollTop(),n=t[0].offsetTop,o=t.height(),r=i>=n-57,c=i>n+o;return r&&!c}}]),e}();t.default=s},48:function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(){return this.nodeType===Node.ELEMENT_NODE}Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),t}}(),c=i(0),s=function(e){return e&&e.__esModule?e:{default:e}}(c),l=/^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/,a=/^ *(\*|-|\d+\.|[*-] \[[ xX]])\s/,u=/^ {0,3}(> ?)+\s/,d=/^ {0,3}!\[([^[\]]*)]\(([^)]*)\)/,f=/^ *(?:={1,}|-{1,})\s*$/,h=/^ *(`{3,}|~{3,})[ ]*$/,v=/^ *(`{3,}|~{3,})[ .]*(\S+)? */,p=/\s/g,_=function(){function e(t,i){n(this,e),this.cm=t,this.preview=i,this.$previewContent=i.$el.find(".tui-editor-contents"),this._sectionList=null,this._currentSection=null}return r(e,[{key:"_addNewSection",value:function(e,t){var i=this._makeSectionData(e,t);this._sectionList.push(i),this._currentSection=i}},{key:"getSectionList",value:function(){return this._sectionList||this.makeSectionList(),this._sectionList}},{key:"_makeSectionData",value:function(e,t){return{start:e,end:t,$previewSectionEl:null}}},{key:"_updateCurrentSectionEnd",value:function(e){this._currentSection.end=e}},{key:"_eachLineState",value:function(e){var t=void 0,i=void 0,n=void 0,o=void 0,r=void 0,c=!0,s=!1,l=!1,a="",u=!1,d=!1,f=void 0,h=this.cm.getDoc().lineCount();for(i=0;i<h;i+=1){t=!1,n=this.cm.getLine(i),o=this.cm.getLine(i+1)||"",r=this.cm.getLine(i-1)||"";var v=this._isCodeBlockEnd(r)&&f!==i-1;if(!s||n&&this._isTableCode(n)?!s&&this._isTable(n,o)&&(s=!0):s=!1,l&&v&&(l=!1),!l&&this._isCodeBlockStart(n)&&(l=this._doFollowedLinesHaveCodeBlockEnd(i,h),f=i),d&&0!==n.length?(this._isIndependentImage(l,s,n,r)?(u=!0,d=!0):(u=!1,d=!1),t=!0):this._isAtxHeader(n)?(u=!1,t=!0,d=!1):this._isCodeBlockEnd(n)||s||!this._isSeTextHeader(n,o)?this._isIndependentImage(l,s,n,r)?(u=!0,t=!0,d=!1):u&&0===n.length&&(u=!1,d=!0):(u=!1,t=!0,d=!1),c){if(!(a+=n.trim()))continue;c=!1}e(t,i)}}},{key:"_isIndependentImage",value:function(e,t,i,n){return!e&&!t&&this._isImage(i)&&!this._isList(i)&&!this._isQuote(i)&&0===n.length}},{key:"_doFollowedLinesHaveCodeBlockEnd",value:function(e,t){for(var i=!1,n=e+1;n<t;n+=1)if(this._isCodeBlockEnd(this.cm.getLine(n))){i=!0;break}return i}},{key:"_isCodeBlockStart",value:function(e){return v.test(e)}},{key:"_isCodeBlockEnd",value:function(e){return h.test(e)}},{key:"_isTable",value:function(e,t){return this._isTableCode(e)&&this._isTableAligner(t)}},{key:"_isTableCode",value:function(e){return/(^\S?.*\|.*)/.test(e)}},{key:"_isTableAligner",value:function(e){return/(\s*[-:]+\s*\|)+/.test(e)}},{key:"_isAtxHeader",value:function(e){return l.test(e)}},{key:"_isSeTextHeader",value:function(e,t){return""!==e.replace(p,"")&&!this._isQuote(e)&&t&&f.test(t)}},{key:"_isImage",value:function(e){return d.test(e)}},{key:"_isList",value:function(e){return a.test(e)}},{key:"_isQuote",value:function(e){return u.test(e)}},{key:"makeSectionList",value:function(){var e=this;this._sectionList=[],this._eachLineState(function(t,i){t||!e._sectionList.length?e._addNewSection(i,i):e._updateCurrentSectionEnd(i)})}},{key:"sectionMatch",value:function(){if(this.getSectionList()){var e=this._getPreviewSections();this._matchPreviewSectionsWithSectionlist(e)}}},{key:"_matchPreviewSectionsWithSectionlist",value:function(e){var t=this.getSectionList();e.forEach(function(e,i){var n=t[i];if(n){var o=(0,s.default)("<div class='content-id-"+i+"'></div>");n.$previewSectionEl=(0,s.default)(e).wrapAll(o).parent()}})}},{key:"_getPreviewSections",value:function(){var e=[],t=0,i=!1;return e[0]=[],this.$previewContent.contents().filter(o).each(function(n,o){var r="P"===o.tagName,c=o.tagName.match(/^(H1|H2|H3|H4|H5|H6)$/),s=r&&"IMG"===o.childNodes[0].nodeName;(c||s||i)&&e[t].length&&(e.push([]),t+=1,i=!1),s&&(i=!0),e[t].push(o)}),e}},{key:"sectionByLine",value:function(e){var t=void 0,i=this.getSectionList(),n=i.length;for(t=0;t<n&&!(e<=i[t].end);t+=1);return t===n&&(t=n-1),i[t]}}]),e}();t.default=_},5:function(e,t){if(void 0===n){var i=new Error('Cannot find module "undefined"');throw i.code="MODULE_NOT_FOUND",i}e.exports=n}})});