@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>
14 lines (13 loc) • 5.52 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 r(t,n){return(r=Object.setPrototypeOf||function(t,n){return t.__proto__=n,t})(t,n)}
/*!
* 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 n="keyword",e="comment",i="tag",o="selector",s="atrule",u="prop",a="string",f="number",c="function",l="operator",h="bracket",d="delimiter",m="space",v="text";function p(t,n){if(t)for(var e=Object.keys(t),i=0;i<e.length;i++)n(t[e[i]],e[i])}function b(t,n){if(void 0===n&&(n=""),!t)throw new Error(n)}function g(t,n){return t.charAt(0)===n}var k=!(void 0===/x/.sticky),S=/[ \t]+/,w=/\/\*[\s\S]*?(\*\/|$)/;var y=function(t){var n,e;function i(){return t.apply(this,arguments)||this}return e=t,(n=i).prototype=Object.create(e.prototype),r(n.prototype.constructor=n,e),i.prototype.run=function(t,n){for(var e=this.tokenize(t,n),i=0;i<e.length;i++)for(var r=e[i],o=0,s=0;s<r.length;s++){var u=r[s],a=u[1].length,f=u[2],c="rc__token rc__"+u[0].split(".")[0],l=u[1].replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");u[2]={category:u[0],code:u[1],html:'<code class="'+c+'">'+l+"</code>",from:o,to:o+a,index:s,state:f.state,depth:f.depth,head:f.head,tail:f.tail,distance:f.distance,language:f.language,split:f.split},o+=a}return e},i}(function(){function t(t){this.language=t,this.init(t)}var n=t.prototype;return n.init=function(e){var i=this;p(e.grammar,function(t,n){e.grammar[n]=i.merge(e,t)}),p(e.use,this.init.bind(this))},n.merge=function(n,t){for(var i=[],e=0;e<t.length;e++){var r=t[e],o=t[e],s=o[0],u=o[1];g(s,"#")&&!u?i.push.apply(i,this.merge(n,n.grammar[s.slice(1)])):function(){var t=u.toString().match(/[gimsy]*$/)[0].replace(/[gy]/g,""),e=u.source+(k?"":"|()");p(n.source,function(t,n){e=e.replace(new RegExp("%"+n,"g"),t.source)}),r[1]=new RegExp(e,(k?"y":"g")+t),i.push(r)}()}return i},n.parse=function(t,n,e,i){var r=0,o=0;this.depth++;t:for(;r<t.length&&!this.aborted;){for(var s=0;s<e.length;s++){var u=e[s],a=u[1],f=u[2];a.lastIndex=r;a=a.exec(t);if(a&&a[0]){if(o<r&&this.push([v,t.slice(o,r)],n,i),"@back"===f){o=r;break t}o=r+=this.handle(a,n,u,i)||1;if("@break"===f)break t;continue t}}r++}return o<r&&this.push([v,t.slice(o)],n,i),this.depth--,r},n.push=function(t,n,e){for(var i=this.depth,r=t[0],o=t[1],s=this.index,u=0,a=0;-1<u&&!this.aborted;){var u=o.indexOf("\n",a),f=this.lines[this.index],c=a===u&&!f.length,l=c?"\n":o.slice(a,u<0?void 0:u),h={depth:i,language:n.id,state:e};l&&(r!==v&&(h.head=-1<u&&!a,h.tail=u<0&&!!a,h.split=-1<u||!!a,h.distance=this.index-s),f.push([r===v&&c?"lb":r,l,h])),-1<u&&(this.index++,this.aborted=this.limit&&this.index>=this.limit,this.aborted||(a=u+1,this.lines[this.index]=[]))}},n.handle=function(t,n,e,i){var r=e[0];if(!r)return 0;var o=t[0];if("@debug"===e[3]&&console.log(o,e),g(r,"@")){b(n.use);var s=n.use[r.slice(1)];return b(s),this.parse(o,s,s.grammar.main,r)}if(g(r,"#")){s=n.grammar[r.slice(1)];return b(s),"@rest"===e[2]&&(o=t.input.slice(t.index)),this.parse(o,n,s,r)}return this.push([r,o],n,i),o.length},n.tokenize=function(t,n){return this.lines=[[]],this.index=0,this.depth=-1,this.limit=n||0,this.aborted=!1,this.parse(t,this.language,this.language.grammar.main,"#main"),this.lines},t}());function x(i){for(var t=arguments.length,n=new Array(1<t?t-1:0),e=1;e<t;e++)n[e-1]=arguments[e];return n.forEach(function(e){var t;null!==(t=e)&&"object"==typeof t&&function(t,n){if(t)for(var e=Object.keys(t),i=0;i<e.length&&!1!==n(t[e[i]],e[i]);i++);}(e,function(t,n){void 0!==e[n]&&(i[n]=e[n])})}),i}function t(){var t={id:"css",name:"CSS",grammar:{main:[["#common"],["#findSingleAtrule"],["#findBlock"]],findBlock:[["#block",/(?:(?![\t\n\r ;\{\}])[\s\S])(?:(?![;\{\}])[\s\S])*\{[\s\S]*?\}/,"@rest"]],findSingleAtrule:[["#atrule",/@(?:(?![;\{])[\s\S])+?;/]],findAtrule:[["#atrule",/@(?:(?![;\{])[\s\S])*?(?=[;\{])/]],findSelector:[["#selector",/(?:(?![\t\n\r ;\{\}])[\s\S])[\s\S]*?(?=\{)/]],common:[[a,/(["'])[\s\S]*?(?:(?!\\)[\s\S])\1/],[e,w],[m,S]],block:[["#inner",/{/,"@rest"],[h,/}/,"@break"],["#findAtrule"],["#findSelector"],[m,S]],inner:[[h,/{/],["#common"],["#findBlock"],["#props"],["#findAtrule"],["",/}/,"@back"]],atrule:[["#common"],["#url",/\burl\(/,"@rest"],[m,S],[s,/[^\s();]+/],[d,/[:;,]/],["#paren",/\(/,"@rest"]],paren:[[h,/^\(/],["#common"],["#paren",/\(/,"@rest"],[h,/\)/,"@break"],["#props"]],selector:[["#common"],[l,/[>+~]/],[h,/[[\]()]/],[d,/=/],[o,/::?\S+/],[o,/[\W\d]\S+/],[i,/\b[a-z]+|\*/i],[o,/\S+/]],url:[["#common"],[c,/^url/],[h,/\(/],[a,/[^)]+/],[h,/\)/,"@break"]],props:[[u,/[a-z0-9-_\xA0-\uFFFF]+(?=:)/i],["#url",/\burl\(/,"@rest"],[c,/\b[\w-]+(?=\()\b/],[n,/!important|\b(?:initial|inherit|unset)/],[u,/[a-z0-9-]+(?=:)/],[f,/#([0-9a-f]{6}|[0-9a-f]{3})/i],[f,/\bU\+[0-9a-f?-]+/i],[f,/[+-]?(\d+\.?\d*|\d*\.?\d+)/],[d,/[:;,]/],["#paren",/\(/,"@rest"],[h,/[[\])]/],[m,S]]}};return x({id:t.id,language:t,lexer:new y(t)},{lineComment:["/*","*/"],blockComment:["/*","*/"],multiline:[["/*","*/",e]],indent:[[/{$/,/^}/,t=["!comment","!string"]]],autoClose:[["(",")",t={close:t,skip:t,remove:t}],["[","]",t],["{","}",t],["'","'",t={close:"@quotes",skip:"@quotes",remove:"@quotes"}],['"','"',t]]})}"undefined"!=typeof window&&window.RyuseiCode&&window.RyuseiCode.register(t())});