Comparing version 0.3.2 to 0.3.3
@@ -1,1 +0,1 @@ | ||
!function(n,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():n.indent=e()}(this,function(){var n=function(n){function e(n,e,t){if(h[n])return h[n];var r=[];h[n]=r,t=t||"";for(var a=0;a<e.length;a++)e[a].a.indexOf(n.toLowerCase())!==-1&&t.indexOf(e[a].b)===-1&&r.push(e[a]);return r}function t(n,t,c){function u(n){Z=n.cursor;var t=n.rule,r=O+1+(t.c||0);n.line=r,z.push(n),t.d&&w[r]++,t.e&&(E=e(t.e,f)),t.f&&F.push(null),t.callback&&t.callback(n,w,A)}function h(){var n=z.pop(),e=n.line,t=n.rule;if(t.d){var r="function"==typeof t.g?t.g(g):t.g,a=r||0!==g.matchIndex?1:0;A[O+a]&&A[O+a].push(e)}t.e&&(E=null),t.f&&F.pop(),F[F.length-1]=n}function d(n,e,t){n=n.substring(t,n.length);for(var r,a,i,s=null,l=n.length,c=F[F.length-1],u=c?c.rule.b:"",h=0;h<e.length;h++)i=e[h],(!i.h||u&&i.h.indexOf(u)!==-1)&&(a=o(n,i.i,i),a.matchIndex!=-1&&a.matchIndex<l&&(!i.j||0===t)&&(l=a.matchIndex,r=a,s=i));return{rule:s,relativeIndex:s?l:-1,matchIndex:s?l+t:-1,cursor:s?t+r.cursor:-1,state:r?r.state:{},lastMatch:c}}function m(n,e,t,r){n=n.substr(t,n.length);var a=e.rule,i=o(n,a.k,a,e.state,r),s=a.l?i.cursor:i.matchIndex;return{endPatternIndex:i.endPatternIndex,matchIndex:i.matchIndex===-1?-1:i.matchIndex+t,cursor:s===-1?-1:s+t,state:i.state}}n=n||"";var g,b,x,k,v,p=c&&null!=c.tabString?c.tabString:"\t",j=n.split(/[\r]?\n/gi),I=j.length,y=a(I),w=a(I),A=r(I),z=[],F=[null],O=0,Z=0,E=null;for(c&&(c.debug={buffers:{ignore:y,indent:w,dedent:A,active:z}});O<I;){if(x=j[O].trim(),k=l(x)+"\r\n",v=z[z.length-1],b=d(k,E||t,Z),z.length)if(g=m(k,v,Z,b),g.matchIndex===-1){if(v.rule.m){y[O]=1,O++,Z=0;continue}}else if(v.rule.m||b.matchIndex===-1||g.matchIndex<=b.matchIndex){h(),Z=g.cursor;continue}b.matchIndex!==-1?u(b):(O++,Z=0)}var P,S,$,q,R,T,M=0,C=i(w),H=a(I),L=[];for(R=0;R<I;R++){for(S=A[R],q=0,T=0;T<S.length;T++)$=S[T],$<0?-$!==R&&(H[-$]++,q+=1):C[$]>0&&(C[$]--,q+=$!==R);P=C[R],H[R]=P>q?1:P<q?P-q:0,C[R]=P>0?1:0}for(R=0;R<I;R++)1===y[R-1]&&1===y[R]?L.push(j[R]):(M+=H[R]||0,L.push((M>0?s(p,M):"")+j[R].trim()));return L.join("\r\n")}function r(n){for(var e=new Array(n),t=0;t<n;t++)e[t]=[];return e}function a(e){if(n.Int16Array)return new Int16Array(e);for(var t=new Array(e),r=0;r<e;r++)t[r]=0;return t}function i(n){for(var e=a(n.length),t=0;t<n.length;t++)e[t]=n[t];return e}function s(n,e){return new Array(e+1).join(n)}function l(n){return n.replace(/\\(u[0-9A-Za-z]{4}|u\{[0-9A-Za-z]{1,6}]\}|x[0-9A-Za-z]{2}|.)/g,"0")}function c(n,e,t){var r=n.lastMatch;r&&"="===r.rule.b&&t[n.line].push(-r.line)}function u(n,e,t,r){var a;if(t.newline){if(a=n.search(/[;,=]?\r*\n/),a!==-1)return{matchIndex:a,length:1}}else a=n.search(/[^\s\r\n\{\(\[]/),t.newline=a!==-1&&(a<=r.relativeIndex||r.relativeIndex===-1);return null}function o(n,e,t,r,a){r=r||{};for(var i,s,l=-1,c=0,u=0;u<e.length;u++)if(s=e[u],"function"==typeof s){if(i=s(n,t,r,a)){l=i.matchIndex,c=i.length;break}}else if(i=n.match(s)){l=n.search(s),c=i[0].length;break}return{endPatternIndex:u,matchIndex:l,cursor:l+c,state:r}}var h={};String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")});var d=/\r*\n/,f=[{a:"html",b:"comment",i:[/\<\!\-\-/],k:[/\-\-\>/],m:!0,l:!0},{a:"html",b:"doctype",i:[/\<\!doctype html>/i],k:[d],m:!0,l:!0},{a:"html",b:"void-tags",i:[/\<(area|base|br|col|command|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)/i],k:[/>/],d:!0,l:!0},{a:"html",b:"mode switch js",i:[function(n){var e=/<script[\s>].*/i,t=/<\/script>/i,r=e.exec(n),a=t.exec(n);return r&&(!a||a.index<r.index)?{matchIndex:r.index,length:r[0].length}:null}],k:[/<\/script>/i],e:"js",l:!0,d:!0,f:!0},{a:"html",b:"mode switch css",i:[function(n){var e=/<style[\s>].*/i,t=/<\/style>/i,r=e.exec(n),a=t.exec(n);return r&&(!a||a.index<r.index)?{matchIndex:r.index,length:r[0].length}:null}],k:[/<\/style>/i],e:"css",l:!0,d:!0,f:!0},{a:"html",b:"html-tag",i:[/<html[^A-Za-z0-9]/i],k:[/<\/html>/i],l:!0},{a:"html",b:"tag",i:[function(n,e,t){var r=/<([A-Za-z0-9\-]+)/,a=n.match(r);return a?(t.openingTag=a[1],{matchIndex:a.index,length:a[0].length}):null}],k:[function(n,e,t){var r=new RegExp("</"+t.openingTag+">","i"),a=n.match(r);return a?{matchIndex:a.index,length:a[0].length}:null}],d:!0,l:!0},{a:"js",b:"line-comment",i:[/\/\//],k:[d],m:!0},{a:"js css",b:"block-comment",i:[/\/\*/],k:[/\*\//],m:!0,l:!0},{a:"js",b:"regex",i:[function(n,e){var t=/[(,=:[!&|?{};][\s]*\/[^\/]|^[\s]*\/[^\/]/,r=n.search(t);if(r!=-1){r=n.indexOf("/",r);var a=n.substring(r+1),i=o(a,e.k,e);if(i.matchIndex!=-1){a=a.substring(0,i.matchIndex);try{return new RegExp(a),{matchIndex:r,length:1}}catch(s){return null}}}return null}],k:[function(n){for(var e=0,t=n.indexOf("/");t!=-1;)try{new RegExp(n.substring(0,t));break}catch(r){t=n.indexOf("/",e),e=t+1}return t===-1?null:{matchIndex:t,length:1}}],m:!0,l:!0},{a:"html",b:"quotes",i:[/"/],k:[/"/,d],m:!0,l:!0},{a:"html",b:"quotes",i:[/'/],k:[/'/,d],m:!0,l:!0},{a:"js css",b:"string",i:[/(''|""|``)/],k:[/./,d]},{a:"js css",b:"string",i:[/\"(?=[^"])/],k:[/[^\\]\"/,d],m:!0,l:!0},{a:"js css",b:"string",i:[/\'(?=[^'])/],k:[/[^\\]\'/,d],m:!0,l:!0},{a:"js css",b:"string",i:[/\`(?=[^`])/],k:[/[^\\]\`/],m:!0,l:!0},{a:"js",b:"if",i:[/^if\s*(?=\()/,/[\s]+if\s*(?=\()/],k:[/else[\s]+/,u,/[{;]/],d:!0},{a:"js",b:"for|while",i:[/^(for|while)\s*(?=\()/],k:[u,/[{;]/],d:!0},{a:"js",b:"else",i:[/else[\s]+/],k:[/if[^\w$]/,u,/[{;]/],d:!0},{a:"js css",b:"bracket",i:[/\(\s*(var|let|const)?\s*/],k:[/\)/],d:!0,l:!0,f:!0},{a:"js",b:"dot-chain",i:[/^\.[A-Za-z$_]/],k:[/[\.;]/,d],d:!0,j:!0,c:-1},{a:"js",b:"dot-chain",i:[/\.\s*\r*\n/],k:[/[\.;})\]]/,/[^\s]\s*\r*\n/],d:!0},{a:"js css",b:"array",i:[/\[/],k:[/\]/],d:!0,l:!0,f:!0},{a:"js css",b:"block",i:[/\{/],k:[/\}/],d:!0,l:!0,f:!0},{a:"js",b:"var/let/const",i:[/(var|let|const)[\s]*\r*\n/],k:[u],d:!0,g:!0},{a:"js",b:"var/let/const",i:[/(var|let|const)\s+(?=[\w$])/],k:[/[,;=]/,u],d:!0},{a:"js",b:"var/let/const",h:["var/let/const","="],i:[/,[\s]*\r*\n/],k:[/[,;]/,u],d:!0,callback:c},{a:"js",b:"var/let/const",h:["var/let/const","="],i:[/^,/],k:[/[,;]/,u],j:!0,d:!0,c:-1,callback:c},{a:"js",b:"equality",i:[/[=<>!]=(=)?/],k:[/./]},{a:"js",b:"=",i:[/=/],k:[/[,;\)\]}]/,d]},{a:"js",b:"?:",i:[/\?/],k:[/[:;]/],g:!0,d:!0},{a:"js",b:"case",i:[/^(case|default)[\s:]/],k:[/break[\s;\r\n]/,/^return[\s;\r\n]/,/^case[\s]+/,/^default[\s:]/,/}/],g:function(n){return n.endPatternIndex<=1},d:!0,f:!0},{a:"js",b:"semicolon",i:[/;/],k:[/./]}];return{css:function(n,r){return t(n,e("css",f),r)},js:function(n,r){return t(n,e("js",f),r)},ts:function(n,r){return t(n,e("js",f),r)},html:function(n,r){var a=r&&r.indentHtmlTag?e("html",f,"html-tag"):e("html",f);return t(n,a,r)}}}(this);return n}); | ||
!function(n,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():n.indent=t()}(this,function(){var n=function(n){function t(n,t){var e,r=[];for(e=0;e<n.length;e++)r.push(t(n[e],e,n));return r}function e(n,t){var e,r;for(e=0;e<n.length;e++)if(r=t(n[e],e,n))return r;return!1}function r(n,t,e){if(d[n])return d[n];var r=[];d[n]=r,e=e||"";for(var a=0;a<t.length;a++)t[a].a.indexOf(n.toLowerCase())!==-1&&e.indexOf(t[a].b)===-1&&r.push(t[a]);return r}function a(n,a,o){function h(n){P=n.cursor;var t=n.rule,e=E+1+(t.c||0);n.line=e,Z.push(n),t.d&&z[e]++,t.e&&(S=r(t.e,j)),t.f&&F.push(null),t.callback&&t.callback(n,z,O)}function d(){var n=Z.pop(),t=n.line,e=n.rule;if(e.d){var r="function"==typeof e.g?e.g(b):e.g,a=r||0!==b.matchIndex?1:0;O[E+a]&&O[E+a].push(t)}e.e&&(S=null),e.f&&F.pop(),F[F.length-1]=n}function m(n,r,a){n=n.substring(a,n.length);for(var l,s,i,c=null,u=n.length,o=F[F.length-1],h=o?o.rule.b:"",d=t(Z,function(n){return n.rule.b}).join("\n"),m=0;m<r.length;m++)i=r[m],i.h&&e(i.h,function(n){return d.indexOf(n)!=-1})||(!i.i||h&&i.i.indexOf(h)!==-1)&&(s=f(n,i.j,i),s.matchIndex!=-1&&s.matchIndex<u&&(!i.k||0===a)&&(u=s.matchIndex,l=s,c=i));return{rule:c,relativeIndex:c?u:-1,matchIndex:c?u+a:-1,cursor:c?a+l.cursor:-1,state:l?l.state:{},lastMatch:o}}function g(n,t,e,r){n=n.substr(e,n.length);var a=t.rule,l=f(n,a.l,a,t.state,r),s=a.m?l.cursor:l.matchIndex;return{endPatternIndex:l.endPatternIndex,matchIndex:l.matchIndex===-1?-1:l.matchIndex+e,cursor:s===-1?-1:s+e,state:l.state}}n=n||"";var b,x,v,p,I,y=o&&null!=o.tabString?o.tabString:"\t",k=n.split(/[\r]?\n/gi),w=k.length,A=s(w),z=s(w),O=l(w),Z=[],F=[null],E=0,P=0,S=null;for(o&&(o.debug={buffers:{ignore:A,indent:z,dedent:O,active:Z}});E<w;){if(v=k[E].trim(),p=u(v)+"\r\n",I=Z[Z.length-1],x=m(p,S||a,P),Z.length)if(b=g(p,I,P,x),b.matchIndex===-1){if(I.rule.n){A[E]=1,E++,P=0;continue}}else if(I.rule.n||x.matchIndex===-1||b.matchIndex<=x.matchIndex){d(),P=b.cursor;continue}x.matchIndex!==-1?h(x):(E++,P=0)}var $,q,R,T,M,C,H=0,L=i(z),_=s(w),B=[];for(M=0;M<w;M++){for(q=O[M],T=0,C=0;C<q.length;C++)R=q[C],R<0?-R!==M&&(_[-R]++,T+=1):L[R]>0&&(L[R]--,T+=R!==M);$=L[M],_[M]=$>T?1:$<T?$-T:0,L[M]=$>0?1:0}for(M=0;M<w;M++)1===A[M-1]&&1===A[M]?B.push(k[M]):(H+=_[M]||0,B.push((H>0?c(y,H):"")+k[M].trim()));return B.join("\r\n")}function l(n){for(var t=new Array(n),e=0;e<n;e++)t[e]=[];return t}function s(t){if(n.Int16Array)return new Int16Array(t);for(var e=new Array(t),r=0;r<t;r++)e[r]=0;return e}function i(n){for(var t=s(n.length),e=0;e<n.length;e++)t[e]=n[e];return t}function c(n,t){return new Array(t+1).join(n)}function u(n){return n.replace(/\\(u[0-9A-Za-z]{4}|u\{[0-9A-Za-z]{1,6}]\}|x[0-9A-Za-z]{2}|.)/g,"0")}function o(n,t,e){var r=n.lastMatch;r&&"="===r.rule.b&&e[n.line].push(-r.line)}function h(n,t,e,r){var a;if(e.newline){if(a=n.search(/[;,=]?\r*\n/),a!==-1)return{matchIndex:a,length:1}}else a=n.search(/[^\s\r\n\{\(\[]/),e.newline=a!==-1&&(a<=r.relativeIndex||r.relativeIndex===-1);return null}function f(n,t,e,r,a){r=r||{};for(var l,s,i=-1,c=0,u=0;u<t.length;u++)if(s=t[u],"function"==typeof s){if(l=s(n,e,r,a)){i=l.matchIndex,c=l.length;break}}else if(l=n.match(s)){i=n.search(s),c=l[0].length;break}return{endPatternIndex:u,matchIndex:i,cursor:i+c,state:r}}var d={};String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")});var m=/\r*\n/,j=[{a:"js html",b:"comment",j:[/\<\!\-\-/],l:[/\-\-\>/],n:!0,m:!0},{a:"html",b:"doctype",j:[/\<\!doctype html>/i],l:[m],n:!0,m:!0},{a:"js html",b:"void-tags",j:[/\<(area|base|br|col|command|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)/i],l:[/>/],d:!0,m:!0},{a:"html",b:"mode switch js",j:[function(n){var t=/<script[\s>].*/i,e=/<\/script>/i,r=t.exec(n),a=e.exec(n);return r&&(!a||a.index<r.index)?{matchIndex:r.index,length:r[0].length}:null}],l:[/<\/script>/i],e:"js",m:!0,d:!0,f:!0},{a:"html",b:"mode switch css",j:[function(n){var t=/<style[\s>].*/i,e=/<\/style>/i,r=t.exec(n),a=e.exec(n);return r&&(!a||a.index<r.index)?{matchIndex:r.index,length:r[0].length}:null}],l:[/<\/style>/i],e:"css",m:!0,d:!0,f:!0},{a:"html",b:"html-tag",j:[/<html[^A-Za-z0-9]/i],l:[/<\/html>/i],m:!0},{a:"js html",b:"tag",h:["="],j:[function(n,t,e){var r=/<([A-Za-z][A-Za-z0-9\-\.]+)/,a=n.match(r);return a?(e.openingTag=a[1],{matchIndex:a.index,length:a[0].length}):null}],l:[function(n,t,e){var r=new RegExp("</"+e.openingTag+">|\\s/>","i"),a=n.match(r);return a?{matchIndex:a.index,length:a[0].length}:null}],d:!0,m:!0},{a:"js",b:"line-comment",j:[/\/\//],l:[m],n:!0},{a:"js css",b:"block-comment",j:[/\/\*/],l:[/\*\//],n:!0,m:!0},{a:"js",b:"regex",j:[function(n,t){var e=/[(,=:[!&|?{};][\s]*\/[^\/]|^[\s]*\/[^\/]/,r=n.search(e);if(r!=-1){r=n.indexOf("/",r);var a=n.substring(r+1),l=f(a,t.l,t);if(l.matchIndex!=-1){a=a.substring(0,l.matchIndex);try{return new RegExp(a),{matchIndex:r,length:1}}catch(s){return null}}}return null}],l:[function(n){for(var t=0,e=n.indexOf("/");e!=-1;)try{new RegExp(n.substring(0,e));break}catch(r){e=n.indexOf("/",t),t=e+1}return e===-1?null:{matchIndex:e,length:1}}],n:!0,m:!0},{a:"js html",b:"quotes",j:[/"/],l:[/"/,m],n:!0,m:!0},{a:"js html",b:"quotes",j:[/'/],l:[/'/,m],n:!0,m:!0},{a:"js css",b:"string",j:[/(''|""|``)/],l:[/./,m]},{a:"js css",b:"string",j:[/\"(?=[^"])/],l:[/[^\\]\"/,m],n:!0,m:!0},{a:"js css",b:"string",j:[/\'(?=[^'])/],l:[/[^\\]\'/,m],n:!0,m:!0},{a:"js css",b:"string",j:[/\`(?=[^`])/],l:[/[^\\]\`/],n:!0,m:!0},{a:"js",b:"if",j:[/^if\s*(?=\()/,/[\s]+if\s*(?=\()/],l:[/else[\s]+/,h,/[{;]/],d:!0},{a:"js",b:"for|while",j:[/^(for|while)\s*(?=\()/],l:[h,/[{;]/],d:!0},{a:"js",b:"else",j:[/else[\s]+/],l:[/if[^\w$]/,h,/[{;]/],d:!0},{a:"js css",b:"bracket",j:[/\(\s*(var|let|const)?\s*/],l:[/\)/],d:!0,m:!0,f:!0},{a:"js",b:"dot-chain",j:[/^\.[A-Za-z$_]/],l:[/[\.;]/,m],d:!0,k:!0,c:-1},{a:"js",b:"dot-chain",j:[/\.\s*\r*\n/],l:[/[\.;})\]]/,/[^\s]\s*\r*\n/],d:!0},{a:"js css",b:"array",j:[/\[/],l:[/\]/],d:!0,m:!0,f:!0},{a:"js css",b:"block",j:[/\{/],l:[/\}/],d:!0,m:!0,f:!0},{a:"js",b:"var/let/const",j:[/(var|let|const)[\s]*\r*\n/],l:[h],d:!0,g:!0},{a:"js",b:"var/let/const",j:[/(var|let|const)\s+(?=[\w$])/],l:[/[,;=]/,h],d:!0},{a:"js",b:"var/let/const",i:["var/let/const","="],j:[/,[\s]*\r*\n/],l:[/[,;]/,h],d:!0,callback:o},{a:"js",b:"var/let/const",i:["var/let/const","="],j:[/^,/],l:[/[,;]/,h],k:!0,d:!0,c:-1,callback:o},{a:"js",b:"equality",j:[/[=<>!]=(=)?/],l:[/./]},{a:"js",b:"=",h:["tag","void-tags","html-tag"],j:[/=/],l:[/[,;\)\]}]/,m]},{a:"js",b:"?:",j:[/\?/],l:[/[:;]/],g:!0,d:!0},{a:"js",b:"case",j:[/^(case|default)[\s:]/],l:[/break[\s;\r\n]/,/^return[\s;\r\n]/,/^case[\s]+/,/^default[\s:]/,/}/],g:function(n){return n.endPatternIndex<=1},d:!0,f:!0},{a:"js",b:"semicolon",j:[/;/],l:[/./]}];return{css:function(n,t){return a(n,r("css",j),t)},js:function(n,t){return a(n,r("js",j),t)},ts:function(n,t){return a(n,r("js",j),t)},html:function(n,t){var e=t&&t.indentHtmlTag?r("html",j,"html-tag"):r("html",j);return a(n,e,t)}}}(this);return n}); |
var mode; | ||
var origin = 'https://spck.io'; | ||
var editor = new SpckEditor('#editor'); | ||
@@ -24,2 +23,74 @@ var tabSize = '2'; | ||
}, | ||
'jsx:ant-design': function () {/* | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { | ||
Layout, | ||
Menu, | ||
Breadcrumb, | ||
Icon, | ||
Skeleton | ||
} from 'antd'; | ||
const { SubMenu } = Menu; | ||
const { Header, Content, Sider } = Layout; | ||
ReactDOM.render( | ||
<Layout> | ||
<Header className="header"> | ||
<div className="logo" /> | ||
<Menu | ||
theme="dark" | ||
mode="horizontal" | ||
defaultSelectedKeys={['2']} | ||
style={{ lineHeight: '64px' }} | ||
> | ||
<Menu.Item key="1">Home</Menu.Item> | ||
<Menu.Item key="2">App</Menu.Item> | ||
</Menu> | ||
</Header> | ||
<Layout> | ||
<Sider width={200} style={{ background: '#fff' }}> | ||
<Menu | ||
mode="inline" | ||
defaultSelectedKeys={['1']} | ||
defaultOpenKeys={['sub1']} | ||
style={{ height: '100%', borderRight: 0 }} | ||
> | ||
<SubMenu key="sub1" title={<span><Icon type="user" />User</span>}> | ||
<Menu.Item key="1">option1</Menu.Item> | ||
<Menu.Item key="2">option2</Menu.Item> | ||
<Menu.Item key="3">option3</Menu.Item> | ||
<Menu.Item key="4">option4</Menu.Item> | ||
</SubMenu> | ||
<SubMenu key="sub2" title={<span><Icon type="laptop" />Device</span>}> | ||
<Menu.Item key="5">option5</Menu.Item> | ||
<Menu.Item key="6">option6</Menu.Item> | ||
<Menu.Item key="7">option7</Menu.Item> | ||
<Menu.Item key="8">option8</Menu.Item> | ||
</SubMenu> | ||
<SubMenu key="sub3" title={<span><Icon type="notification" />Notifications</span>}> | ||
<Menu.Item key="9">option9</Menu.Item> | ||
<Menu.Item key="10">option10</Menu.Item> | ||
<Menu.Item key="11">option11</Menu.Item> | ||
<Menu.Item key="12">option12</Menu.Item> | ||
</SubMenu> | ||
</Menu> | ||
</Sider> | ||
<Layout style={{ padding: '0 24px 24px' }}> | ||
<Breadcrumb style={{ margin: '16px 0' }}> | ||
<Breadcrumb.Item>Home</Breadcrumb.Item> | ||
<Breadcrumb.Item>List</Breadcrumb.Item> | ||
<Breadcrumb.Item>App</Breadcrumb.Item> | ||
</Breadcrumb> | ||
<Content style={{ background: '#fff', padding: 24, margin: 0, minHeight: 280 }}> | ||
<Skeleton /> | ||
</Content> | ||
</Layout> | ||
</Layout> | ||
</Layout>, | ||
mountNode); | ||
*/ | ||
}, | ||
'tsx:class': function () {/* | ||
@@ -104,2 +175,4 @@ interface Props { | ||
changeExample('jsx:class'); | ||
}, null, { | ||
maxTries: 50 | ||
}); | ||
@@ -120,3 +193,3 @@ } | ||
mode: mode | ||
}, origin); | ||
}); | ||
} | ||
@@ -133,3 +206,3 @@ | ||
tabSize: tabSizeMap[size] | ||
}, origin); | ||
}); | ||
} | ||
@@ -154,4 +227,4 @@ | ||
text: indent[modeMap[mode]](e.data, {tabString: tabStringMap[tabSize]}) | ||
}, origin); | ||
}); | ||
}); | ||
} |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.SpckEditor=t()}(this,function(){var e=function(e,t){if("string"==typeof e)this.element=document.querySelector(e);else{if(n=e,!("object"==typeof Node?n instanceof Node:n&&"object"==typeof n&&"number"==typeof n.nodeType&&"string"==typeof n.nodeName))throw new Error('Argument "element" must be a selector string or a HTMLElement.');this.element=e}var n;if(!((e=this.element)&&e.contentWindow&&e.contentWindow.postMessage))throw new Error('Argument "element" must be an IFRAME element.');this.contentWindow=e.contentWindow,this.origin=t||"https://spck.io"};return e.prototype={connect:function(t,n,e){var o=(e=e||{}).maxTries||10,i=e.interval||500,r=this.origin,s=this.contentWindow;n=n||function(e){throw new Error(e.message)};var a=0,c=setInterval(function(){if(o<=a)return clearInterval(c),void n({id:1,message:"Connection to iframe window failed: maximum tries exceeded."});var e;a++;try{e=new MessageChannel}catch(e){return clearInterval(c),void n({id:2,message:"MessageChannel not supported."})}e.port1.onmessage=function(e){"connected"==e.data&&(clearInterval(c),t&&t(a))};try{s.postMessage("connect",r,[e.port2])}catch(e){}},i)},configure:function(e){this.contentWindow.postMessage(e,this.origin)},getText:function(e){var t=new MessageChannel;t.port1.onmessage=e,this.contentWindow.postMessage("text",this.origin,[t.port2])}},e}); | ||
!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.SpckEditor=t()}(this,function(){var e=function(e,t){if("string"==typeof e)this.element=document.querySelector(e);else{if(n=e,!("object"==typeof Node?n instanceof Node:n&&"object"==typeof n&&"number"==typeof n.nodeType&&"string"==typeof n.nodeName))throw new Error('Argument "element" must be a selector string or a HTMLElement.');this.element=e}var n;if(!((e=this.element)&&e.contentWindow&&e.contentWindow.postMessage))throw new Error('Argument "element" must be an IFRAME element.');this.contentWindow=e.contentWindow,this.origin=t||"https://embed.spck.io"};return e.prototype={connect:function(t,n,e){var o=(e=e||{}).maxTries||10,i=e.interval||500,r=this.origin,s=this.contentWindow;n=n||function(e){throw new Error(e.message)};var a=0,c=setInterval(function(){if(o<=a)return clearInterval(c),void n({id:1,message:"Connection to iframe window failed: maximum tries exceeded."});var e;a++;try{e=new MessageChannel}catch(e){return clearInterval(c),void n({id:2,message:"MessageChannel not supported."})}e.port1.onmessage=function(e){"connected"==e.data&&(clearInterval(c),t&&t(a))};try{s.postMessage("connect",r,[e.port2])}catch(e){}},i)},configure:function(e){this.contentWindow.postMessage(e,this.origin)},getText:function(e){var t=new MessageChannel;t.port1.onmessage=e,this.contentWindow.postMessage("text",this.origin,[t.port2])}},e}); |
@@ -13,2 +13,21 @@ ;(function(root, factory) { | ||
function map(array, predicate) { | ||
var i, results = []; | ||
for (i=0; i<array.length; i++) { | ||
results.push(predicate(array[i], i, array)); | ||
} | ||
return results; | ||
} | ||
function some(array, predicate) { | ||
var i, result; | ||
for (i=0; i<array.length; i++) { | ||
result = predicate(array[i], i, array); | ||
if (result) { | ||
return result; | ||
} | ||
} | ||
return false; | ||
} | ||
function filterRules(language, rules, excludes) { | ||
@@ -52,2 +71,3 @@ if (rulesCache[language]) | ||
* $lineOffset - added to the line field when rule is applied | ||
* $excludeIf - used to exclude rule matching if any of these rules are active | ||
* $lastRule - used to continue a previous rule | ||
@@ -62,3 +82,3 @@ * $newScope - used to determine if rule creates a new scope, used for lastRule | ||
{ | ||
$languages: "html", | ||
$languages: "js html", | ||
$name: "comment", | ||
@@ -79,3 +99,3 @@ $startPatterns: [/\<\!\-\-/], | ||
{ | ||
$languages: "html", | ||
$languages: "js html", | ||
$name: "void-tags", | ||
@@ -142,6 +162,7 @@ $startPatterns: [ | ||
{ | ||
$languages: "html", | ||
$languages: "js html", | ||
$name: "tag", | ||
$excludeIf: ["="], | ||
$startPatterns: [function (string, rule, state) { | ||
var re = /<([A-Za-z0-9\-]+)/; | ||
var re = /<([A-Za-z][A-Za-z0-9\-\.]+)/; | ||
var match = string.match(re); | ||
@@ -159,3 +180,3 @@ if (match) { | ||
$endPatterns: [function (string, rule, state) { | ||
var re = new RegExp("</" + state.openingTag + ">", "i"); | ||
var re = new RegExp("<\/" + state.openingTag + ">|\\s\/>", "i"); | ||
var match = string.match(re); | ||
@@ -237,3 +258,3 @@ if (match) { | ||
{ | ||
$languages: "html", | ||
$languages: "js html", | ||
$name: "quotes", | ||
@@ -246,3 +267,3 @@ $startPatterns: [/"/], | ||
{ | ||
$languages: "html", | ||
$languages: "js html", | ||
$name: "quotes", | ||
@@ -392,2 +413,3 @@ $startPatterns: [/'/], | ||
$name: "=", | ||
$excludeIf: ["tag", "void-tags", "html-tag"], | ||
$startPatterns: [/=/], | ||
@@ -610,6 +632,12 @@ $endPatterns: [/[,;\)\]}]/, NEW_LINE_REGEX] | ||
var lastRuleInScope = lastMatch ? lastMatch.rule.$name : ''; | ||
var activeRules = map(activeMatches, function (match) { | ||
return match.rule.$name; | ||
}).join('\n'); // Use \n as a special delimiter for rule names | ||
for (var rule, r = 0; r < rules.length; r++) { | ||
rule = rules[r]; | ||
if (!rule.$lastRule || | ||
if (rule.$excludeIf && some(rule.$excludeIf, function (excludeRule) { | ||
return activeRules.indexOf(excludeRule) != -1; | ||
})) { | ||
} else if (!rule.$lastRule || | ||
(lastRuleInScope && rule.$lastRule.indexOf(lastRuleInScope) !== -1) | ||
@@ -616,0 +644,0 @@ ) { |
@@ -1,1 +0,1 @@ | ||
!function(n,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():n.indent=e()}(this,function(){var n=function(n){function e(n,e,t){if(h[n])return h[n];var r=[];h[n]=r,t=t||"";for(var a=0;a<e.length;a++)e[a].a.indexOf(n.toLowerCase())!==-1&&t.indexOf(e[a].b)===-1&&r.push(e[a]);return r}function t(n,t,c){function u(n){Z=n.cursor;var t=n.rule,r=O+1+(t.c||0);n.line=r,z.push(n),t.d&&w[r]++,t.e&&(E=e(t.e,f)),t.f&&F.push(null),t.callback&&t.callback(n,w,A)}function h(){var n=z.pop(),e=n.line,t=n.rule;if(t.d){var r="function"==typeof t.g?t.g(g):t.g,a=r||0!==g.matchIndex?1:0;A[O+a]&&A[O+a].push(e)}t.e&&(E=null),t.f&&F.pop(),F[F.length-1]=n}function d(n,e,t){n=n.substring(t,n.length);for(var r,a,i,s=null,l=n.length,c=F[F.length-1],u=c?c.rule.b:"",h=0;h<e.length;h++)i=e[h],(!i.h||u&&i.h.indexOf(u)!==-1)&&(a=o(n,i.i,i),a.matchIndex!=-1&&a.matchIndex<l&&(!i.j||0===t)&&(l=a.matchIndex,r=a,s=i));return{rule:s,relativeIndex:s?l:-1,matchIndex:s?l+t:-1,cursor:s?t+r.cursor:-1,state:r?r.state:{},lastMatch:c}}function m(n,e,t,r){n=n.substr(t,n.length);var a=e.rule,i=o(n,a.k,a,e.state,r),s=a.l?i.cursor:i.matchIndex;return{endPatternIndex:i.endPatternIndex,matchIndex:i.matchIndex===-1?-1:i.matchIndex+t,cursor:s===-1?-1:s+t,state:i.state}}n=n||"";var g,b,x,k,v,p=c&&null!=c.tabString?c.tabString:"\t",j=n.split(/[\r]?\n/gi),I=j.length,y=a(I),w=a(I),A=r(I),z=[],F=[null],O=0,Z=0,E=null;for(c&&(c.debug={buffers:{ignore:y,indent:w,dedent:A,active:z}});O<I;){if(x=j[O].trim(),k=l(x)+"\r\n",v=z[z.length-1],b=d(k,E||t,Z),z.length)if(g=m(k,v,Z,b),g.matchIndex===-1){if(v.rule.m){y[O]=1,O++,Z=0;continue}}else if(v.rule.m||b.matchIndex===-1||g.matchIndex<=b.matchIndex){h(),Z=g.cursor;continue}b.matchIndex!==-1?u(b):(O++,Z=0)}var P,S,$,q,R,T,M=0,C=i(w),H=a(I),L=[];for(R=0;R<I;R++){for(S=A[R],q=0,T=0;T<S.length;T++)$=S[T],$<0?-$!==R&&(H[-$]++,q+=1):C[$]>0&&(C[$]--,q+=$!==R);P=C[R],H[R]=P>q?1:P<q?P-q:0,C[R]=P>0?1:0}for(R=0;R<I;R++)1===y[R-1]&&1===y[R]?L.push(j[R]):(M+=H[R]||0,L.push((M>0?s(p,M):"")+j[R].trim()));return L.join("\r\n")}function r(n){for(var e=new Array(n),t=0;t<n;t++)e[t]=[];return e}function a(e){if(n.Int16Array)return new Int16Array(e);for(var t=new Array(e),r=0;r<e;r++)t[r]=0;return t}function i(n){for(var e=a(n.length),t=0;t<n.length;t++)e[t]=n[t];return e}function s(n,e){return new Array(e+1).join(n)}function l(n){return n.replace(/\\(u[0-9A-Za-z]{4}|u\{[0-9A-Za-z]{1,6}]\}|x[0-9A-Za-z]{2}|.)/g,"0")}function c(n,e,t){var r=n.lastMatch;r&&"="===r.rule.b&&t[n.line].push(-r.line)}function u(n,e,t,r){var a;if(t.newline){if(a=n.search(/[;,=]?\r*\n/),a!==-1)return{matchIndex:a,length:1}}else a=n.search(/[^\s\r\n\{\(\[]/),t.newline=a!==-1&&(a<=r.relativeIndex||r.relativeIndex===-1);return null}function o(n,e,t,r,a){r=r||{};for(var i,s,l=-1,c=0,u=0;u<e.length;u++)if(s=e[u],"function"==typeof s){if(i=s(n,t,r,a)){l=i.matchIndex,c=i.length;break}}else if(i=n.match(s)){l=n.search(s),c=i[0].length;break}return{endPatternIndex:u,matchIndex:l,cursor:l+c,state:r}}var h={};String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")});var d=/\r*\n/,f=[{a:"html",b:"comment",i:[/\<\!\-\-/],k:[/\-\-\>/],m:!0,l:!0},{a:"html",b:"doctype",i:[/\<\!doctype html>/i],k:[d],m:!0,l:!0},{a:"html",b:"void-tags",i:[/\<(area|base|br|col|command|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)/i],k:[/>/],d:!0,l:!0},{a:"html",b:"mode switch js",i:[function(n){var e=/<script[\s>].*/i,t=/<\/script>/i,r=e.exec(n),a=t.exec(n);return r&&(!a||a.index<r.index)?{matchIndex:r.index,length:r[0].length}:null}],k:[/<\/script>/i],e:"js",l:!0,d:!0,f:!0},{a:"html",b:"mode switch css",i:[function(n){var e=/<style[\s>].*/i,t=/<\/style>/i,r=e.exec(n),a=t.exec(n);return r&&(!a||a.index<r.index)?{matchIndex:r.index,length:r[0].length}:null}],k:[/<\/style>/i],e:"css",l:!0,d:!0,f:!0},{a:"html",b:"html-tag",i:[/<html[^A-Za-z0-9]/i],k:[/<\/html>/i],l:!0},{a:"html",b:"tag",i:[function(n,e,t){var r=/<([A-Za-z0-9\-]+)/,a=n.match(r);return a?(t.openingTag=a[1],{matchIndex:a.index,length:a[0].length}):null}],k:[function(n,e,t){var r=new RegExp("</"+t.openingTag+">","i"),a=n.match(r);return a?{matchIndex:a.index,length:a[0].length}:null}],d:!0,l:!0},{a:"js",b:"line-comment",i:[/\/\//],k:[d],m:!0},{a:"js css",b:"block-comment",i:[/\/\*/],k:[/\*\//],m:!0,l:!0},{a:"js",b:"regex",i:[function(n,e){var t=/[(,=:[!&|?{};][\s]*\/[^\/]|^[\s]*\/[^\/]/,r=n.search(t);if(r!=-1){r=n.indexOf("/",r);var a=n.substring(r+1),i=o(a,e.k,e);if(i.matchIndex!=-1){a=a.substring(0,i.matchIndex);try{return new RegExp(a),{matchIndex:r,length:1}}catch(s){return null}}}return null}],k:[function(n){for(var e=0,t=n.indexOf("/");t!=-1;)try{new RegExp(n.substring(0,t));break}catch(r){t=n.indexOf("/",e),e=t+1}return t===-1?null:{matchIndex:t,length:1}}],m:!0,l:!0},{a:"html",b:"quotes",i:[/"/],k:[/"/,d],m:!0,l:!0},{a:"html",b:"quotes",i:[/'/],k:[/'/,d],m:!0,l:!0},{a:"js css",b:"string",i:[/(''|""|``)/],k:[/./,d]},{a:"js css",b:"string",i:[/\"(?=[^"])/],k:[/[^\\]\"/,d],m:!0,l:!0},{a:"js css",b:"string",i:[/\'(?=[^'])/],k:[/[^\\]\'/,d],m:!0,l:!0},{a:"js css",b:"string",i:[/\`(?=[^`])/],k:[/[^\\]\`/],m:!0,l:!0},{a:"js",b:"if",i:[/^if\s*(?=\()/,/[\s]+if\s*(?=\()/],k:[/else[\s]+/,u,/[{;]/],d:!0},{a:"js",b:"for|while",i:[/^(for|while)\s*(?=\()/],k:[u,/[{;]/],d:!0},{a:"js",b:"else",i:[/else[\s]+/],k:[/if[^\w$]/,u,/[{;]/],d:!0},{a:"js css",b:"bracket",i:[/\(\s*(var|let|const)?\s*/],k:[/\)/],d:!0,l:!0,f:!0},{a:"js",b:"dot-chain",i:[/^\.[A-Za-z$_]/],k:[/[\.;]/,d],d:!0,j:!0,c:-1},{a:"js",b:"dot-chain",i:[/\.\s*\r*\n/],k:[/[\.;})\]]/,/[^\s]\s*\r*\n/],d:!0},{a:"js css",b:"array",i:[/\[/],k:[/\]/],d:!0,l:!0,f:!0},{a:"js css",b:"block",i:[/\{/],k:[/\}/],d:!0,l:!0,f:!0},{a:"js",b:"var/let/const",i:[/(var|let|const)[\s]*\r*\n/],k:[u],d:!0,g:!0},{a:"js",b:"var/let/const",i:[/(var|let|const)\s+(?=[\w$])/],k:[/[,;=]/,u],d:!0},{a:"js",b:"var/let/const",h:["var/let/const","="],i:[/,[\s]*\r*\n/],k:[/[,;]/,u],d:!0,callback:c},{a:"js",b:"var/let/const",h:["var/let/const","="],i:[/^,/],k:[/[,;]/,u],j:!0,d:!0,c:-1,callback:c},{a:"js",b:"equality",i:[/[=<>!]=(=)?/],k:[/./]},{a:"js",b:"=",i:[/=/],k:[/[,;\)\]}]/,d]},{a:"js",b:"?:",i:[/\?/],k:[/[:;]/],g:!0,d:!0},{a:"js",b:"case",i:[/^(case|default)[\s:]/],k:[/break[\s;\r\n]/,/^return[\s;\r\n]/,/^case[\s]+/,/^default[\s:]/,/}/],g:function(n){return n.endPatternIndex<=1},d:!0,f:!0},{a:"js",b:"semicolon",i:[/;/],k:[/./]}];return{css:function(n,r){return t(n,e("css",f),r)},js:function(n,r){return t(n,e("js",f),r)},ts:function(n,r){return t(n,e("js",f),r)},html:function(n,r){var a=r&&r.indentHtmlTag?e("html",f,"html-tag"):e("html",f);return t(n,a,r)}}}(this);return n}); | ||
!function(n,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():n.indent=t()}(this,function(){var n=function(n){function t(n,t){var e,r=[];for(e=0;e<n.length;e++)r.push(t(n[e],e,n));return r}function e(n,t){var e,r;for(e=0;e<n.length;e++)if(r=t(n[e],e,n))return r;return!1}function r(n,t,e){if(d[n])return d[n];var r=[];d[n]=r,e=e||"";for(var a=0;a<t.length;a++)t[a].a.indexOf(n.toLowerCase())!==-1&&e.indexOf(t[a].b)===-1&&r.push(t[a]);return r}function a(n,a,o){function h(n){P=n.cursor;var t=n.rule,e=E+1+(t.c||0);n.line=e,Z.push(n),t.d&&z[e]++,t.e&&(S=r(t.e,j)),t.f&&F.push(null),t.callback&&t.callback(n,z,O)}function d(){var n=Z.pop(),t=n.line,e=n.rule;if(e.d){var r="function"==typeof e.g?e.g(b):e.g,a=r||0!==b.matchIndex?1:0;O[E+a]&&O[E+a].push(t)}e.e&&(S=null),e.f&&F.pop(),F[F.length-1]=n}function m(n,r,a){n=n.substring(a,n.length);for(var l,s,i,c=null,u=n.length,o=F[F.length-1],h=o?o.rule.b:"",d=t(Z,function(n){return n.rule.b}).join("\n"),m=0;m<r.length;m++)i=r[m],i.h&&e(i.h,function(n){return d.indexOf(n)!=-1})||(!i.i||h&&i.i.indexOf(h)!==-1)&&(s=f(n,i.j,i),s.matchIndex!=-1&&s.matchIndex<u&&(!i.k||0===a)&&(u=s.matchIndex,l=s,c=i));return{rule:c,relativeIndex:c?u:-1,matchIndex:c?u+a:-1,cursor:c?a+l.cursor:-1,state:l?l.state:{},lastMatch:o}}function g(n,t,e,r){n=n.substr(e,n.length);var a=t.rule,l=f(n,a.l,a,t.state,r),s=a.m?l.cursor:l.matchIndex;return{endPatternIndex:l.endPatternIndex,matchIndex:l.matchIndex===-1?-1:l.matchIndex+e,cursor:s===-1?-1:s+e,state:l.state}}n=n||"";var b,x,v,p,I,y=o&&null!=o.tabString?o.tabString:"\t",k=n.split(/[\r]?\n/gi),w=k.length,A=s(w),z=s(w),O=l(w),Z=[],F=[null],E=0,P=0,S=null;for(o&&(o.debug={buffers:{ignore:A,indent:z,dedent:O,active:Z}});E<w;){if(v=k[E].trim(),p=u(v)+"\r\n",I=Z[Z.length-1],x=m(p,S||a,P),Z.length)if(b=g(p,I,P,x),b.matchIndex===-1){if(I.rule.n){A[E]=1,E++,P=0;continue}}else if(I.rule.n||x.matchIndex===-1||b.matchIndex<=x.matchIndex){d(),P=b.cursor;continue}x.matchIndex!==-1?h(x):(E++,P=0)}var $,q,R,T,M,C,H=0,L=i(z),_=s(w),B=[];for(M=0;M<w;M++){for(q=O[M],T=0,C=0;C<q.length;C++)R=q[C],R<0?-R!==M&&(_[-R]++,T+=1):L[R]>0&&(L[R]--,T+=R!==M);$=L[M],_[M]=$>T?1:$<T?$-T:0,L[M]=$>0?1:0}for(M=0;M<w;M++)1===A[M-1]&&1===A[M]?B.push(k[M]):(H+=_[M]||0,B.push((H>0?c(y,H):"")+k[M].trim()));return B.join("\r\n")}function l(n){for(var t=new Array(n),e=0;e<n;e++)t[e]=[];return t}function s(t){if(n.Int16Array)return new Int16Array(t);for(var e=new Array(t),r=0;r<t;r++)e[r]=0;return e}function i(n){for(var t=s(n.length),e=0;e<n.length;e++)t[e]=n[e];return t}function c(n,t){return new Array(t+1).join(n)}function u(n){return n.replace(/\\(u[0-9A-Za-z]{4}|u\{[0-9A-Za-z]{1,6}]\}|x[0-9A-Za-z]{2}|.)/g,"0")}function o(n,t,e){var r=n.lastMatch;r&&"="===r.rule.b&&e[n.line].push(-r.line)}function h(n,t,e,r){var a;if(e.newline){if(a=n.search(/[;,=]?\r*\n/),a!==-1)return{matchIndex:a,length:1}}else a=n.search(/[^\s\r\n\{\(\[]/),e.newline=a!==-1&&(a<=r.relativeIndex||r.relativeIndex===-1);return null}function f(n,t,e,r,a){r=r||{};for(var l,s,i=-1,c=0,u=0;u<t.length;u++)if(s=t[u],"function"==typeof s){if(l=s(n,e,r,a)){i=l.matchIndex,c=l.length;break}}else if(l=n.match(s)){i=n.search(s),c=l[0].length;break}return{endPatternIndex:u,matchIndex:i,cursor:i+c,state:r}}var d={};String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")});var m=/\r*\n/,j=[{a:"js html",b:"comment",j:[/\<\!\-\-/],l:[/\-\-\>/],n:!0,m:!0},{a:"html",b:"doctype",j:[/\<\!doctype html>/i],l:[m],n:!0,m:!0},{a:"js html",b:"void-tags",j:[/\<(area|base|br|col|command|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)/i],l:[/>/],d:!0,m:!0},{a:"html",b:"mode switch js",j:[function(n){var t=/<script[\s>].*/i,e=/<\/script>/i,r=t.exec(n),a=e.exec(n);return r&&(!a||a.index<r.index)?{matchIndex:r.index,length:r[0].length}:null}],l:[/<\/script>/i],e:"js",m:!0,d:!0,f:!0},{a:"html",b:"mode switch css",j:[function(n){var t=/<style[\s>].*/i,e=/<\/style>/i,r=t.exec(n),a=e.exec(n);return r&&(!a||a.index<r.index)?{matchIndex:r.index,length:r[0].length}:null}],l:[/<\/style>/i],e:"css",m:!0,d:!0,f:!0},{a:"html",b:"html-tag",j:[/<html[^A-Za-z0-9]/i],l:[/<\/html>/i],m:!0},{a:"js html",b:"tag",h:["="],j:[function(n,t,e){var r=/<([A-Za-z][A-Za-z0-9\-\.]+)/,a=n.match(r);return a?(e.openingTag=a[1],{matchIndex:a.index,length:a[0].length}):null}],l:[function(n,t,e){var r=new RegExp("</"+e.openingTag+">|\\s/>","i"),a=n.match(r);return a?{matchIndex:a.index,length:a[0].length}:null}],d:!0,m:!0},{a:"js",b:"line-comment",j:[/\/\//],l:[m],n:!0},{a:"js css",b:"block-comment",j:[/\/\*/],l:[/\*\//],n:!0,m:!0},{a:"js",b:"regex",j:[function(n,t){var e=/[(,=:[!&|?{};][\s]*\/[^\/]|^[\s]*\/[^\/]/,r=n.search(e);if(r!=-1){r=n.indexOf("/",r);var a=n.substring(r+1),l=f(a,t.l,t);if(l.matchIndex!=-1){a=a.substring(0,l.matchIndex);try{return new RegExp(a),{matchIndex:r,length:1}}catch(s){return null}}}return null}],l:[function(n){for(var t=0,e=n.indexOf("/");e!=-1;)try{new RegExp(n.substring(0,e));break}catch(r){e=n.indexOf("/",t),t=e+1}return e===-1?null:{matchIndex:e,length:1}}],n:!0,m:!0},{a:"js html",b:"quotes",j:[/"/],l:[/"/,m],n:!0,m:!0},{a:"js html",b:"quotes",j:[/'/],l:[/'/,m],n:!0,m:!0},{a:"js css",b:"string",j:[/(''|""|``)/],l:[/./,m]},{a:"js css",b:"string",j:[/\"(?=[^"])/],l:[/[^\\]\"/,m],n:!0,m:!0},{a:"js css",b:"string",j:[/\'(?=[^'])/],l:[/[^\\]\'/,m],n:!0,m:!0},{a:"js css",b:"string",j:[/\`(?=[^`])/],l:[/[^\\]\`/],n:!0,m:!0},{a:"js",b:"if",j:[/^if\s*(?=\()/,/[\s]+if\s*(?=\()/],l:[/else[\s]+/,h,/[{;]/],d:!0},{a:"js",b:"for|while",j:[/^(for|while)\s*(?=\()/],l:[h,/[{;]/],d:!0},{a:"js",b:"else",j:[/else[\s]+/],l:[/if[^\w$]/,h,/[{;]/],d:!0},{a:"js css",b:"bracket",j:[/\(\s*(var|let|const)?\s*/],l:[/\)/],d:!0,m:!0,f:!0},{a:"js",b:"dot-chain",j:[/^\.[A-Za-z$_]/],l:[/[\.;]/,m],d:!0,k:!0,c:-1},{a:"js",b:"dot-chain",j:[/\.\s*\r*\n/],l:[/[\.;})\]]/,/[^\s]\s*\r*\n/],d:!0},{a:"js css",b:"array",j:[/\[/],l:[/\]/],d:!0,m:!0,f:!0},{a:"js css",b:"block",j:[/\{/],l:[/\}/],d:!0,m:!0,f:!0},{a:"js",b:"var/let/const",j:[/(var|let|const)[\s]*\r*\n/],l:[h],d:!0,g:!0},{a:"js",b:"var/let/const",j:[/(var|let|const)\s+(?=[\w$])/],l:[/[,;=]/,h],d:!0},{a:"js",b:"var/let/const",i:["var/let/const","="],j:[/,[\s]*\r*\n/],l:[/[,;]/,h],d:!0,callback:o},{a:"js",b:"var/let/const",i:["var/let/const","="],j:[/^,/],l:[/[,;]/,h],k:!0,d:!0,c:-1,callback:o},{a:"js",b:"equality",j:[/[=<>!]=(=)?/],l:[/./]},{a:"js",b:"=",h:["tag","void-tags","html-tag"],j:[/=/],l:[/[,;\)\]}]/,m]},{a:"js",b:"?:",j:[/\?/],l:[/[:;]/],g:!0,d:!0},{a:"js",b:"case",j:[/^(case|default)[\s:]/],l:[/break[\s;\r\n]/,/^return[\s;\r\n]/,/^case[\s]+/,/^default[\s:]/,/}/],g:function(n){return n.endPatternIndex<=1},d:!0,f:!0},{a:"js",b:"semicolon",j:[/;/],l:[/./]}];return{css:function(n,t){return a(n,r("css",j),t)},js:function(n,t){return a(n,r("js",j),t)},ts:function(n,t){return a(n,r("js",j),t)},html:function(n,t){var e=t&&t.indentHtmlTag?r("html",j,"html-tag"):r("html",j);return a(n,e,t)}}}(this);return n}); |
{ | ||
"name": "indent.js", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "Fast minimalistic pure indentation of JavaScript, CSS, and HTML.", | ||
@@ -5,0 +5,0 @@ "main": "lib/indent.js", |
@@ -1,7 +0,9 @@ | ||
# indent.js - pure code indentation for jsx, tsx, ts, js, html, css, less, scss | ||
# indent.js - pure code indentation for js, jsx, json, ts, tsx, html, css, less, scss | ||
[![Build Status](https://travis-ci.org/zebzhao/indent.js.svg?branch=master)](https://travis-ci.org/zebzhao/indent.js) | ||
Fast minimalistic pure code indentation. Indents JavaScript, Typescript, TSX, JSX, CSS, and HTML. Does not do any beautifying of your code, leave it as it is, only correctly indents it following some basic rules. | ||
Fast, minimalistic, pure code indentation. Indents JavaScript, JSON, JSX, Typescript, TSX, CSS, LESS, SCSS, and HTML. Unlike JSBeautify, which adds new lines when reformatting code and changes single line expressions, indent.js preserves new lines in when indenting it. Indent.js is coded with simple, but universal, and unopinionated rules. | ||
Indent.js is thoroughly tested to make sure it correctly indents all styles, and types of code. | ||
*If you like this project please leave a star. Your support is greatly appreciated.* | ||
@@ -18,4 +20,4 @@ | ||
* [Minified (~5 kB) no gzip](https://raw.githubusercontent.com/zebzhao/indent.js/master/lib/indent.js) | ||
* [Not minified (~11 kB) no gzip](https://raw.githubusercontent.com/zebzhao/indent.js/master/lib/indent.js) | ||
* [Minified (~2.7 kB) with gzip](https://raw.githubusercontent.com/zebzhao/indent.js/master/lib/indent.min.js) | ||
* [Not minified (~6 kB) with gzip](https://raw.githubusercontent.com/zebzhao/indent.js/master/lib/indent.js) | ||
@@ -78,3 +80,3 @@ | ||
## Languages still not supported: | ||
## Languages not supported: | ||
@@ -81,0 +83,0 @@ 1. CoffeeScript |
var indent = (function (root) { | ||
var rulesCache = {}; | ||
function map(array, predicate) { | ||
var i, results = []; | ||
for (i=0; i<array.length; i++) { | ||
results.push(predicate(array[i], i, array)); | ||
} | ||
return results; | ||
} | ||
function some(array, predicate) { | ||
var i, result; | ||
for (i=0; i<array.length; i++) { | ||
result = predicate(array[i], i, array); | ||
if (result) { | ||
return result; | ||
} | ||
} | ||
return false; | ||
} | ||
function filterRules(language, rules, excludes) { | ||
@@ -42,2 +61,3 @@ if (rulesCache[language]) | ||
* $lineOffset - added to the line field when rule is applied | ||
* $excludeIf - used to exclude rule matching if any of these rules are active | ||
* $lastRule - used to continue a previous rule | ||
@@ -52,3 +72,3 @@ * $newScope - used to determine if rule creates a new scope, used for lastRule | ||
{ | ||
$languages: "html", | ||
$languages: "js html", | ||
$name: "comment", | ||
@@ -69,3 +89,3 @@ $startPatterns: [/\<\!\-\-/], | ||
{ | ||
$languages: "html", | ||
$languages: "js html", | ||
$name: "void-tags", | ||
@@ -132,6 +152,7 @@ $startPatterns: [ | ||
{ | ||
$languages: "html", | ||
$languages: "js html", | ||
$name: "tag", | ||
$excludeIf: ["="], | ||
$startPatterns: [function (string, rule, state) { | ||
var re = /<([A-Za-z0-9\-]+)/; | ||
var re = /<([A-Za-z][A-Za-z0-9\-\.]+)/; | ||
var match = string.match(re); | ||
@@ -149,3 +170,3 @@ if (match) { | ||
$endPatterns: [function (string, rule, state) { | ||
var re = new RegExp("</" + state.openingTag + ">", "i"); | ||
var re = new RegExp("<\/" + state.openingTag + ">|\\s\/>", "i"); | ||
var match = string.match(re); | ||
@@ -227,3 +248,3 @@ if (match) { | ||
{ | ||
$languages: "html", | ||
$languages: "js html", | ||
$name: "quotes", | ||
@@ -236,3 +257,3 @@ $startPatterns: [/"/], | ||
{ | ||
$languages: "html", | ||
$languages: "js html", | ||
$name: "quotes", | ||
@@ -382,2 +403,3 @@ $startPatterns: [/'/], | ||
$name: "=", | ||
$excludeIf: ["tag", "void-tags", "html-tag"], | ||
$startPatterns: [/=/], | ||
@@ -600,6 +622,12 @@ $endPatterns: [/[,;\)\]}]/, NEW_LINE_REGEX] | ||
var lastRuleInScope = lastMatch ? lastMatch.rule.$name : ''; | ||
var activeRules = map(activeMatches, function (match) { | ||
return match.rule.$name; | ||
}).join('\n'); // Use \n as a special delimiter for rule names | ||
for (var rule, r = 0; r < rules.length; r++) { | ||
rule = rules[r]; | ||
if (!rule.$lastRule || | ||
if (rule.$excludeIf && some(rule.$excludeIf, function (excludeRule) { | ||
return activeRules.indexOf(excludeRule) != -1; | ||
})) { | ||
} else if (!rule.$lastRule || | ||
(lastRuleInScope && rule.$lastRule.indexOf(lastRuleInScope) !== -1) | ||
@@ -606,0 +634,0 @@ ) { |
@@ -19,2 +19,24 @@ var sut = require('../../lib/indent').html; | ||
}); | ||
}); | ||
it('tag with dot', function () { | ||
var expected = ` | ||
<Menu.Item> | ||
<Menu.Item> | ||
</Menu.Item> | ||
</Menu.Item> | ||
`; | ||
expect(sut(expected, {tabString: ts})).to.equal( | ||
expected.replace(/\r*\n/g, '\r\n')); | ||
}); | ||
it('tag with dash', function () { | ||
var expected = ` | ||
<Menu-Item> | ||
<Menu-Item> | ||
</Menu-Item> | ||
</Menu-Item> | ||
`; | ||
expect(sut(expected, {tabString: ts})).to.equal( | ||
expected.replace(/\r*\n/g, '\r\n')); | ||
}); | ||
}); |
@@ -39,2 +39,2 @@ var sut = require('../../lib/indent').js; | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1364560
70
2671
90