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) 3.7 kB
!function(n,t){"function"==typeof define&&define.amd?define([],t):"undefined"!=typeof exports?t():(t(),n.unknown={})}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(){"use strict";function r(n,t){return(r=Object.setPrototypeOf||function(n,t){return n.__proto__=t,n})(n,t)}function e(n,t){for(var i=0;i<t.length;i++){var o=t[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(n,o.key,o)}} /*! * RyuseiCode.js * Version : 0.1.17 * License : MIT * Copyright: 2021 Naotoshi Fujita */ function u(n){return null!==n&&"object"==typeof n}function f(n){return void 0===n}function c(n,t){if(n)for(var i=Object.keys(n),o=0;o<i.length&&!1!==t(n[i[o]],i[o]);o++);return n}function s(o){for(var n=arguments.length,t=new Array(1<n?n-1:0),i=1;i<n;i++)t[i-1]=arguments[i];return t.forEach(function(i){u(i)&&c(i,function(n,t){f(i[t])||(o[t]=i[t])})}),o}function h(n){return n&&n.defaultPrevented}var a=new WeakMap;function v(n,t){n&&(n.cancelable&&n.preventDefault(),t&&n.stopPropagation())}var d="keymap",w={cutLine:["X",!0],copyLine:["C",!0],moveUp:["ArrowUp",!0],moveDown:["ArrowDown",!0]},n=function(t){var n,i;function o(n){n=t.call(this,n)||this;return n.addKeyBindings(w),n}return i=t,(n=o).prototype=Object.create(i.prototype),r(n.prototype.constructor=n,i),o.prototype.mount=function(o){t.prototype.mount.call(this,o);var i=this.Selection,r=this.Measure,e=this.Edit;this.on(d+":copyLine",function(n,t){i.isCollapsed()&&!h(t)&&(i.selectLine(void 0,!0,!0),e.copy(),v(t))}),this.on(d+":cutLine",function(n,t){i.isCollapsed()&&!h(t)&&(e.cutLine(),v(t))}),this.on(d+":moveUp "+d+":moveDown",function(n,t){var i;o.scroller.scrollTop+=(i=n.type,n="n",(i.slice(-n.length)===n?1:-1)*r.lineHeight),v(t)})},o}(function(){function n(n){this.Editor=n,this.event=n.event,this.options=n.options,this.language=n.language}var t,i,o=n.prototype;return o.mount=function(n){var i=this;this.elements=n,c(this.Editor.Components,function(n,t){i[t]=n})},o.destroy=function(){!function t(i,n,o){"function"==typeof o?n.split(" ").forEach(function(n){i.removeEventListener(n,o)}):(n=a.get(o))&&(n.forEach(function(n){t(n.elm,n.events,n.callback)}),a.delete(o))}(null,"",this)},o.on=function(n,t,i,o){this.event.on(n,i?t.bind(i):t,this,o)},o.off=function(n){this.event.off(n,this)},o.emit=function(n){for(var t,i=arguments.length,o=new Array(1<i?i-1:0),r=1;r<i;r++)o[r-1]=arguments[r];(t=this.event).emit.apply(t,[n].concat(o))},o.bind=function(n,t,i,o){var r,e,u,f;r=n,e=t,u=o?i.bind(o):i,f=this,e.split(" ").forEach(function(n){r.addEventListener(n,u),f&&((n=a.get(f)||[]).push({elm:r,events:e,callback:u}),a.set(f,n))})},o.getLanguage=function(n){n=n||this.Selection.focus;var t=this.language,n=this.lines.getInfoAt(n);return n&&n.language&&t.use&&t.use[n.language]?t.use[n.language].config:t},o.invoke=function(n,t){for(var i,o=arguments.length,r=new Array(2<o?o-2:0),e=2;e<o;e++)r[e-2]=arguments[e];return(i=this.Editor).invoke.apply(i,[n,t].concat(r))},o.require=function(n){return this.Editor.require(n)},o.addIcons=function(n){var t=this.options;t.icons=s({},n,t.icons)},o.addI18n=function(n){var t=this.options;t.i18n=s({},n,t.i18n)},o.addKeyBindings=function(n){var t=this.options;t.keymap=s({},n,t.keymap)},o.getOptions=function(n,t){n=this.options[n];return f(n)||!0===n?t||{}:u(n)?s({},t,n):void function(n,t){if(void 0===t&&(t=""),!n)throw new Error("[ryuseicode] "+t)}(!1)},t=n,(o=[{key:"lines",get:function(){return this.Code.Lines}},{key:"i18n",get:function(){return this.options.i18n}}])&&e(t.prototype,o),i&&e(t,i),n}());"undefined"!=typeof window&&window.RyuseiCode&&window.RyuseiCode.compose({Shortcut:n})});