UNPKG

@ryusei/code

Version:

<div align="center"> <a href="https://code.ryuseijs.com"> <img alt="RyuseiCode" src="https://code.ryuseijs.com/images/svg/logo.svg" width="70"> </a>

9 lines (8 loc) 5.4 kB
!function(t,n){"function"==typeof define&&define.amd?define([],n):"undefined"!=typeof exports?n():(n(),t.unknown={})}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(){"use strict";function r(t,n){t.prototype=Object.create(n.prototype),i(t.prototype.constructor=t,n)}function i(t,n){return(i=Object.setPrototypeOf||function(t,n){return t.__proto__=n,t})(t,n)}function e(t,n){for(var i=0;i<n.length;i++){var r=n[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}} /*! * RyuseiCode.js * Version : 0.1.17 * License : MIT * Copyright: 2021 Naotoshi Fujita */ function u(t){return null!==t&&"object"==typeof t}function v(t){return void 0===t}function o(t,n){if(t)for(var i=Object.keys(t),r=0;r<i.length&&!1!==n(t[i[r]],i[r]);r++);return t}function f(r){for(var t=arguments.length,n=new Array(1<t?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];return n.forEach(function(i){u(i)&&o(i,function(t,n){v(i[n])||(r[n]=i[n])})}),r}var s=new WeakMap;function c(t){return"string"==typeof t?t:t+"px"}var h="ryuseicode";function a(t,n){return u=t,o=0,f=n,c=!(s=!1),i.cancel=e,i.invoke=function(){h&&a()},i;function i(){s&&e();for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];a=r.bind.apply(r,[this].concat(n)),h||(v(h)&&f?a():h=c?requestAnimationFrame(a):setTimeout(a,o))}function r(){for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];u.apply(this,n),e()}function e(){(c?cancelAnimationFrame:clearTimeout)(h),h=null}var u,o,f,s,c,h,a}Math.min;var d=Math.max,l=Math.floor;Math.ceil,Math.abs,Math.round;var t=function(){function t(t){this.Editor=t,this.event=t.event,this.options=t.options,this.language=t.language}var n,i,r=t.prototype;return r.mount=function(t){var i=this;this.elements=t,o(this.Editor.Components,function(t,n){i[n]=t})},r.destroy=function(){!function n(i,t,r){"function"==typeof r?t.split(" ").forEach(function(t){i.removeEventListener(t,r)}):(t=s.get(r))&&(t.forEach(function(t){n(t.elm,t.events,t.callback)}),s.delete(r))}(null,"",this)},r.on=function(t,n,i,r){this.event.on(t,i?n.bind(i):n,this,r)},r.off=function(t){this.event.off(t,this)},r.emit=function(t){for(var n,i=arguments.length,r=new Array(1<i?i-1:0),e=1;e<i;e++)r[e-1]=arguments[e];(n=this.event).emit.apply(n,[t].concat(r))},r.bind=function(t,n,i,r){var e,u,o,f;e=t,u=n,o=r?i.bind(r):i,f=this,u.split(" ").forEach(function(t){e.addEventListener(t,o),f&&((t=s.get(f)||[]).push({elm:e,events:u,callback:o}),s.set(f,t))})},r.getLanguage=function(t){t=t||this.Selection.focus;var n=this.language,t=this.lines.getInfoAt(t);return t&&t.language&&n.use&&n.use[t.language]?n.use[t.language].config:n},r.invoke=function(t,n){for(var i,r=arguments.length,e=new Array(2<r?r-2:0),u=2;u<r;u++)e[u-2]=arguments[u];return(i=this.Editor).invoke.apply(i,[t,n].concat(e))},r.require=function(t){return this.Editor.require(t)},r.addIcons=function(t){var n=this.options;n.icons=f({},t,n.icons)},r.addI18n=function(t){var n=this.options;n.i18n=f({},t,n.i18n)},r.addKeyBindings=function(t){var n=this.options;n.keymap=f({},t,n.keymap)},r.getOptions=function(t,n){t=this.options[t];return v(t)||!0===t?n||{}:u(t)?f({},n,t):void function(t,n){if(void 0===n&&(n=""),!t)throw new Error("["+h+"] "+n)}(!1)},n=t,(r=[{key:"lines",get:function(){return this.Code.Lines}},{key:"i18n",get:function(){return this.options.i18n}}])&&e(n.prototype,r),i&&e(n,i),t}(),y=function(t){function n(){return t.apply(this,arguments)||this}return r(n,t),n.prototype.calcBoundaries=function(t){var n=this.Editor.options.indent,i=this.Editor.Components,r=i.Measure,e=i.Measure.padding,i=r.measureWidth(n,!0),r=r.getTop(t[0])+e.top,e=l(t[1]/n.length)*i+e.left;return{start:{top:r,left:e},end:{top:r,left:e+i}}},n}(function(){function t(t,n){this.Editor=t,this.elements=n,this.scroller=n.scroller}var n=t.prototype;return n.calcBoundaries=function(t,n){var i,r,e=this.Editor.Components.Measure,r=(r=n,0<((i=t)[0]-r[0]||i[1]-r[1]));return{start:e.getOffset(r?n:t),end:e.getOffset(r?t:n)}},n.html=function(t,n,i){if((i=void 0===i?!0:i)&&this.cache)return this.cache;var r=this.Editor.Components.Measure,e=r.lineHeight,u=r.padding,o=this.calcBoundaries(t,n),i=o.start,r=o.end,t=r.top-i.top,n=t-e,o=d(i.left,u.left),f="";return t?(f+=this.buildLine(i.top,o,"100%"),f+=this.buildLine(r.top,u.left,d(r.left-u.left,0)),0<n&&(f+=this.buildLine(i.top+e,u.left,"100%",n))):f+=this.buildLine(i.top,o,d(r.left-o,0)),this.cache=f},n.buildLine=function(t,n,i,r){i="top: "+c(t)+"; left: "+c(n)+"; width: "+c(i)+";";return r&&(i+=" height: "+c(r)+";"),'<div class="ryuseicode__marker" style="'+i+'"></div>'},t}()),w="indent",t=function(n){function t(){return n.apply(this,arguments)||this}r(t,n);var i=t.prototype;return i.mount=function(t){n.prototype.mount.call(this,t),this.t()},i.t=function(){var t=this.n.bind(this);this.on("changed",a(t)),this.on(["mounted","chunkMoved"],t)},i.n=function(){var t=this.Range,n=this.i();t.clearRanges(w),t.register(w,n,!1,y)},i.i=function(){for(var t=this.Chunk,n=t.start,i=t.end,r=[],e=0,u=d(n,0);u<=i;u++){var o=this.lines[u];if(!o)break;var f=o.indentDepth-1;if(0<(f=o.isEmpty()&&0<e?e:f)){for(var s=0;s<f;s++){var c=this.options.indent.length;r.push({start:[u,s*c],end:[u,(s+1)*c]})}e=f}else e=0}return r},t}(t);"undefined"!=typeof window&&window.RyuseiCode&&window.RyuseiCode.compose({Guide:t})});