@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>
15 lines (14 loc) • 4.9 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)}}
/*!
* RyuseiCode.js
* Version : 0.1.17
* License : MIT
* Copyright: 2021 Naotoshi Fujita
*/
/*!
* RyuseiLight.js
* Version : 1.2.0
* License : MIT
* Copyright: 2020 Naotoshi Fujita
*/
var u="string";function s(t){return null!==t&&"object"==typeof t}function f(t){return"function"==typeof t}function c(t){return"string"==typeof t}function h(t){return void 0===t}function a(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 v(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){s(i)&&a(i,function(t,n){h(i[n])||(r[n]=i[n])})}),r}var d=new WeakMap;var l={Up:"ArrowUp",Down:"ArrowDown",Right:"ArrowRight",Left:"ArrowLeft",Del:"Delete",Esc:"Escape",Spacebar:" "};var t=function(n){var t;function i(){return n.apply(this,arguments)||this}r=n,(t=i).prototype=Object.create(r.prototype),e(t.prototype.constructor=t,r);var r=i.prototype;return r.mount=function(t){var i=this;n.prototype.mount.call(this,t),this.on("keydown",function(t,n){i.t(n),i.n(n)}),this.on("changed",function(t,n){"input"===n&&i.i()})},r.i=function(){var t,n=this.Input;n.composing||-1<(t=this.r(!1).indexOf(n.get().key))&&this.e(t,"close")&&n.apply({type:"autoClose",insertion:this.o(t),offset:this.u(t)})},r.t=function(t){var n,i,r,e=this.Input;e.composing||-1<(r=(n=this.r(!0)).indexOf((r=t.key,l[r]||r)))&&this.e(r,"skip")&&n[r]===e.char()&&(r=this.Selection,e=this.Selection.focus,r.set([e[0],e[1]+1]),(t=t)&&(t.cancelable&&t.preventDefault(),i&&t.stopPropagation()))},r.n=function(t){var n,i=this.Input;"Backspace"!==t.key||-1<(n=this.r(!1).indexOf(i.char(i.col-1)))&&this.e(n,"remove")&&this.r(!0)[n]===i.char()&&(t=this.Selection,n=this.Selection.focus,i.value=i.before+i.after.slice(1),t.set(n))},r.r=function(n){return this.s().map(function(t){t=t[n?1:0];return c(t)?t:""})},r.o=function(t){t=this.s()[t],t=t&&t[1];return f(t)?t(this.Editor):t||""},r.u=function(t){t=this.s()[t],t=t&&t[2];return t&&t.offset||0},r.e=function(t,n){var i=this.Scope,r=this.s()[t],t=r[2];if(!t)return!0;t=t[n];return f(t)?t(this.Editor,r):c(t)?"@quotes"===t&&this.f(n):Array.isArray(t)?i.isIn(t):t},r.f=function(t){var n=this.Selection.get().start,i=this.Input,r=this.lines.getInfoAt(n),e=i.info;if(r&&(r.category===u||e&&e.category===u))return("skip"===t||"remove"===t)&&0===(r=[(n=n)[0],r.to-1],n[0]-r[0]||n[1]-r[1]);i=i.after;return!this.Scope.isIn("comment")&&(!i||/^\s/.test(i))},r.s=function(){return this.getLanguage().autoClose||[]},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,a(this.Editor.Components,function(t,n){i[n]=t})},r.destroy=function(){!function n(i,t,r){f(r)?t.split(" ").forEach(function(t){i.removeEventListener(t,r)}):(t=d.get(r))&&(t.forEach(function(t){n(t.elm,t.events,t.callback)}),d.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,u,s;e=t,o=n,u=r?i.bind(r):i,s=this,o.split(" ").forEach(function(t){e.addEventListener(t,u),s&&((t=d.get(s)||[]).push({elm:e,events:o,callback:u}),d.set(s,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=v({},t,n.icons)},r.addI18n=function(t){var n=this.options;n.i18n=v({},t,n.i18n)},r.addKeyBindings=function(t){var n=this.options;n.keymap=v({},t,n.keymap)},r.getOptions=function(t,n){t=this.options[t];return h(t)||!0===t?n||{}:s(t)?v({},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({AutoClose:t})});