simple-syntax-highlighter
Advanced tools
Comparing version 3.0.8 to 3.0.10
@@ -1,3 +0,3 @@ | ||
"use strict";const i=require("vue"),_=["data-type","data-label"],B=["contenteditable"],F={class:"ssh-pre__original"},H={__name:"simple-syntax-highlighter",props:{language:{type:String,default:""},label:{type:[String,Boolean],default:!1},tab:{type:[Boolean,String],default:" "},dark:{type:Boolean,default:!1},copyButton:{type:Boolean,default:!1},editable:{type:Boolean,default:!1}},emits:["copied"],setup(g,{emit:$}){const o={quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,comment:/(\/\/.*?(?:\n|$)|\/\*.*?(?:\*\/|$))/,doctype:/(<!DOCTYPE.*?>)/,htmlTag:/<(?:([a-z][\w:-]*)((?:[\w\- ]+=(?:"[^"]*"|'[^']*'))*|(?:[^&]|&(?:lt|amp|quot|apos|gt);)*?)(\s*\/?)|(\/?)([a-z][\w:-]*))>/,htmlentity:/(&(?:[a-z]+|#x?\d+);)/,punctuation:new RegExp("(!==?|(?:[[\\](){}.:,+\\-?=!])+|(?<!&(?:[a-z]+|#x?\\d+));|\\|\\||<|>|&)"),number:/(-?(?:\.\d+|\d+(?:\.\d+)?))/,boolean:/\b(true|false)\b/},f={shell:{quote:o.quote,comment:/(#.*?)(?:\n|$)/,keyword:/\b(p?npm|yarn|i(?:nstall)?|run|audit|outdated|update|publish|whoami|cd|sudo|chmod|chown|ls|cat|vim?|scp|rm|mv|mkdir|ln|open|cwd|which|clear|curl|ping|systemctl|echo|export|open|bash|exit)\b/,param:/( --(?:save|save-dev))(?:\s|$)/},xml:{doctype:o.doctype,quote:o.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:o.htmlentity,tag:o.htmlTag},html:{doctype:o.doctype,quote:o.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:o.htmlentity,tag:o.htmlTag},"html-vue":{doctype:o.doctype,quote:o.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:o.htmlentity,tag:/<(?:([a-z][\w:-]*)((?:[\w-]+\s*=(?:"[^"]*"|'[^']*'))*|(?:[^&]|&(?:lt|amp|quot|apos|gt);)*?)(\s*\/?)|(\/?)([a-z][\w:-]*))>/},pug:{text:/((?:^|\n)[ \t]*|^)\|([ \t]*)([^\n]+(?=\s*(?:\n|$)))/,text2:/([ \t]*)([.#\w-]+(?:\([^)]*\))*)\.\n((?:\n+(?=\4[ \t]+)|(?=\4[ \t]+).+?(?:\n|$)*?)*)(?=\s*(?:\n|$))/,quote:o.quote,comment:/(^|\n)([ \t]*|^)(\/\/-[ \t]*(?:[^\n]*?(?:\n\10[ \t]+[^\n]*)+|[^\n]+(?=\n|$)))/,tag:/([a-z][\w:-]*|)([.#][a-z][.\w-]*|)(?:\((\s*(?:[@:]?[a-z][\w-]+(?:=(?:"[^"]*"|'[^']*'))*\s*)*)\))?/,"inline-tag":/#\[([^[\]]+)\]/},css:{comment:/(\/\*.+?(?:\*\/|$))/,quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,pseudo:/(:(?:hover|active|focus|visited|not|before|after|(?:first|last|nth)-child))/,"selector keyword vendor":/(@-(?:moz|o|webkit|ms)-(?=keyframes\s))/,"selector keyword":/((?:@(?:import|media|font-face|keyframes)|screen|print|and)(?=[\s({])|keyframes|\s(?:ul|ol|li|table|div|pre|p|a|img|br|hr|h[1-6]|em|strong|span|html|body|iframe|video|audio|input|button|form|label|fieldset|small|abbr|i|dd|dt)\b)(?=.*\{})/,variable:/(--[a-z0-9-]+)/,selector:/((?:[.#-\w*+ >:,[\]="~\n]|>)+)(?=\s*\{)/,"attribute keyword vendor":/(-(?:moz|o|webkit|ms)-(?=transform|transition|user-select|tap-highlight-color|animation|background-size|box-shadow))/,"attribute keyword":/\b(content|float|display|position|top|left|right|bottom|(?:(?:max|min)-)?width|(?:(?:max|min|line)-)?height|font(?:-(?:family|style|size|weight|variant|stretch))?|vertical-align|color|opacity|visibility|z-index|pointer-events|user-select|transform(?:-(?:origin|style|delay|duration|property|timing-function))?|transition(?:-(?:delay|duration))?|animation(?:-(?:name|delay|duration|direction|fill-mode))?|backface-visibility|backdrop-filter|background(?:-(?:color|position|image|repeat|size|attachment|origin|clip|blend-mode))?|(?:padding|margin|border)(?:-(?:top|left|right|bottom))?|border(?:-(?:radius|color|width|style|spacing))|white-space|text-(?:align|transform|decoration|shadow|indent)|overflow(?:-(?:x|y))?|(?:letter|word)-spacing|word-break|box-(?:sizing|shadow)|stroke(?:-(?:width|opacity|dasharray|dashoffset|linecap|linejoin))?|fill|speak|outline|user-select|cursor|flex(?:-(?:direction|flow|grow|shrink|basis|wrap))?|(?:justify|align)-(?:content|self|items))(?=\s*:)/,"value keyword vendor":/(-(?:moz|o|webkit|ms)-(?=linear-gradient))/,"value keyword":/\b(inherit|initial|normal|none|unset|auto|inline(?:-(?:block|flex))?|block|flex|absolute|relative|static|fixed|sticky|hidden|visible|top|left|right|bottom|center|middle|baseline|solid|dotted|dashed|line-through|(?:over|under)line|wavy|double|(?:pre-|no)?wrap|pre|break-word|(?:upper|lower)case|capitalize|italic|bold|attr\(.*?\)|linear|ease(?:-in)?(?:-out)?|all|infinite|cubic-bezier|(?:translate|rotate)(?:[X-Z]|3d)?|skew[XY]?|scale|(?:no-)?repeat|repeat(?:-x|-y)|contain|cover|url|(?:repeating-)?(?:linear|radial)-gradient|inset|pointer|(?:flex-)?(?:start|end)|space-(?:between|evenly|around)|stretch|revert|row(?:-reverse)?|column(?:-reverse)?)(?=\s*[,;}(]|\s+[\da-z!])/,"value keyword important":/( ?!important)/,number:o.number,color:/(transparent|#(?:[\da-f]{6}|[\da-f]{3})|rgba?\([\d., ]*\))/,htmlentity:o.htmlentity,punctuation:/([:,;{}@#()!]+)/,attribute:/([a-z-]+)(?=\s*:)/,unit:/(px|pt|cm|%|r?em|m?s|deg|vh|vw|vmin|vmax)(?=(?:\s*[;,{}})]|\s+[-\da-z#]))/,error:/([:,;{}@#()!]+|<|>|&)/},json:{quote:/("(?:\\"|[^"])*")/,number:o.number,boolean:o.boolean,punctuation:/([[\](){}:,]+)/,error:/(&(:?lt|gt|amp);|(?!\s).)/},js:{quote:o.quote,comment:o.comment,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:o.boolean,this:/\b(this)(?=\W)/,keyword:/\b(new|getElementsBy(?:Tag|Class|)Name|getElementById|querySelector|querySelectorAll|arguments|if|else|do|return|case|default|(?:f|F)unction|typeof|instanceof|undefined|document(?:Element)?|window|console|while|for|forEach|switch|in|break|continue|delete|length|var|let|const|export|import|as|require|from|Class|constructor|Number|Boolean|String|Array|Object|RegExp|Integer|Date|Promise|Proxy|WeakMap|WeakSet|Symbol|SyncManager|File(?:Reader)?|DataTransfer|DocumentFragment|async|await|(?:clear|set)(?:Timeout|Interval)|parse(?:Int|Float)|Math(?=\.)|isNaN|atob|btoa|getComputedStyle)(?=\W)/,htmlentity:o.htmlentity,punctuation:/(!==?|[[\]!(){}:;,+\-%*/?=]+|\.+(?![a-z])|\|\||<|>|&)/,variable:/(\.?[a-z_]\w*)/,"external-var":/(\$|jQuery|JSON)(?=\W|$)/},php:{quote:o.quote,comment:o.comment,special:/(<\?(?:php)?|\?>|__(?:DIR|FILE|LINE|CLASS|METHOD|FUNCTION|NAMESPACE|TRAIT)__)/,punctuation:o.punctuation,number:o.number,boolean:o.boolean,variable:/(\$\w+)/,keyword:/\b(define|echo|die|exit|print_r|var_dump|if|else|elseif|do|return|case|default|function|\$this|while|foreach|for|switch|in|break|continue|empty|isset|unset|parse_ini_file|session_(?:start|destroy|id)|header|json_(?:encode|decode)|error_log|(require|include)(:?_once)?|try|throw|new|Exception|catch|finally|preg_(?:match|replace)|list|strlen|substr|str_replace|array_(?:keys|values))(?=\W|$)/},sql:{quote:o.quote,comment:/((?:--|#)\s.*?(?:\n|$)|\/\*.*?\*\/)/,punctuation:o.punctuation,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:o.boolean,keyword:/\b(\*|DECLARE|BEGIN|END|RETURNS|FUNCTION|CREATE|DATABASE|TABLE|VIEW|COLUMN|INDEX|GRANT|REVOKE|ALL|PRIVILEGES|IDENTIFIED|FLUSH|ALTER|MODIFY|DROP|TRUNCATE|CONSTRAINT|ADD|CHECK|(?:(?:PRIMARY|FOREIGN|UNIQUE) )?KEY|REFERENCES|AUTO_INCREMENT|COMMENT|DEFAULT|UNSIGNED|CHARSET|COLLATE|CHARACTER|ENGINE|SQL_MODE|USE|IF|THEN|NULL|EXISTS|UNIQUE|SELECT|UPDATE|DELETE|(?:INSERT|REPLACE)(?: INTO)?|VALUES|SET|FROM|WHERE|(?:ORDER|GROUP) BY|LIMIT|(?:(?:LEFT|RIGHT|INNER|OUTER|CROSS) |)JOIN|AS|ON|COUNT|AVG|SUM|MIN|MAX|CASE|TO|WHEN|BETWEEN|AND|OR|NOT|IN|LIKE|IS|CONCAT|SUBSTRING|CURRENT_(?:DATE|TIMESTAMP)|USING|HAVING?)(?=\W|$)/,"var-type":/\b((?:var)?char|(?:tiny|small|medium|big)?int|decimal|float|double|real|bit|boolean|date(?:time)?|time(?:stamp)?|year|(?:tiny|medium|long)?(?:text|blob)|enum)\b/}},x={xml:/(\s*)([a-z\d\-:]+)(?:=("|')(.*?)\3)?/g,html:/(\s*)([a-z-]+)(?:=("|')(.*?)\3)?/gs,"html-vue":/(\s*)([@:#]?[a-z\d-]+)(?:(?:=("|')(.*?)\3)|)/gs,pug:/(\s*|,)([@:#]?[a-z\d-]+)(?:(?:=("|')(.*?)\3)|)/g},R={shell:{quote:2},xml:{quote:2,tag:5},html:{quote:2,tag:5},"html-vue":{quote:2,tag:5},pug:{text:3,text2:3,quote:2,comment:3,tag:6},json:{},php:{quote:2},sql:{quote:2},css:{quote:2},js:{quote:2}},u=g,A=$,T=i.ref(Object.keys(f)),d=i.ref(null),v=i.useSlots(),w=t=>t.map(e=>{if(!e.children||typeof e.children=="string")return e.children||"";if(Array.isArray(e.children))return w(e.children);if(e.children.default)return w(e.children.default())}).join(""),y=t=>t.replace(/[<>]/g,e=>({"<":"<",">":">"})[e]),q=t=>{let e,s,l,n,a,c;if(e=t.match(/rgba?\((.*),\s*(.*),\s*(.*?)(?:,\s*([^)]*))\)/))l=parseInt(e[1])<=100,n=parseInt(e[2])<=100,a=parseInt(e[3])<=100,c=parseFloat(e[4])<.3;else if(s=t.match(/#([\da-f]{3}(?:[\da-f]{3})?)/)){const r=s[1].length===3;l=parseInt(s[1][0])<=9,n=parseInt(s[1][r?1:2])<=9,a=parseInt(s[1][r?2:4])<=9}return(l&&n&&a||l&&n&&!a||!l&&n&&a)&&!c},L=()=>{let t="";const e=[];for(const s in f[u.language]){const l=R[u.language][s]||1;for(let n=0;n<l;n++)e.push(s);t+=(t?"|":"")+f[u.language][s].source}return[t,e]},N=t=>{const e=(s,l,n,a,c)=>`${l}<span class="attribute">${n}</span>`+(a||c?'<span class="punctuation">=</span>':"")+(a||c?`<span class="quote">${a||""}${c||""}${a||""}</span>`:"");if(u.language==="pug"){let[s,l="",n="",a="",c="",r=""]=t;return l=l.replace(/#[\w-]+/g,b=>`<span class="id">${b}</span>`).replace(/\.[\w-]+/g,b=>`<span class="class">${b}</span>`),n&&(n=n.replace(x.pug,e),n='<span class="punctuation">(</span>'+n+'<span class="punctuation">)</span>'),r&&(r=k(r)),`<span class="tag-name">${s}</span>${l}${n}`+(a?'<span class="punctuation">.</span>':"")+(c||"")+(r?`<span class="text">${r}</span>`:"")}else{const[s,l="",n="",a="",c]=t,r=l.replace(x[u.language],e);return`<span class="punctuation"><${a}</span><span class="tag-name">${s||c}</span>`+r+`<span class="punctuation">${n}></span>`}},k=t=>t.replace(new RegExp(f.pug["inline-tag"],"gsi"),(e,s)=>'<span class="inline-tag">#[</span>'+s.replace(new RegExp(f.pug.tag,"si"),(l,...n)=>(n=n.slice(0,n.length-2),N(n)))+'<span class="inline-tag">]</span>'),O=()=>{if(T.value.includes(u.language)){const t=z();d.value.innerHTML=E(d.value.innerText),I(d.value.childNodes,t)}},z=()=>{const t=window.getSelection();t.collapseToEnd();const e=new Range;return e.setStart(d.value,0),e.setEnd(t.extentNode,t.extentOffset),e.toString().length},I=(t,e)=>{var l,n;let s=0;for(const a of t){const c=((l=a.innerText)==null?void 0:l.length)||a.length;if(s+c>=e){a.childNodes.length>1?I(a.childNodes,e-s):document.getSelection().setPosition(((n=a.childNodes)==null?void 0:n[0])||a,e-s);break}s+=c}},D=t=>{switch(t.which){case 9:S(u.tab),t.preventDefault();break;case 13:S(` | ||
"use strict";const i=require("vue"),_=["data-type","data-label"],B=["contenteditable"],F={class:"ssh-pre__original"},H={__name:"simple-syntax-highlighter",props:{language:{type:String,default:""},label:{type:[String,Boolean],default:!1},tab:{type:[Boolean,String],default:" "},dark:{type:Boolean,default:!1},copyButton:{type:Boolean,default:!1},editable:{type:Boolean,default:!1}},emits:["copied"],setup(g,{emit:$}){const o={quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,comment:/(\/\/.*?(?:\n|$)|\/\*.*?(?:\*\/|$))/,doctype:/(<!DOCTYPE.*?>)/,htmlTag:/<(?:([a-z][\w:-]*)((?:[\w\- ]+=(?:"[^"]*"|'[^']*'))*|(?:[^&]|&(?:lt|amp|quot|apos|gt);)*?)(\s*\/?)|(\/?)([a-z][\w:-]*))>/,htmlentity:/(&(?:[a-z]+|#x?\d+);)/,punctuation:new RegExp("(!==?|(?:[[\\](){}.:,+\\-?=!])+|(?<!&(?:[a-z]+|#x?\\d+));|\\|\\||<|>|&)"),number:/(-?(?:\.\d+|\d+(?:\.\d+)?))/,boolean:/\b(true|false)\b/},f={shell:{quote:o.quote,comment:/(#.*?)(?:\n|$)/,keyword:/\b(p?npm|yarn|i(?:nstall)?|run|audit|outdated|update|publish|whoami|cd|sudo|chmod|chown|ls|cat|vim?|scp|rm|mv|mkdir|ln|open|cwd|which|clear|curl|ping|systemctl|echo|export|open|bash|exit)\b/,param:/( --(?:save|save-dev))(?:\s|$)/},xml:{doctype:o.doctype,quote:o.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:o.htmlentity,tag:o.htmlTag},html:{doctype:o.doctype,quote:o.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:o.htmlentity,tag:o.htmlTag},"html-vue":{doctype:o.doctype,quote:o.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:o.htmlentity,tag:/<(?:([a-z][\w:-]*)((?:[\w-]+\s*=(?:"[^"]*"|'[^']*'))*|(?:[^&]|&(?:lt|amp|quot|apos|gt);)*?)(\s*\/?)|(\/?)([a-z][\w:-]*))>/},pug:{text:/((?:^|\n)[ \t]*|^)\|([ \t]*)([^\n]+(?=\s*(?:\n|$)))/,text2:/([ \t]*)([.#\w-]+(?:\([^)]*\))*)\.\n((?:\n+(?=\4[ \t]+)|(?=\4[ \t]+).+?(?:\n|$)*?)*)(?=\s*(?:\n|$))/,quote:o.quote,comment:/(^|\n)([ \t]*|^)(\/\/-[ \t]*(?:[^\n]*?(?:\n\10[ \t]+[^\n]*)+|[^\n]+(?=\n|$)))/,tag:/([a-z][\w:-]*|)([.#][a-z][.\w-]*|)\b(?:\((\s*(?:[#@:]?[a-z][\w-.:]+(?:=(?:"[^"]*"|'[^']*'))*\s*)*)\))?(\.?)([ \t]*)([^\n]+)?(?=\n|$)/,"inline-tag":/#\[([^[\]]+)\]/},css:{comment:/(\/\*.+?(?:\*\/|$))/,quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,pseudo:/(:(?:hover|active|focus|visited|not|before|after|(?:first|last|nth)-child))/,"selector keyword vendor":/(@-(?:moz|o|webkit|ms)-(?=keyframes\s))/,"selector keyword":/((?:@(?:import|media|font-face|keyframes)|screen|print|and)(?=[\s({])|keyframes|\s(?:ul|ol|li|table|div|pre|p|a|img|br|hr|h[1-6]|em|strong|span|html|body|iframe|video|audio|input|button|form|label|fieldset|small|abbr|i|dd|dt)\b)(?=.*\{})/,variable:/(--[a-z0-9-]+)/,selector:/((?:[.#-\w*+ >:,[\]="~\n]|>)+)(?=\s*\{)/,"attribute keyword vendor":/(-(?:moz|o|webkit|ms)-(?=transform|transition|user-select|tap-highlight-color|animation|background-size|box-shadow))/,"attribute keyword":/\b(content|float|display|position|top|left|right|bottom|(?:(?:max|min)-)?width|(?:(?:max|min|line)-)?height|font(?:-(?:family|style|size|weight|variant|stretch))?|vertical-align|color|opacity|visibility|z-index|pointer-events|user-select|transform(?:-(?:origin|style|delay|duration|property|timing-function))?|transition(?:-(?:delay|duration))?|animation(?:-(?:name|delay|duration|direction|fill-mode))?|backface-visibility|backdrop-filter|background(?:-(?:color|position|image|repeat|size|attachment|origin|clip|blend-mode))?|(?:padding|margin|border)(?:-(?:top|left|right|bottom))?|border(?:-(?:radius|color|width|style|spacing))|white-space|text-(?:align|transform|decoration|shadow|indent)|overflow(?:-(?:x|y))?|(?:letter|word)-spacing|word-break|box-(?:sizing|shadow)|stroke(?:-(?:width|opacity|dasharray|dashoffset|linecap|linejoin))?|fill|speak|outline|user-select|cursor|flex(?:-(?:direction|flow|grow|shrink|basis|wrap))?|(?:justify|align)-(?:content|self|items))(?=\s*:)/,"value keyword vendor":/(-(?:moz|o|webkit|ms)-(?=linear-gradient))/,"value keyword":/\b(inherit|initial|normal|none|unset|auto|inline(?:-(?:block|flex))?|block|flex|absolute|relative|static|fixed|sticky|hidden|visible|top|left|right|bottom|center|middle|baseline|solid|dotted|dashed|line-through|(?:over|under)line|wavy|double|(?:pre-|no)?wrap|pre|break-word|(?:upper|lower)case|capitalize|italic|bold|attr\(.*?\)|linear|ease(?:-in)?(?:-out)?|all|infinite|cubic-bezier|(?:translate|rotate)(?:[X-Z]|3d)?|skew[XY]?|scale|(?:no-)?repeat|repeat(?:-x|-y)|contain|cover|url|(?:repeating-)?(?:linear|radial)-gradient|inset|pointer|(?:flex-)?(?:start|end)|space-(?:between|evenly|around)|stretch|revert|row(?:-reverse)?|column(?:-reverse)?)(?=\s*[,;}(]|\s+[\da-z!])/,"value keyword important":/( ?!important)/,number:o.number,color:/(transparent|#(?:[\da-f]{6}|[\da-f]{3})|rgba?\([\d., ]*\))/,htmlentity:o.htmlentity,punctuation:/([:,;{}@#()!]+)/,attribute:/([a-z-]+)(?=\s*:)/,unit:/(px|pt|cm|%|r?em|m?s|deg|vh|vw|vmin|vmax)(?=(?:\s*[;,{}})]|\s+[-\da-z#]))/,error:/([:,;{}@#()!]+|<|>|&)/},json:{quote:/("(?:\\"|[^"])*")/,number:o.number,boolean:o.boolean,punctuation:/([[\](){}:,]+)/,error:/(&(:?lt|gt|amp);|(?!\s).)/},js:{quote:o.quote,comment:o.comment,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:o.boolean,this:/\b(this)(?=\W)/,keyword:/\b(new|getElementsBy(?:Tag|Class|)Name|getElementById|querySelector|querySelectorAll|arguments|if|else|do|return|case|default|(?:f|F)unction|typeof|instanceof|undefined|document(?:Element)?|window|console|while|for|forEach|switch|in|break|continue|delete|length|var|let|const|export|import|as|require|from|Class|constructor|Number|Boolean|String|Array|Object|RegExp|Integer|Date|Promise|Proxy|WeakMap|WeakSet|Symbol|SyncManager|File(?:Reader)?|DataTransfer|DocumentFragment|async|await|(?:clear|set)(?:Timeout|Interval)|parse(?:Int|Float)|Math(?=\.)|isNaN|atob|btoa|getComputedStyle)(?=\W)/,htmlentity:o.htmlentity,punctuation:/(!==?|[[\]!(){}:;,+\-%*/?=]+|\.+(?![a-z])|\|\||<|>|&)/,variable:/(\.?[a-z_]\w*)/,"external-var":/(\$|jQuery|JSON)(?=\W|$)/},php:{quote:o.quote,comment:o.comment,special:/(<\?(?:php)?|\?>|__(?:DIR|FILE|LINE|CLASS|METHOD|FUNCTION|NAMESPACE|TRAIT)__)/,punctuation:o.punctuation,number:o.number,boolean:o.boolean,variable:/(\$\w+)/,keyword:/\b(define|echo|die|exit|print_r|var_dump|if|else|elseif|do|return|case|default|function|\$this|while|foreach|for|switch|in|break|continue|empty|isset|unset|parse_ini_file|session_(?:start|destroy|id)|header|json_(?:encode|decode)|error_log|(require|include)(:?_once)?|try|throw|new|Exception|catch|finally|preg_(?:match|replace)|list|strlen|substr|str_replace|array_(?:keys|values))(?=\W|$)/},sql:{quote:o.quote,comment:/((?:--|#)\s.*?(?:\n|$)|\/\*.*?\*\/)/,punctuation:o.punctuation,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:o.boolean,keyword:/\b(\*|DECLARE|BEGIN|END|RETURNS|FUNCTION|CREATE|DATABASE|TABLE|VIEW|COLUMN|INDEX|GRANT|REVOKE|ALL|PRIVILEGES|IDENTIFIED|FLUSH|ALTER|MODIFY|DROP|TRUNCATE|CONSTRAINT|ADD|CHECK|(?:(?:PRIMARY|FOREIGN|UNIQUE) )?KEY|REFERENCES|AUTO_INCREMENT|COMMENT|DEFAULT|UNSIGNED|CHARSET|COLLATE|CHARACTER|ENGINE|SQL_MODE|USE|IF|THEN|NULL|EXISTS|UNIQUE|SELECT|UPDATE|DELETE|(?:INSERT|REPLACE)(?: INTO)?|VALUES|SET|FROM|WHERE|(?:ORDER|GROUP) BY|LIMIT|(?:(?:LEFT|RIGHT|INNER|OUTER|CROSS) |)JOIN|AS|ON|COUNT|AVG|SUM|MIN|MAX|CASE|TO|WHEN|BETWEEN|AND|OR|NOT|IN|LIKE|IS|CONCAT|SUBSTRING|CURRENT_(?:DATE|TIMESTAMP)|USING|HAVING?)(?=\W|$)/,"var-type":/\b((?:var)?char|(?:tiny|small|medium|big)?int|decimal|float|double|real|bit|boolean|date(?:time)?|time(?:stamp)?|year|(?:tiny|medium|long)?(?:text|blob)|enum)\b/}},x={xml:/(\s*)([a-z\d\-:]+)(?:=("|')(.*?)\3)?/g,html:/(\s*)([a-z-]+)(?:=("|')(.*?)\3)?/gs,"html-vue":/(\s*)([@:#]?[a-z\d-]+)(?:(?:=("|')(.*?)\3)|)/gs,pug:/(\s*|,)([@:#]?[a-z\d-]+)(?:(?:=("|')(.*?)\3)|)/g},R={shell:{quote:2},xml:{quote:2,tag:5},html:{quote:2,tag:5},"html-vue":{quote:2,tag:5},pug:{text:3,text2:3,quote:2,comment:3,tag:6},json:{},php:{quote:2},sql:{quote:2},css:{quote:2},js:{quote:2}},u=g,A=$,T=i.ref(Object.keys(f)),d=i.ref(null),v=i.useSlots(),w=t=>t.map(e=>{if(!e.children||typeof e.children=="string")return e.children||"";if(Array.isArray(e.children))return w(e.children);if(e.children.default)return w(e.children.default())}).join(""),y=t=>t.replace(/[<>]/g,e=>({"<":"<",">":">"})[e]),q=t=>{let e,s,l,n,a,c;if(e=t.match(/rgba?\((.*),\s*(.*),\s*(.*?)(?:,\s*([^)]*))\)/))l=parseInt(e[1])<=100,n=parseInt(e[2])<=100,a=parseInt(e[3])<=100,c=parseFloat(e[4])<.3;else if(s=t.match(/#([\da-f]{3}(?:[\da-f]{3})?)/)){const r=s[1].length===3;l=parseInt(s[1][0])<=9,n=parseInt(s[1][r?1:2])<=9,a=parseInt(s[1][r?2:4])<=9}return(l&&n&&a||l&&n&&!a||!l&&n&&a)&&!c},L=()=>{let t="";const e=[];for(const s in f[u.language]){const l=R[u.language][s]||1;for(let n=0;n<l;n++)e.push(s);t+=(t?"|":"")+f[u.language][s].source}return[t,e]},N=t=>{const e=(s,l,n,a,c)=>`${l}<span class="attribute">${n}</span>`+(a||c?'<span class="punctuation">=</span>':"")+(a||c?`<span class="quote">${a||""}${c||""}${a||""}</span>`:"");if(u.language==="pug"){let[s,l="",n="",a="",c="",r=""]=t;return l=l.replace(/#[\w-]+/g,b=>`<span class="id">${b}</span>`).replace(/\.[\w-]+/g,b=>`<span class="class">${b}</span>`),n&&(n=n.replace(x.pug,e),n='<span class="punctuation">(</span>'+n+'<span class="punctuation">)</span>'),r&&(r=k(r)),`<span class="tag-name">${s}</span>${l}${n}`+(a?'<span class="punctuation">.</span>':"")+(c||"")+(r?`<span class="text">${r}</span>`:"")}else{const[s,l="",n="",a="",c]=t,r=l.replace(x[u.language],e);return`<span class="punctuation"><${a}</span><span class="tag-name">${s||c}</span>`+r+`<span class="punctuation">${n}></span>`}},k=t=>t.replace(new RegExp(f.pug["inline-tag"],"gsi"),(e,s)=>'<span class="inline-tag">#[</span>'+s.replace(new RegExp(f.pug.tag,"si"),(l,...n)=>(n=n.slice(0,n.length-2),N(n)))+'<span class="inline-tag">]</span>'),O=()=>{if(T.value.includes(u.language)){const t=z();d.value.innerHTML=E(d.value.innerText),I(d.value.childNodes,t)}},z=()=>{const t=window.getSelection();t.collapseToEnd();const e=new Range;return e.setStart(d.value,0),e.setEnd(t.extentNode,t.extentOffset),e.toString().length},I=(t,e)=>{var l,n;let s=0;for(const a of t){const c=((l=a.innerText)==null?void 0:l.length)||a.length;if(s+c>=e){a.childNodes.length>1?I(a.childNodes,e-s):document.getSelection().setPosition(((n=a.childNodes)==null?void 0:n[0])||a,e-s);break}s+=c}},D=t=>{switch(t.which){case 9:S(u.tab),t.preventDefault();break;case 13:S(` | ||
`),t.preventDefault();break}},S=t=>{const e=window.getSelection(),s=e.getRangeAt(0),l=document.createTextNode(t);s.insertNode(l),e.collapseToEnd()},E=t=>{if(!T.value.includes(u.language))return t;const[e,s]=L();return y(t.replace(/&/g,"&")).replace(new RegExp(e,"gsi"),(l,...n)=>{n=n.slice(0,n.length-2);let a;const c=u.language==="pug";let r=n.find((p,m)=>p&&(a=s[m])&&p);if(["punctuation","quote","htmlentity"].includes(a))r=y(r);else if(a==="comment")if(c){const[p,m,h]=n.slice(s.indexOf("comment"));r=`${p}${m}${y(h)}`}else r=y(r);else if(a==="text"&&c){let[p,m,h]=n;return h=k(h),`${p}<span class="punctuation">|</span>${m}<span class="text">${h}</span>`}else if(a==="text2"&&c){const[,,,p,m,h]=n,U=E(m);return`${p}${U}<span class="punctuation">.</span> | ||
<span class="text">${h}</span>`}else{if(a==="tag"&&["xml","html","html-vue","pug"].includes(u.language))return N(n.slice(s.indexOf("tag")));if(a==="variable"&&r[0]==="."&&u.language==="js")return`<span class="punctuation">.</span><span class="obj-attr">${r.substr(1)}</span>`}let b="";return a==="color"&&u.language==="css"&&(b=` style="background-color: ${r};color: #${q(r)?"fff":"000"}"`),a&&`<span class="${a}"${b}>${r}</span>`||""})},C=()=>v.default&&w(v.default())||"",M=t=>{t.target.insertAdjacentHTML("afterend",`<textarea id="clipboard-textarea">${d.value.innerText}</textarea>`);const e=document.getElementById("clipboard-textarea");e.select(),e.setSelectionRange(0,99999),document.execCommand("copy"),e.remove(),A("copied",d.value.innerText)};return i.onMounted(()=>{const t=C();d.value.innerText=t,d.value.innerHTML=E(d.value.innerText)}),i.onBeforeUpdate(()=>{d.value&&(d.value.innerHTML=E(C()))}),(t,e)=>(i.openBlock(),i.createElementBlock("div",{class:i.normalizeClass(["ssh-pre",{"ssh-pre--dark":g.dark}]),"data-type":g.language,"data-label":g.label||null},[g.copyButton?(i.openBlock(),i.createElementBlock("button",{key:0,class:"ssh-pre__copy",onClick:M},[i.renderSlot(t.$slots,"copy-button",{},()=>[i.createTextVNode("Copy")])])):i.createCommentVNode("",!0),i.createTextVNode(),i.createElementVNode("pre",{ref_key:"codeEl",ref:d,class:"ssh-pre__content",contenteditable:g.editable?"true":"false",onKeydown:e[0]||(e[0]=s=>g.editable&&D(s)),onInput:O}," ",40,B),i.createTextVNode(),i.createElementVNode("div",F,[i.renderSlot(t.$slots,"default")])],10,_))}};module.exports=H; |
@@ -80,3 +80,3 @@ import { ref as $, useSlots as j, onMounted as G, onBeforeUpdate as W, openBlock as R, createElementBlock as A, normalizeClass as V, renderSlot as q, createTextVNode as w, createCommentVNode as K, createElementVNode as L } from "vue"; | ||
// inside. | ||
tag: /([a-z][\w:-]*|)([.#][a-z][.\w-]*|)(?:\((\s*(?:[@:]?[a-z][\w-]+(?:=(?:"[^"]*"|'[^']*'))*\s*)*)\))?/, | ||
tag: /([a-z][\w:-]*|)([.#][a-z][.\w-]*|)\b(?:\((\s*(?:[#@:]?[a-z][\w-.:]+(?:=(?:"[^"]*"|'[^']*'))*\s*)*)\))?(\.?)([ \t]*)([^\n]+)?(?=\n|$)/, | ||
"inline-tag": /#\[([^[\]]+)\]/ | ||
@@ -83,0 +83,0 @@ // Only performed inside tags inner texts. |
@@ -1,3 +0,3 @@ | ||
(function(l,b){typeof exports=="object"&&typeof module<"u"?module.exports=b(require("vue")):typeof define=="function"&&define.amd?define(["vue"],b):(l=typeof globalThis<"u"?globalThis:l||self,l.sshpre=b(l.Vue))})(this,function(l){"use strict";const b=["data-type","data-label"],R=["contenteditable"],A={class:"ssh-pre__original"};return{__name:"simple-syntax-highlighter",props:{language:{type:String,default:""},label:{type:[String,Boolean],default:!1},tab:{type:[Boolean,String],default:" "},dark:{type:Boolean,default:!1},copyButton:{type:Boolean,default:!1},editable:{type:Boolean,default:!1}},emits:["copied"],setup(g,{emit:q}){const o={quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,comment:/(\/\/.*?(?:\n|$)|\/\*.*?(?:\*\/|$))/,doctype:/(<!DOCTYPE.*?>)/,htmlTag:/<(?:([a-z][\w:-]*)((?:[\w\- ]+=(?:"[^"]*"|'[^']*'))*|(?:[^&]|&(?:lt|amp|quot|apos|gt);)*?)(\s*\/?)|(\/?)([a-z][\w:-]*))>/,htmlentity:/(&(?:[a-z]+|#x?\d+);)/,punctuation:new RegExp("(!==?|(?:[[\\](){}.:,+\\-?=!])+|(?<!&(?:[a-z]+|#x?\\d+));|\\|\\||<|>|&)"),number:/(-?(?:\.\d+|\d+(?:\.\d+)?))/,boolean:/\b(true|false)\b/},y={shell:{quote:o.quote,comment:/(#.*?)(?:\n|$)/,keyword:/\b(p?npm|yarn|i(?:nstall)?|run|audit|outdated|update|publish|whoami|cd|sudo|chmod|chown|ls|cat|vim?|scp|rm|mv|mkdir|ln|open|cwd|which|clear|curl|ping|systemctl|echo|export|open|bash|exit)\b/,param:/( --(?:save|save-dev))(?:\s|$)/},xml:{doctype:o.doctype,quote:o.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:o.htmlentity,tag:o.htmlTag},html:{doctype:o.doctype,quote:o.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:o.htmlentity,tag:o.htmlTag},"html-vue":{doctype:o.doctype,quote:o.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:o.htmlentity,tag:/<(?:([a-z][\w:-]*)((?:[\w-]+\s*=(?:"[^"]*"|'[^']*'))*|(?:[^&]|&(?:lt|amp|quot|apos|gt);)*?)(\s*\/?)|(\/?)([a-z][\w:-]*))>/},pug:{text:/((?:^|\n)[ \t]*|^)\|([ \t]*)([^\n]+(?=\s*(?:\n|$)))/,text2:/([ \t]*)([.#\w-]+(?:\([^)]*\))*)\.\n((?:\n+(?=\4[ \t]+)|(?=\4[ \t]+).+?(?:\n|$)*?)*)(?=\s*(?:\n|$))/,quote:o.quote,comment:/(^|\n)([ \t]*|^)(\/\/-[ \t]*(?:[^\n]*?(?:\n\10[ \t]+[^\n]*)+|[^\n]+(?=\n|$)))/,tag:/([a-z][\w:-]*|)([.#][a-z][.\w-]*|)(?:\((\s*(?:[@:]?[a-z][\w-]+(?:=(?:"[^"]*"|'[^']*'))*\s*)*)\))?/,"inline-tag":/#\[([^[\]]+)\]/},css:{comment:/(\/\*.+?(?:\*\/|$))/,quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,pseudo:/(:(?:hover|active|focus|visited|not|before|after|(?:first|last|nth)-child))/,"selector keyword vendor":/(@-(?:moz|o|webkit|ms)-(?=keyframes\s))/,"selector keyword":/((?:@(?:import|media|font-face|keyframes)|screen|print|and)(?=[\s({])|keyframes|\s(?:ul|ol|li|table|div|pre|p|a|img|br|hr|h[1-6]|em|strong|span|html|body|iframe|video|audio|input|button|form|label|fieldset|small|abbr|i|dd|dt)\b)(?=.*\{})/,variable:/(--[a-z0-9-]+)/,selector:/((?:[.#-\w*+ >:,[\]="~\n]|>)+)(?=\s*\{)/,"attribute keyword vendor":/(-(?:moz|o|webkit|ms)-(?=transform|transition|user-select|tap-highlight-color|animation|background-size|box-shadow))/,"attribute keyword":/\b(content|float|display|position|top|left|right|bottom|(?:(?:max|min)-)?width|(?:(?:max|min|line)-)?height|font(?:-(?:family|style|size|weight|variant|stretch))?|vertical-align|color|opacity|visibility|z-index|pointer-events|user-select|transform(?:-(?:origin|style|delay|duration|property|timing-function))?|transition(?:-(?:delay|duration))?|animation(?:-(?:name|delay|duration|direction|fill-mode))?|backface-visibility|backdrop-filter|background(?:-(?:color|position|image|repeat|size|attachment|origin|clip|blend-mode))?|(?:padding|margin|border)(?:-(?:top|left|right|bottom))?|border(?:-(?:radius|color|width|style|spacing))|white-space|text-(?:align|transform|decoration|shadow|indent)|overflow(?:-(?:x|y))?|(?:letter|word)-spacing|word-break|box-(?:sizing|shadow)|stroke(?:-(?:width|opacity|dasharray|dashoffset|linecap|linejoin))?|fill|speak|outline|user-select|cursor|flex(?:-(?:direction|flow|grow|shrink|basis|wrap))?|(?:justify|align)-(?:content|self|items))(?=\s*:)/,"value keyword vendor":/(-(?:moz|o|webkit|ms)-(?=linear-gradient))/,"value keyword":/\b(inherit|initial|normal|none|unset|auto|inline(?:-(?:block|flex))?|block|flex|absolute|relative|static|fixed|sticky|hidden|visible|top|left|right|bottom|center|middle|baseline|solid|dotted|dashed|line-through|(?:over|under)line|wavy|double|(?:pre-|no)?wrap|pre|break-word|(?:upper|lower)case|capitalize|italic|bold|attr\(.*?\)|linear|ease(?:-in)?(?:-out)?|all|infinite|cubic-bezier|(?:translate|rotate)(?:[X-Z]|3d)?|skew[XY]?|scale|(?:no-)?repeat|repeat(?:-x|-y)|contain|cover|url|(?:repeating-)?(?:linear|radial)-gradient|inset|pointer|(?:flex-)?(?:start|end)|space-(?:between|evenly|around)|stretch|revert|row(?:-reverse)?|column(?:-reverse)?)(?=\s*[,;}(]|\s+[\da-z!])/,"value keyword important":/( ?!important)/,number:o.number,color:/(transparent|#(?:[\da-f]{6}|[\da-f]{3})|rgba?\([\d., ]*\))/,htmlentity:o.htmlentity,punctuation:/([:,;{}@#()!]+)/,attribute:/([a-z-]+)(?=\s*:)/,unit:/(px|pt|cm|%|r?em|m?s|deg|vh|vw|vmin|vmax)(?=(?:\s*[;,{}})]|\s+[-\da-z#]))/,error:/([:,;{}@#()!]+|<|>|&)/},json:{quote:/("(?:\\"|[^"])*")/,number:o.number,boolean:o.boolean,punctuation:/([[\](){}:,]+)/,error:/(&(:?lt|gt|amp);|(?!\s).)/},js:{quote:o.quote,comment:o.comment,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:o.boolean,this:/\b(this)(?=\W)/,keyword:/\b(new|getElementsBy(?:Tag|Class|)Name|getElementById|querySelector|querySelectorAll|arguments|if|else|do|return|case|default|(?:f|F)unction|typeof|instanceof|undefined|document(?:Element)?|window|console|while|for|forEach|switch|in|break|continue|delete|length|var|let|const|export|import|as|require|from|Class|constructor|Number|Boolean|String|Array|Object|RegExp|Integer|Date|Promise|Proxy|WeakMap|WeakSet|Symbol|SyncManager|File(?:Reader)?|DataTransfer|DocumentFragment|async|await|(?:clear|set)(?:Timeout|Interval)|parse(?:Int|Float)|Math(?=\.)|isNaN|atob|btoa|getComputedStyle)(?=\W)/,htmlentity:o.htmlentity,punctuation:/(!==?|[[\]!(){}:;,+\-%*/?=]+|\.+(?![a-z])|\|\||<|>|&)/,variable:/(\.?[a-z_]\w*)/,"external-var":/(\$|jQuery|JSON)(?=\W|$)/},php:{quote:o.quote,comment:o.comment,special:/(<\?(?:php)?|\?>|__(?:DIR|FILE|LINE|CLASS|METHOD|FUNCTION|NAMESPACE|TRAIT)__)/,punctuation:o.punctuation,number:o.number,boolean:o.boolean,variable:/(\$\w+)/,keyword:/\b(define|echo|die|exit|print_r|var_dump|if|else|elseif|do|return|case|default|function|\$this|while|foreach|for|switch|in|break|continue|empty|isset|unset|parse_ini_file|session_(?:start|destroy|id)|header|json_(?:encode|decode)|error_log|(require|include)(:?_once)?|try|throw|new|Exception|catch|finally|preg_(?:match|replace)|list|strlen|substr|str_replace|array_(?:keys|values))(?=\W|$)/},sql:{quote:o.quote,comment:/((?:--|#)\s.*?(?:\n|$)|\/\*.*?\*\/)/,punctuation:o.punctuation,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:o.boolean,keyword:/\b(\*|DECLARE|BEGIN|END|RETURNS|FUNCTION|CREATE|DATABASE|TABLE|VIEW|COLUMN|INDEX|GRANT|REVOKE|ALL|PRIVILEGES|IDENTIFIED|FLUSH|ALTER|MODIFY|DROP|TRUNCATE|CONSTRAINT|ADD|CHECK|(?:(?:PRIMARY|FOREIGN|UNIQUE) )?KEY|REFERENCES|AUTO_INCREMENT|COMMENT|DEFAULT|UNSIGNED|CHARSET|COLLATE|CHARACTER|ENGINE|SQL_MODE|USE|IF|THEN|NULL|EXISTS|UNIQUE|SELECT|UPDATE|DELETE|(?:INSERT|REPLACE)(?: INTO)?|VALUES|SET|FROM|WHERE|(?:ORDER|GROUP) BY|LIMIT|(?:(?:LEFT|RIGHT|INNER|OUTER|CROSS) |)JOIN|AS|ON|COUNT|AVG|SUM|MIN|MAX|CASE|TO|WHEN|BETWEEN|AND|OR|NOT|IN|LIKE|IS|CONCAT|SUBSTRING|CURRENT_(?:DATE|TIMESTAMP)|USING|HAVING?)(?=\W|$)/,"var-type":/\b((?:var)?char|(?:tiny|small|medium|big)?int|decimal|float|double|real|bit|boolean|date(?:time)?|time(?:stamp)?|year|(?:tiny|medium|long)?(?:text|blob)|enum)\b/}},T={xml:/(\s*)([a-z\d\-:]+)(?:=("|')(.*?)\3)?/g,html:/(\s*)([a-z-]+)(?:=("|')(.*?)\3)?/gs,"html-vue":/(\s*)([@:#]?[a-z\d-]+)(?:(?:=("|')(.*?)\3)|)/gs,pug:/(\s*|,)([@:#]?[a-z\d-]+)(?:(?:=("|')(.*?)\3)|)/g},L={shell:{quote:2},xml:{quote:2,tag:5},html:{quote:2,tag:5},"html-vue":{quote:2,tag:5},pug:{text:3,text2:3,quote:2,comment:3,tag:6},json:{},php:{quote:2},sql:{quote:2},css:{quote:2},js:{quote:2}},u=g,O=q,N=l.ref(Object.keys(y)),d=l.ref(null),k=l.useSlots(),x=t=>t.map(e=>{if(!e.children||typeof e.children=="string")return e.children||"";if(Array.isArray(e.children))return x(e.children);if(e.children.default)return x(e.children.default())}).join(""),E=t=>t.replace(/[<>]/g,e=>({"<":"<",">":">"})[e]),z=t=>{let e,s,r,n,a,c;if(e=t.match(/rgba?\((.*),\s*(.*),\s*(.*?)(?:,\s*([^)]*))\)/))r=parseInt(e[1])<=100,n=parseInt(e[2])<=100,a=parseInt(e[3])<=100,c=parseFloat(e[4])<.3;else if(s=t.match(/#([\da-f]{3}(?:[\da-f]{3})?)/)){const i=s[1].length===3;r=parseInt(s[1][0])<=9,n=parseInt(s[1][i?1:2])<=9,a=parseInt(s[1][i?2:4])<=9}return(r&&n&&a||r&&n&&!a||!r&&n&&a)&&!c},D=()=>{let t="";const e=[];for(const s in y[u.language]){const r=L[u.language][s]||1;for(let n=0;n<r;n++)e.push(s);t+=(t?"|":"")+y[u.language][s].source}return[t,e]},I=t=>{const e=(s,r,n,a,c)=>`${r}<span class="attribute">${n}</span>`+(a||c?'<span class="punctuation">=</span>':"")+(a||c?`<span class="quote">${a||""}${c||""}${a||""}</span>`:"");if(u.language==="pug"){let[s,r="",n="",a="",c="",i=""]=t;return r=r.replace(/#[\w-]+/g,f=>`<span class="id">${f}</span>`).replace(/\.[\w-]+/g,f=>`<span class="class">${f}</span>`),n&&(n=n.replace(T.pug,e),n='<span class="punctuation">(</span>'+n+'<span class="punctuation">)</span>'),i&&(i=S(i)),`<span class="tag-name">${s}</span>${r}${n}`+(a?'<span class="punctuation">.</span>':"")+(c||"")+(i?`<span class="text">${i}</span>`:"")}else{const[s,r="",n="",a="",c]=t,i=r.replace(T[u.language],e);return`<span class="punctuation"><${a}</span><span class="tag-name">${s||c}</span>`+i+`<span class="punctuation">${n}></span>`}},S=t=>t.replace(new RegExp(y.pug["inline-tag"],"gsi"),(e,s)=>'<span class="inline-tag">#[</span>'+s.replace(new RegExp(y.pug.tag,"si"),(r,...n)=>(n=n.slice(0,n.length-2),I(n)))+'<span class="inline-tag">]</span>'),M=()=>{if(N.value.includes(u.language)){const t=_();d.value.innerHTML=w(d.value.innerText),v(d.value.childNodes,t)}},_=()=>{const t=window.getSelection();t.collapseToEnd();const e=new Range;return e.setStart(d.value,0),e.setEnd(t.extentNode,t.extentOffset),e.toString().length},v=(t,e)=>{var r,n;let s=0;for(const a of t){const c=((r=a.innerText)==null?void 0:r.length)||a.length;if(s+c>=e){a.childNodes.length>1?v(a.childNodes,e-s):document.getSelection().setPosition(((n=a.childNodes)==null?void 0:n[0])||a,e-s);break}s+=c}},U=t=>{switch(t.which){case 9:C(u.tab),t.preventDefault();break;case 13:C(` | ||
(function(l,b){typeof exports=="object"&&typeof module<"u"?module.exports=b(require("vue")):typeof define=="function"&&define.amd?define(["vue"],b):(l=typeof globalThis<"u"?globalThis:l||self,l.sshpre=b(l.Vue))})(this,function(l){"use strict";const b=["data-type","data-label"],R=["contenteditable"],A={class:"ssh-pre__original"};return{__name:"simple-syntax-highlighter",props:{language:{type:String,default:""},label:{type:[String,Boolean],default:!1},tab:{type:[Boolean,String],default:" "},dark:{type:Boolean,default:!1},copyButton:{type:Boolean,default:!1},editable:{type:Boolean,default:!1}},emits:["copied"],setup(g,{emit:q}){const o={quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,comment:/(\/\/.*?(?:\n|$)|\/\*.*?(?:\*\/|$))/,doctype:/(<!DOCTYPE.*?>)/,htmlTag:/<(?:([a-z][\w:-]*)((?:[\w\- ]+=(?:"[^"]*"|'[^']*'))*|(?:[^&]|&(?:lt|amp|quot|apos|gt);)*?)(\s*\/?)|(\/?)([a-z][\w:-]*))>/,htmlentity:/(&(?:[a-z]+|#x?\d+);)/,punctuation:new RegExp("(!==?|(?:[[\\](){}.:,+\\-?=!])+|(?<!&(?:[a-z]+|#x?\\d+));|\\|\\||<|>|&)"),number:/(-?(?:\.\d+|\d+(?:\.\d+)?))/,boolean:/\b(true|false)\b/},y={shell:{quote:o.quote,comment:/(#.*?)(?:\n|$)/,keyword:/\b(p?npm|yarn|i(?:nstall)?|run|audit|outdated|update|publish|whoami|cd|sudo|chmod|chown|ls|cat|vim?|scp|rm|mv|mkdir|ln|open|cwd|which|clear|curl|ping|systemctl|echo|export|open|bash|exit)\b/,param:/( --(?:save|save-dev))(?:\s|$)/},xml:{doctype:o.doctype,quote:o.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:o.htmlentity,tag:o.htmlTag},html:{doctype:o.doctype,quote:o.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:o.htmlentity,tag:o.htmlTag},"html-vue":{doctype:o.doctype,quote:o.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:o.htmlentity,tag:/<(?:([a-z][\w:-]*)((?:[\w-]+\s*=(?:"[^"]*"|'[^']*'))*|(?:[^&]|&(?:lt|amp|quot|apos|gt);)*?)(\s*\/?)|(\/?)([a-z][\w:-]*))>/},pug:{text:/((?:^|\n)[ \t]*|^)\|([ \t]*)([^\n]+(?=\s*(?:\n|$)))/,text2:/([ \t]*)([.#\w-]+(?:\([^)]*\))*)\.\n((?:\n+(?=\4[ \t]+)|(?=\4[ \t]+).+?(?:\n|$)*?)*)(?=\s*(?:\n|$))/,quote:o.quote,comment:/(^|\n)([ \t]*|^)(\/\/-[ \t]*(?:[^\n]*?(?:\n\10[ \t]+[^\n]*)+|[^\n]+(?=\n|$)))/,tag:/([a-z][\w:-]*|)([.#][a-z][.\w-]*|)\b(?:\((\s*(?:[#@:]?[a-z][\w-.:]+(?:=(?:"[^"]*"|'[^']*'))*\s*)*)\))?(\.?)([ \t]*)([^\n]+)?(?=\n|$)/,"inline-tag":/#\[([^[\]]+)\]/},css:{comment:/(\/\*.+?(?:\*\/|$))/,quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,pseudo:/(:(?:hover|active|focus|visited|not|before|after|(?:first|last|nth)-child))/,"selector keyword vendor":/(@-(?:moz|o|webkit|ms)-(?=keyframes\s))/,"selector keyword":/((?:@(?:import|media|font-face|keyframes)|screen|print|and)(?=[\s({])|keyframes|\s(?:ul|ol|li|table|div|pre|p|a|img|br|hr|h[1-6]|em|strong|span|html|body|iframe|video|audio|input|button|form|label|fieldset|small|abbr|i|dd|dt)\b)(?=.*\{})/,variable:/(--[a-z0-9-]+)/,selector:/((?:[.#-\w*+ >:,[\]="~\n]|>)+)(?=\s*\{)/,"attribute keyword vendor":/(-(?:moz|o|webkit|ms)-(?=transform|transition|user-select|tap-highlight-color|animation|background-size|box-shadow))/,"attribute keyword":/\b(content|float|display|position|top|left|right|bottom|(?:(?:max|min)-)?width|(?:(?:max|min|line)-)?height|font(?:-(?:family|style|size|weight|variant|stretch))?|vertical-align|color|opacity|visibility|z-index|pointer-events|user-select|transform(?:-(?:origin|style|delay|duration|property|timing-function))?|transition(?:-(?:delay|duration))?|animation(?:-(?:name|delay|duration|direction|fill-mode))?|backface-visibility|backdrop-filter|background(?:-(?:color|position|image|repeat|size|attachment|origin|clip|blend-mode))?|(?:padding|margin|border)(?:-(?:top|left|right|bottom))?|border(?:-(?:radius|color|width|style|spacing))|white-space|text-(?:align|transform|decoration|shadow|indent)|overflow(?:-(?:x|y))?|(?:letter|word)-spacing|word-break|box-(?:sizing|shadow)|stroke(?:-(?:width|opacity|dasharray|dashoffset|linecap|linejoin))?|fill|speak|outline|user-select|cursor|flex(?:-(?:direction|flow|grow|shrink|basis|wrap))?|(?:justify|align)-(?:content|self|items))(?=\s*:)/,"value keyword vendor":/(-(?:moz|o|webkit|ms)-(?=linear-gradient))/,"value keyword":/\b(inherit|initial|normal|none|unset|auto|inline(?:-(?:block|flex))?|block|flex|absolute|relative|static|fixed|sticky|hidden|visible|top|left|right|bottom|center|middle|baseline|solid|dotted|dashed|line-through|(?:over|under)line|wavy|double|(?:pre-|no)?wrap|pre|break-word|(?:upper|lower)case|capitalize|italic|bold|attr\(.*?\)|linear|ease(?:-in)?(?:-out)?|all|infinite|cubic-bezier|(?:translate|rotate)(?:[X-Z]|3d)?|skew[XY]?|scale|(?:no-)?repeat|repeat(?:-x|-y)|contain|cover|url|(?:repeating-)?(?:linear|radial)-gradient|inset|pointer|(?:flex-)?(?:start|end)|space-(?:between|evenly|around)|stretch|revert|row(?:-reverse)?|column(?:-reverse)?)(?=\s*[,;}(]|\s+[\da-z!])/,"value keyword important":/( ?!important)/,number:o.number,color:/(transparent|#(?:[\da-f]{6}|[\da-f]{3})|rgba?\([\d., ]*\))/,htmlentity:o.htmlentity,punctuation:/([:,;{}@#()!]+)/,attribute:/([a-z-]+)(?=\s*:)/,unit:/(px|pt|cm|%|r?em|m?s|deg|vh|vw|vmin|vmax)(?=(?:\s*[;,{}})]|\s+[-\da-z#]))/,error:/([:,;{}@#()!]+|<|>|&)/},json:{quote:/("(?:\\"|[^"])*")/,number:o.number,boolean:o.boolean,punctuation:/([[\](){}:,]+)/,error:/(&(:?lt|gt|amp);|(?!\s).)/},js:{quote:o.quote,comment:o.comment,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:o.boolean,this:/\b(this)(?=\W)/,keyword:/\b(new|getElementsBy(?:Tag|Class|)Name|getElementById|querySelector|querySelectorAll|arguments|if|else|do|return|case|default|(?:f|F)unction|typeof|instanceof|undefined|document(?:Element)?|window|console|while|for|forEach|switch|in|break|continue|delete|length|var|let|const|export|import|as|require|from|Class|constructor|Number|Boolean|String|Array|Object|RegExp|Integer|Date|Promise|Proxy|WeakMap|WeakSet|Symbol|SyncManager|File(?:Reader)?|DataTransfer|DocumentFragment|async|await|(?:clear|set)(?:Timeout|Interval)|parse(?:Int|Float)|Math(?=\.)|isNaN|atob|btoa|getComputedStyle)(?=\W)/,htmlentity:o.htmlentity,punctuation:/(!==?|[[\]!(){}:;,+\-%*/?=]+|\.+(?![a-z])|\|\||<|>|&)/,variable:/(\.?[a-z_]\w*)/,"external-var":/(\$|jQuery|JSON)(?=\W|$)/},php:{quote:o.quote,comment:o.comment,special:/(<\?(?:php)?|\?>|__(?:DIR|FILE|LINE|CLASS|METHOD|FUNCTION|NAMESPACE|TRAIT)__)/,punctuation:o.punctuation,number:o.number,boolean:o.boolean,variable:/(\$\w+)/,keyword:/\b(define|echo|die|exit|print_r|var_dump|if|else|elseif|do|return|case|default|function|\$this|while|foreach|for|switch|in|break|continue|empty|isset|unset|parse_ini_file|session_(?:start|destroy|id)|header|json_(?:encode|decode)|error_log|(require|include)(:?_once)?|try|throw|new|Exception|catch|finally|preg_(?:match|replace)|list|strlen|substr|str_replace|array_(?:keys|values))(?=\W|$)/},sql:{quote:o.quote,comment:/((?:--|#)\s.*?(?:\n|$)|\/\*.*?\*\/)/,punctuation:o.punctuation,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:o.boolean,keyword:/\b(\*|DECLARE|BEGIN|END|RETURNS|FUNCTION|CREATE|DATABASE|TABLE|VIEW|COLUMN|INDEX|GRANT|REVOKE|ALL|PRIVILEGES|IDENTIFIED|FLUSH|ALTER|MODIFY|DROP|TRUNCATE|CONSTRAINT|ADD|CHECK|(?:(?:PRIMARY|FOREIGN|UNIQUE) )?KEY|REFERENCES|AUTO_INCREMENT|COMMENT|DEFAULT|UNSIGNED|CHARSET|COLLATE|CHARACTER|ENGINE|SQL_MODE|USE|IF|THEN|NULL|EXISTS|UNIQUE|SELECT|UPDATE|DELETE|(?:INSERT|REPLACE)(?: INTO)?|VALUES|SET|FROM|WHERE|(?:ORDER|GROUP) BY|LIMIT|(?:(?:LEFT|RIGHT|INNER|OUTER|CROSS) |)JOIN|AS|ON|COUNT|AVG|SUM|MIN|MAX|CASE|TO|WHEN|BETWEEN|AND|OR|NOT|IN|LIKE|IS|CONCAT|SUBSTRING|CURRENT_(?:DATE|TIMESTAMP)|USING|HAVING?)(?=\W|$)/,"var-type":/\b((?:var)?char|(?:tiny|small|medium|big)?int|decimal|float|double|real|bit|boolean|date(?:time)?|time(?:stamp)?|year|(?:tiny|medium|long)?(?:text|blob)|enum)\b/}},T={xml:/(\s*)([a-z\d\-:]+)(?:=("|')(.*?)\3)?/g,html:/(\s*)([a-z-]+)(?:=("|')(.*?)\3)?/gs,"html-vue":/(\s*)([@:#]?[a-z\d-]+)(?:(?:=("|')(.*?)\3)|)/gs,pug:/(\s*|,)([@:#]?[a-z\d-]+)(?:(?:=("|')(.*?)\3)|)/g},L={shell:{quote:2},xml:{quote:2,tag:5},html:{quote:2,tag:5},"html-vue":{quote:2,tag:5},pug:{text:3,text2:3,quote:2,comment:3,tag:6},json:{},php:{quote:2},sql:{quote:2},css:{quote:2},js:{quote:2}},u=g,O=q,N=l.ref(Object.keys(y)),d=l.ref(null),k=l.useSlots(),x=t=>t.map(e=>{if(!e.children||typeof e.children=="string")return e.children||"";if(Array.isArray(e.children))return x(e.children);if(e.children.default)return x(e.children.default())}).join(""),E=t=>t.replace(/[<>]/g,e=>({"<":"<",">":">"})[e]),z=t=>{let e,s,r,n,a,c;if(e=t.match(/rgba?\((.*),\s*(.*),\s*(.*?)(?:,\s*([^)]*))\)/))r=parseInt(e[1])<=100,n=parseInt(e[2])<=100,a=parseInt(e[3])<=100,c=parseFloat(e[4])<.3;else if(s=t.match(/#([\da-f]{3}(?:[\da-f]{3})?)/)){const i=s[1].length===3;r=parseInt(s[1][0])<=9,n=parseInt(s[1][i?1:2])<=9,a=parseInt(s[1][i?2:4])<=9}return(r&&n&&a||r&&n&&!a||!r&&n&&a)&&!c},D=()=>{let t="";const e=[];for(const s in y[u.language]){const r=L[u.language][s]||1;for(let n=0;n<r;n++)e.push(s);t+=(t?"|":"")+y[u.language][s].source}return[t,e]},I=t=>{const e=(s,r,n,a,c)=>`${r}<span class="attribute">${n}</span>`+(a||c?'<span class="punctuation">=</span>':"")+(a||c?`<span class="quote">${a||""}${c||""}${a||""}</span>`:"");if(u.language==="pug"){let[s,r="",n="",a="",c="",i=""]=t;return r=r.replace(/#[\w-]+/g,f=>`<span class="id">${f}</span>`).replace(/\.[\w-]+/g,f=>`<span class="class">${f}</span>`),n&&(n=n.replace(T.pug,e),n='<span class="punctuation">(</span>'+n+'<span class="punctuation">)</span>'),i&&(i=S(i)),`<span class="tag-name">${s}</span>${r}${n}`+(a?'<span class="punctuation">.</span>':"")+(c||"")+(i?`<span class="text">${i}</span>`:"")}else{const[s,r="",n="",a="",c]=t,i=r.replace(T[u.language],e);return`<span class="punctuation"><${a}</span><span class="tag-name">${s||c}</span>`+i+`<span class="punctuation">${n}></span>`}},S=t=>t.replace(new RegExp(y.pug["inline-tag"],"gsi"),(e,s)=>'<span class="inline-tag">#[</span>'+s.replace(new RegExp(y.pug.tag,"si"),(r,...n)=>(n=n.slice(0,n.length-2),I(n)))+'<span class="inline-tag">]</span>'),M=()=>{if(N.value.includes(u.language)){const t=_();d.value.innerHTML=w(d.value.innerText),v(d.value.childNodes,t)}},_=()=>{const t=window.getSelection();t.collapseToEnd();const e=new Range;return e.setStart(d.value,0),e.setEnd(t.extentNode,t.extentOffset),e.toString().length},v=(t,e)=>{var r,n;let s=0;for(const a of t){const c=((r=a.innerText)==null?void 0:r.length)||a.length;if(s+c>=e){a.childNodes.length>1?v(a.childNodes,e-s):document.getSelection().setPosition(((n=a.childNodes)==null?void 0:n[0])||a,e-s);break}s+=c}},U=t=>{switch(t.which){case 9:C(u.tab),t.preventDefault();break;case 13:C(` | ||
`),t.preventDefault();break}},C=t=>{const e=window.getSelection(),s=e.getRangeAt(0),r=document.createTextNode(t);s.insertNode(r),e.collapseToEnd()},w=t=>{if(!N.value.includes(u.language))return t;const[e,s]=D();return E(t.replace(/&/g,"&")).replace(new RegExp(e,"gsi"),(r,...n)=>{n=n.slice(0,n.length-2);let a;const c=u.language==="pug";let i=n.find((p,m)=>p&&(a=s[m])&&p);if(["punctuation","quote","htmlentity"].includes(a))i=E(i);else if(a==="comment")if(c){const[p,m,h]=n.slice(s.indexOf("comment"));i=`${p}${m}${E(h)}`}else i=E(i);else if(a==="text"&&c){let[p,m,h]=n;return h=S(h),`${p}<span class="punctuation">|</span>${m}<span class="text">${h}</span>`}else if(a==="text2"&&c){const[,,,p,m,h]=n,F=w(m);return`${p}${F}<span class="punctuation">.</span> | ||
<span class="text">${h}</span>`}else{if(a==="tag"&&["xml","html","html-vue","pug"].includes(u.language))return I(n.slice(s.indexOf("tag")));if(a==="variable"&&i[0]==="."&&u.language==="js")return`<span class="punctuation">.</span><span class="obj-attr">${i.substr(1)}</span>`}let f="";return a==="color"&&u.language==="css"&&(f=` style="background-color: ${i};color: #${z(i)?"fff":"000"}"`),a&&`<span class="${a}"${f}>${i}</span>`||""})},$=()=>k.default&&x(k.default())||"",B=t=>{t.target.insertAdjacentHTML("afterend",`<textarea id="clipboard-textarea">${d.value.innerText}</textarea>`);const e=document.getElementById("clipboard-textarea");e.select(),e.setSelectionRange(0,99999),document.execCommand("copy"),e.remove(),O("copied",d.value.innerText)};return l.onMounted(()=>{const t=$();d.value.innerText=t,d.value.innerHTML=w(d.value.innerText)}),l.onBeforeUpdate(()=>{d.value&&(d.value.innerHTML=w($()))}),(t,e)=>(l.openBlock(),l.createElementBlock("div",{class:l.normalizeClass(["ssh-pre",{"ssh-pre--dark":g.dark}]),"data-type":g.language,"data-label":g.label||null},[g.copyButton?(l.openBlock(),l.createElementBlock("button",{key:0,class:"ssh-pre__copy",onClick:B},[l.renderSlot(t.$slots,"copy-button",{},()=>[l.createTextVNode("Copy")])])):l.createCommentVNode("",!0),l.createTextVNode(),l.createElementVNode("pre",{ref_key:"codeEl",ref:d,class:"ssh-pre__content",contenteditable:g.editable?"true":"false",onKeydown:e[0]||(e[0]=s=>g.editable&&U(s)),onInput:M}," ",40,R),l.createTextVNode(),l.createElementVNode("div",A,[l.renderSlot(t.$slots,"default")])],10,b))}}}); |
{ | ||
"name": "simple-syntax-highlighter", | ||
"version": "3.0.8", | ||
"version": "3.0.10", | ||
"description": "No chi-chi syntax highlighter for Vue.js 3 (and 2).", | ||
@@ -34,9 +34,2 @@ "author": "Antoni Andre <antoniandre.web@gmail.com>", | ||
], | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build --base /simple-syntax-highlighter/", | ||
"build-bundle": "BUNDLE=true vite build && mv ./dist/style.css ./dist/sshpre.css", | ||
"serve": "vite preview --base /simple-syntax-highlighter/", | ||
"publish-doc": "npm run build && npm run build-bundle && git add . && git commit -m 'Publish documentation on Github.' && git push && git push --tag" | ||
}, | ||
"devDependencies": { | ||
@@ -65,3 +58,10 @@ "@eslint/js": "^9.9.0", | ||
"vue": "^3.2.0" | ||
}, | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build --base /simple-syntax-highlighter/", | ||
"build-bundle": "BUNDLE=true vite build && mv ./dist/style.css ./dist/sshpre.css", | ||
"serve": "vite preview --base /simple-syntax-highlighter/", | ||
"publish-doc": "npm run build && npm run build-bundle && git add . && git commit -m 'Publish documentation on Github.' && git push && git push --tag" | ||
} | ||
} | ||
} |
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
54858
453