@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>
2 lines (1 loc) • 5.02 kB
JavaScript
!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 e(t,n){return(e=Object.setPrototypeOf||function(t,n){return t.__proto__=n,t})(t,n)}function o(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)}}function h(t){return null!==t&&"object"==typeof t}function u(t){return void 0===t}function s(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){h(i)&&s(i,function(t,n){u(i[n])||(r[n]=i[n])})}),r}var c=new WeakMap;var a=Math.max,v=Math.min;var l=Math.min;Math.max,Math.floor,Math.ceil,Math.abs,Math.round;function d(t){return t.replace(/[.*+\-?^${}()|[\]\\]/g,"\\$&")}var m="change",y="changed",w="keymap",b={lineComment:["/",!0],blockComment:["?",!0,!0]},p="comment",t=function(n){var t;function i(t){t=n.call(this,t)||this;return t.addKeyBindings(b),t}r=n,(t=i).prototype=Object.create(r.prototype),e(t.prototype.constructor=t,r);var r=i.prototype;return r.mount=function(t){n.prototype.mount.call(this,t);t=this.language;t.blockComment&&this.on(w+":blockComment",this.t,this),t.lineComment&&this.on(w+":lineComment",this.n,this)},r.t=function(){var t=this.Selection.get(),n=t.start,i=t.end,t=this.i(n)||this.i(i);this.emit(m,p),t?(n=t.start,i=t.end,this.r(n,i,!1)):this.e(n,i,!1),this.o(n,i,!!t,!1),this.emit(y,p)},r.n=function(){var t,n,i=this.Selection.get(),r=i.start,e=i.end,o=this.lines;this.emit(m,p);for(var h=r[0];h<=e[0];h++){var u=this.h([h,o[h].text.length]);u&&(this.r(u.start,u.end,!0),t=e,n=!0)}if(!n)for(var s=o.findMinIndent(r[0],e[0]),f=r[0];f<=e[0];f++)this.e([f,s.length],[f,o[f].text.length],!0);this.o(r,t||e,n,!0),this.emit(y,p)},r.e=function(t,n,i){var r=this.Code,e=this.u(i?[t[0],0]:t,i);e&&(i=e[0]+(e[1]?"":" "),r.replaceRange(t,n,i+r.sliceRange(t,n)+(e[1]||"")))},r.r=function(t,n,i){var r=this.Code,e=this.u(t,i);e&&(i=r.sliceRange(t,n),e="^"+d(e[0])+"[ ]?|[ ]?"+d(e[1])+"$",r.replaceRange(t,n,i.replace(new RegExp(e,"g"),"")))},r.o=function(t,n,i,r){var e,o,h=this.lines,u=this.Selection.get(),s=this.u(t,r);s&&(e=(i&&!r?u.start:n)[0],u=u.end[1],r?e=l(e+1,h.length-1):(o=s[0].length,i?e===t[0]&&(u-=o):e===t[0]&&(u+=o)),this.View.jump(e),this.Sync.sync(t[0],n[0]),i=u,o=0,t=this.lines[e].text.length,n=v(o,t),t=a(o,t),u=v(a(n,i),t),this.Selection.set([e,u]))},r.u=function(t,n){return this.getLanguage(t)[(n?"line":"block")+"Comment"]},r.i=function(t){var n=this.lines,i=n.getInfoAt(t);if(i&&"comment"===i.category){i=n.findBlockStart(t),t=n.findBlockEnd(t);if(i&&t)return{start:i,end:t}}return null},r.h=function(t){var n=this.u(t,!0),i=n[0],r=n[1],e=t[0],o=this.lines[e].text;if(o){n=o.trim();if(t=i,n.slice(0,t.length)===t&&(!r||(t=r,n.slice(-t.length)===t))){r=r?o.lastIndexOf(r):o.length;return{start:[e,o.indexOf(i)],end:[e,r]}}}return null},i}(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,s(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=c.get(r))&&(t.forEach(function(t){n(t.elm,t.events,t.callback)}),c.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,o,h,u;e=t,o=n,h=r?i.bind(r):i,u=this,o.split(" ").forEach(function(t){e.addEventListener(t,h),u&&((t=c.get(u)||[]).push({elm:e,events:o,callback:h}),c.set(u,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),o=2;o<r;o++)e[o-2]=arguments[o];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 u(t)||!0===t?n||{}:h(t)?f({},n,t):void function(t,n){if(void 0===n&&(n=""),!t)throw new Error("[ryuseicode] "+n)}(!1)},n=t,(r=[{key:"lines",get:function(){return this.Code.Lines}},{key:"i18n",get:function(){return this.options.i18n}}])&&o(n.prototype,r),i&&o(n,i),t}());"undefined"!=typeof window&&window.RyuseiCode&&window.RyuseiCode.compose({Comment:t})});