v1.0.0.1
StocketBase
- (function () {
- 'use strict';
-
- var STRING = /"(?:\\.|[^"\\\n])*"|'(?:\\.|[^'\\\n])*'/.source;
- var NUMBER = /\b0x[\da-f]+\b|\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/.source;
- var FUNCTION = /[A-Za-z_$][\w$]*(?=\s*\()/.source;
-
- function words(list) {
- return '\\b(?:' + list.join('|') + ')\\b';
- }
-
- var JS_KEYWORDS = ['async', 'await', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do', 'else', 'export', 'extends', 'finally', 'for', 'from', 'function', 'if', 'import', 'in', 'instanceof', 'let', 'new', 'of', 'return', 'static', 'super', 'switch', 'throw', 'try', 'typeof', 'var', 'void', 'while', 'with', 'yield', 'interface', 'type', 'enum', 'implements', 'public', 'private', 'protected', 'readonly'];
- var PHP_KEYWORDS = ['abstract', 'and', 'array', 'as', 'break', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'extends', 'final', 'finally', 'fn', 'for', 'foreach', 'function', 'global', 'if', 'implements', 'include', 'include_once', 'instanceof', 'interface', 'isset', 'list', 'match', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'readonly', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor', 'yield'];
- var PY_KEYWORDS = ['and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'];
- var SQL_KEYWORDS = ['select', 'from', 'where', 'and', 'or', 'not', 'in', 'is', 'null', 'insert', 'into', 'values', 'update', 'set', 'delete', 'create', 'table', 'alter', 'drop', 'add', 'column', 'index', 'primary', 'key', 'foreign', 'references', 'join', 'left', 'right', 'inner', 'outer', 'on', 'as', 'group', 'by', 'order', 'having', 'limit', 'offset', 'distinct', 'union', 'all', 'exists', 'between', 'like', 'case', 'when', 'then', 'else', 'end', 'default', 'unique', 'if', 'engine', 'auto_increment', 'asc', 'desc', 'count', 'sum', 'avg', 'min', 'max'];
- var BASH_KEYWORDS = ['if', 'then', 'else', 'elif', 'fi', 'for', 'while', 'do', 'done', 'case', 'esac', 'function', 'in', 'return', 'exit', 'export', 'local', 'echo', 'cd', 'sudo', 'source'];
- var CLIKE_KEYWORDS = ['abstract', 'as', 'break', 'case', 'catch', 'char', 'class', 'const', 'continue', 'default', 'do', 'double', 'else', 'enum', 'extends', 'final', 'finally', 'float', 'for', 'fn', 'func', 'go', 'if', 'impl', 'import', 'in', 'int', 'interface', 'let', 'long', 'match', 'mut', 'namespace', 'new', 'package', 'private', 'protected', 'public', 'return', 'short', 'static', 'struct', 'super', 'switch', 'this', 'throw', 'throws', 'try', 'typedef', 'unsigned', 'use', 'using', 'var', 'virtual', 'void', 'volatile', 'while'];
- var LITERALS = ['true', 'false', 'null', 'undefined', 'NaN', 'Infinity', 'this', 'None', 'True', 'False', 'self', 'nil', 'TRUE', 'FALSE', 'NULL'];
-
- var LANGUAGES = {
- javascript: {
- rules: [
- ['comment', /\/\/[^\n]*|\/\*[\s\S]*?\*\//.source],
- ['string', /`(?:\\[\s\S]|[^`\\])*`/.source + '|' + STRING],
- ['keyword', words(JS_KEYWORDS)],
- ['literal', words(LITERALS)],
- ['function', FUNCTION],
- ['number', NUMBER]
- ]
- },
- css: {
- rules: [
- ['comment', /\/\*[\s\S]*?\*\//.source],
- ['string', STRING],
- ['keyword', /@[\w-]+/.source],
- ['attr', /[\w-]+(?=\s*:[^;{}]*[;}])/.source],
- ['tag', /[.#][A-Za-z_][\w-]*(?=[^;{}]*\{)/.source],
- ['number', /#[\da-f]{3,8}\b|-?\d*\.?\d+(?:px|em|rem|%|vh|vw|s|ms|deg|fr)?/.source],
- ['function', /[\w-]+(?=\()/.source]
- ]
- },
- php: {
- rules: [
- ['comment', /\/\/[^\n]*|#[^\n]*|\/\*[\s\S]*?\*\//.source],
- ['string', STRING],
- ['keyword', /<\?php|<\?=|\?>/.source + '|' + words(PHP_KEYWORDS)],
- ['variable', /\$[A-Za-z_]\w*/.source],
- ['literal', words(LITERALS)],
- ['function', FUNCTION],
- ['number', NUMBER]
- ]
- },
- python: {
- rules: [
- ['comment', /#[^\n]*/.source],
- ['string', /'''[\s\S]*?'''|"""[\s\S]*?"""/.source + '|' + STRING],
- ['keyword', words(PY_KEYWORDS)],
- ['literal', words(LITERALS)],
- ['tag', /@\w+/.source],
- ['function', FUNCTION],
- ['number', NUMBER]
- ]
- },
- sql: {
- flags: 'gi',
- rules: [
- ['comment', /--[^\n]*|\/\*[\s\S]*?\*\//.source],
- ['string', /'(?:''|[^'])*'/.source],
- ['keyword', words(SQL_KEYWORDS)],
- ['function', /[A-Za-z_]\w*(?=\s*\()/.source],
- ['number', NUMBER]
- ]
- },
- bash: {
- rules: [
- ['comment', /#[^\n]*/.source],
- ['string', STRING],
- ['variable', /\$(?:\w+|\{[^}]*\})/.source],
- ['keyword', words(BASH_KEYWORDS)],
- ['attr', /(?:^|\s)--?[A-Za-z][\w-]*/.source],
- ['number', NUMBER]
- ]
- },
- json: {
- rules: [
- ['attr', /"(?:\\.|[^"\\\n])*"(?=\s*:)/.source],
- ['string', STRING],
- ['literal', words(['true', 'false', 'null'])],
- ['number', /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/.source]
- ]
- },
- clike: {
- rules: [
- ['comment', /\/\/[^\n]*|\/\*[\s\S]*?\*\//.source],
- ['string', STRING],
- ['keyword', words(CLIKE_KEYWORDS)],
- ['literal', words(LITERALS)],
- ['function', FUNCTION],
- ['number', NUMBER]
- ]
- }
- };
-
- var ALIASES = {
- js: 'javascript', jsx: 'javascript', ts: 'javascript', tsx: 'javascript', typescript: 'javascript', node: 'javascript',
- scss: 'css', less: 'css',
- py: 'python',
- mysql: 'sql', sqlite: 'sql', postgresql: 'sql',
- sh: 'bash', shell: 'bash', zsh: 'bash',
- java: 'clike', c: 'clike', cpp: 'clike', csharp: 'clike', cs: 'clike', go: 'clike', rust: 'clike', kotlin: 'clike', swift: 'clike',
- html: 'markup', xml: 'markup', svg: 'markup', htm: 'markup'
- };
-
- var compiled = {};
-
- function escapeHtml(text) {
- return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
- }
-
- function span(className, text) {
- return '<span class="tok-' + className + '">' + escapeHtml(text) + '</span>';
- }
-
- function scan(source, pattern, handler) {
- var output = '';
- var last = 0;
- var match;
-
- pattern.lastIndex = 0;
- while ((match = pattern.exec(source)) !== null) {
- if (match[0] === '') {
- pattern.lastIndex++;
- continue;
- }
- output += escapeHtml(source.slice(last, match.index)) + handler(match);
- last = pattern.lastIndex;
- }
-
- return output + escapeHtml(source.slice(last));
- }
-
- function compile(name) {
- if (compiled[name]) {
- return compiled[name];
- }
-
- var spec = LANGUAGES[name];
- var source = spec.rules.map(function (rule) {
- return '(' + rule[1] + ')';
- }).join('|');
-
- compiled[name] = { pattern: new RegExp(source, spec.flags || 'g'), rules: spec.rules };
-
- return compiled[name];
- }
-
- function highlightTag(tag) {
- var parts = tag.match(/^<(\/?)([^\s>\/]+)([\s\S]*?)(\/?)>$/);
- if (!parts) {
- return escapeHtml(tag);
- }
-
- var attributes = scan(parts[3], /([^\s=\/>]+)(?:(\s*=\s*)("[^"]*"|'[^']*'|[^\s"'>]+))?/g, function (match) {
- return span('attr', match[1]) + (match[2] ? escapeHtml(match[2]) + span('string', match[3]) : '');
- });
-
- return escapeHtml('<' + parts[1]) + span('tag', parts[2]) + attributes + escapeHtml(parts[4] + '>');
- }
-
- function highlightMarkup(source) {
- var pattern = /<!--[\s\S]*?-->|<!doctype[^>]*>|<(script|style)\b[^>]*>[\s\S]*?<\/\1\s*>|<\/?[A-Za-z][^>]*>/gi;
-
- return scan(source, pattern, function (match) {
- var text = match[0];
-
- if (text.indexOf('<!--') === 0) {
- return span('comment', text);
- }
- if (text.charAt(1) === '!') {
- return span('keyword', text);
- }
- if (match[1]) {
- var open = text.match(/^<[^>]*>/)[0];
- var close = text.match(/<\/[^>]*>$/)[0];
- var body = text.slice(open.length, text.length - close.length);
-
- return highlightTag(open) + highlight(body, match[1].toLowerCase() === 'style' ? 'css' : 'javascript') + highlightTag(close);
- }
-
- return highlightTag(text);
- });
- }
-
- function highlight(source, language) {
- var name = ALIASES[language] || language;
-
- if (name === 'markup') {
- return highlightMarkup(source);
- }
- if (!LANGUAGES[name]) {
- return escapeHtml(source);
- }
-
- var compiledLanguage = compile(name);
-
- return scan(source, compiledLanguage.pattern, function (match) {
- for (var index = 0; index < compiledLanguage.rules.length; index++) {
- if (match[index + 1] !== undefined) {
- return span(compiledLanguage.rules[index][0], match[0]);
- }
- }
-
- return escapeHtml(match[0]);
- });
- }
-
- function languageOf(code) {
- var match = /(?:^|\s)language-([\w+#-]+)/.exec(code.className);
-
- return match ? match[1].toLowerCase() : '';
- }
-
- function initHighlight() {
- document.querySelectorAll('pre > code[class*="language-"]').forEach(function (code) {
- var language = languageOf(code);
- var name = ALIASES[language] || language;
-
- if (name !== 'markup' && !LANGUAGES[name]) {
- return;
- }
- if (code.textContent.length > 60000) {
- return;
- }
-
- code.innerHTML = highlight(code.textContent, language);
- code.classList.add('is-highlighted');
- });
- }
-
- function copyText(text) {
- if (navigator.clipboard && window.isSecureContext) {
- return navigator.clipboard.writeText(text);
- }
-
- return new Promise(function (resolve, reject) {
- var field = document.createElement('textarea');
- field.value = text;
- field.setAttribute('readonly', '');
- field.style.position = 'fixed';
- field.style.opacity = '0';
- document.body.appendChild(field);
- field.select();
-
- try {
- document.execCommand('copy') ? resolve() : reject();
- } catch (error) {
- reject(error);
- }
-
- document.body.removeChild(field);
- });
- }
-
- function initCopy() {
- document.querySelectorAll('.code-block .code-copy').forEach(function (button) {
- button.addEventListener('click', function () {
- var code = button.parentNode.querySelector('code');
- if (!code) {
- return;
- }
-
- copyText(code.textContent).then(function () {
- button.textContent = button.getAttribute('data-copied');
- button.classList.add('is-copied');
-
- setTimeout(function () {
- button.textContent = button.getAttribute('data-label');
- button.classList.remove('is-copied');
- }, 1800);
- });
- });
- });
- }
-
- function init() {
- initHighlight();
- initCopy();
- }
-
- if (document.readyState === 'loading') {
- document.addEventListener('DOMContentLoaded', init);
- } else {
- init();
- }
- })();
-