@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) • 4.51 kB
JavaScript
!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 u(n,t){return(u=Object.setPrototypeOf||function(n,t){return n.__proto__=t,n})(n,t)}function r(n,t){for(var i=0;i<t.length;i++){var e=t[i];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(n,e.key,e)}}
/*!
* RyuseiCode.js
* Version : 0.1.17
* License : MIT
* Copyright: 2021 Naotoshi Fujita
*/
function o(n){return null!==n&&"object"==typeof n}function e(n){return Array.isArray(n)}function f(n){return"string"==typeof n}function c(n){return void 0===n}function s(n,t){return void 0===t&&(t=!1),!e(n)||t&&!e(n[0])?[n]:n}function h(t,n,i){t&&s(n).forEach(function(n){n&&t.classList[i?"add":"remove"](n)})}function a(n,t){h(n,t,!0)}function v(n,t){if(n)for(var i=Object.keys(n),e=0;e<i.length&&!1!==t(n[i[e]],i[e]);e++);return n}function d(e){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){o(i)&&v(i,function(n,t){c(i[t])||(e[t]=i[t])})}),e}function l(n,t,i){n=document.createElement(n);return t&&(f(t)||e(t)?a:function(i,n){if(i){if(f(n))return i.getAttribute(n);o(n)&&v(n,function(n,t){null===n?i.removeAttribute(t):i.setAttribute(t,String(n))})}})(n,t),i&&(i=i,s(n).forEach(i.appendChild.bind(i))),n}var y=new WeakMap;var p="ryuseicode";var w="is-active",g="readOnly",b=p+"__active-line",n=function(e){var n;function t(n){var i=e.call(this,n)||this;return i.on("initStyle",function(n,t){t("."+b,"height",i.options.lineHeight)}),i}i=e,(n=t).prototype=Object.create(i.prototype),u(n.prototype.constructor=n,i);var i=t.prototype;return i.mount=function(n){var t,i=this;e.prototype.mount.call(this,n),this.n=(t={class:b},n=n.background,l("div",t,n)),this.on(["focus","focusLineChanged",g],function(n,t){n.type===g&&t?i.t():(i.i(),i.e())}),this.on("blur",this.t,this),this.on("resize",this.e,this)},i.i=function(){var n=this.Editor;n.isFocused()&&!n.readOnly&&(this.u()||(a(this.n,w),this.emit("activeLine:activated")))},i.e=function(){var n;this.u()&&(n=(n=this.Measure).getTop(this.Selection.focus[0])+n.padding.top,this.r!==n&&(function(i,n){if(f(n))return getComputedStyle(i)[n];v(n,function(n,t){c(n)||(i.style[t]=String(n))})}(this.n,{top:f(n=this.r=n)?n:n+"px"}),this.emit("activeLine:updated")))},i.t=function(){h(this.n,w,!1),this.r=-1,this.emit("activeLine:deactivated")},i.u=function(){return n=this.n,t=w,n&&n.classList.contains(t);var n,t},t}(function(){function n(n){this.Editor=n,this.event=n.event,this.options=n.options,this.language=n.language}var t,i,e=n.prototype;return e.mount=function(n){var i=this;this.elements=n,v(this.Editor.Components,function(n,t){i[t]=n})},e.destroy=function(){!function t(i,n,e){"function"==typeof e?n.split(" ").forEach(function(n){i.removeEventListener(n,e)}):(n=y.get(e))&&(n.forEach(function(n){t(n.elm,n.events,n.callback)}),y.delete(e))}(null,"",this)},e.on=function(n,t,i,e){this.event.on(n,i?t.bind(i):t,this,e)},e.off=function(n){this.event.off(n,this)},e.emit=function(n){for(var t,i=arguments.length,e=new Array(1<i?i-1:0),u=1;u<i;u++)e[u-1]=arguments[u];(t=this.event).emit.apply(t,[n].concat(e))},e.bind=function(n,t,i,e){var u,r,o,f;u=n,r=t,o=e?i.bind(e):i,f=this,r.split(" ").forEach(function(n){u.addEventListener(n,o),f&&((n=y.get(f)||[]).push({elm:u,events:r,callback:o}),y.set(f,n))})},e.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},e.invoke=function(n,t){for(var i,e=arguments.length,u=new Array(2<e?e-2:0),r=2;r<e;r++)u[r-2]=arguments[r];return(i=this.Editor).invoke.apply(i,[n,t].concat(u))},e.require=function(n){return this.Editor.require(n)},e.addIcons=function(n){var t=this.options;t.icons=d({},n,t.icons)},e.addI18n=function(n){var t=this.options;t.i18n=d({},n,t.i18n)},e.addKeyBindings=function(n){var t=this.options;t.keymap=d({},n,t.keymap)},e.getOptions=function(n,t){n=this.options[n];return c(n)||!0===n?t||{}:o(n)?d({},t,n):void function(n,t){if(void 0===t&&(t=""),!n)throw new Error("["+p+"] "+t)}(!1)},t=n,(e=[{key:"lines",get:function(){return this.Code.Lines}},{key:"i18n",get:function(){return this.options.i18n}}])&&r(t.prototype,e),i&&r(t,i),n}());"undefined"!=typeof window&&window.RyuseiCode&&window.RyuseiCode.compose({ActiveLine:n})});