From d2f1d2d75b975345c45624fc3bd3307047e7bd87 Mon Sep 17 00:00:00 2001 From: Miao Wang Date: Mon, 15 Apr 2024 12:40:09 +0800 Subject: [PATCH] using vite to bundle njs scripts --- _src/entrypoints-njs/all.js | 2 + _src/entrypoints-njs/fancy_index.js | 34 ++++++ _src/entrypoints-njs/legacy_index.js | 74 +++++++++++++ _vite.config.mjs | 82 ++++++++++++++ package-lock.json | 154 +++++++++++++++++++++++++++ package.json | 3 + static/njs/all.njs | 4 - static/njs/fancy_index.njs | 32 ------ static/njs/legacy_index.njs | 101 ------------------ static/njs/markup.min.njs | 7 -- 10 files changed, 349 insertions(+), 144 deletions(-) create mode 100644 _src/entrypoints-njs/all.js create mode 100644 _src/entrypoints-njs/fancy_index.js create mode 100644 _src/entrypoints-njs/legacy_index.js delete mode 100644 static/njs/all.njs delete mode 100644 static/njs/fancy_index.njs delete mode 100644 static/njs/legacy_index.njs delete mode 100644 static/njs/markup.min.njs diff --git a/_src/entrypoints-njs/all.js b/_src/entrypoints-njs/all.js new file mode 100644 index 0000000..b6492b4 --- /dev/null +++ b/_src/entrypoints-njs/all.js @@ -0,0 +1,2 @@ +export { legacyIndexRender } from "./legacy_index"; +export { fancyIndexBeforeRender, fancyIndexAfterRender } from "./fancy_index"; diff --git a/_src/entrypoints-njs/fancy_index.js b/_src/entrypoints-njs/fancy_index.js new file mode 100644 index 0000000..e6c6025 --- /dev/null +++ b/_src/entrypoints-njs/fancy_index.js @@ -0,0 +1,34 @@ +import Mark from "markup-js"; + +function fancyIndexRender(r, templateUrl) { + r.subrequest( + templateUrl, + { + args: "", + body: "", + method: "GET", + }, + function (rTmpl) { + if (rTmpl.status != 200) { + return r.return(rTmpl.status); + } + const tmpl = rTmpl.responseText; + const result = Mark.up(tmpl, { + url: r.variables.request_uri.replace(/\/+/g, "/").replace(/\?.*$/, ""), + }); + r.status = 200; + r.headersOut["Content-Type"] = "text/html"; + r.sendHeader(); + r.send(result); + r.finish(); + }, + ); +} + +export function fancyIndexBeforeRender(r) { + return fancyIndexRender(r, "/fancy-index/before.html"); +} + +export function fancyIndexAfterRender(r) { + return fancyIndexRender(r, "/fancy-index/after.html"); +} diff --git a/_src/entrypoints-njs/legacy_index.js b/_src/entrypoints-njs/legacy_index.js new file mode 100644 index 0000000..155debb --- /dev/null +++ b/_src/entrypoints-njs/legacy_index.js @@ -0,0 +1,74 @@ +import Mark from "markup-js"; +import processingHandlers from "../lib/mirrorListDataProcessing"; +import { TUNASYNC_JSON_PATH } from "../lib/consts"; + +export function legacyIndexRender(r) { + r.subrequest( + "/legacy_index.html", + { + args: "", + body: "", + method: "GET", + }, + function (rTmpl) { + if (rTmpl.status != 200) { + return r.return(rTmpl.status); + } + var tmpl = rTmpl.responseText; + + r.subrequest( + "/static/njs/options.json", + { + args: "", + body: "", + method: "GET", + }, + function (rOpt) { + if (rOpt.status != 200) { + return r.return(rOpt.status); + } + let global_options; + try { + global_options = JSON.parse(rOpt.responseText); + } catch (e) { + return r.return(500); + } + const { + unlistedMirrors: unlisted, + genMainMirrorList, + postProcessStatusData, + } = processingHandlers(global_options.options); + const help_url = Object.fromEntries( + global_options.helps.map((h) => [h.mirrorid, h.url]), + ); + r.subrequest( + TUNASYNC_JSON_PATH, + { + args: "", + body: "", + method: "GET", + }, + function (rMirs) { + let mirs = []; + if (rMirs.status == 200) { + try { + mirs = JSON.parse(rMirs.responseText); + } catch (e) {} + } + const renMirs = genMainMirrorList( + postProcessStatusData(mirs, unlisted), + help_url, + ); + var result = Mark.up(tmpl, { mirs: renMirs }); + r.status = 200; + r.headersOut["Content-Type"] = "text/html"; + r.sendHeader(); + r.send(result); + r.finish(); + }, + ); + }, + ); + }, + ); +} diff --git a/_vite.config.mjs b/_vite.config.mjs index 0a0050c..56cb503 100644 --- a/_vite.config.mjs +++ b/_vite.config.mjs @@ -9,6 +9,9 @@ import { Liquid, Tag as LiquidTag } from "liquidjs"; import Babel from "@babel/core"; import BabelPresetEnv from "@babel/preset-env"; import fs from "node:fs"; +import { build as viteBuild, normalizePath } from "vite"; +import glob from "fast-glob"; +import { getBabelOutputPlugin } from "@rollup/plugin-babel"; const visualizer = await (async () => { if (process.env.VISUALIZER) { @@ -138,6 +141,85 @@ export default defineConfig(({ mode }) => ({ dirs: [resolve(__dirname, "_src/components")], resolvers: [], }), + (() => { + const savedConfig = { + njsOutputDir: "static/njs", + }; + return { + name: "add-njs", + config(config) { + savedConfig.minify = config.build?.minify; + savedConfig.root = config.root; + savedConfig.mode = config.mode; + savedConfig.njsFiles = glob.sync("entrypoints-njs/**", { + cwd: config.root, + }); + savedConfig.sourcemap = config.build?.sourcemap; + savedConfig.logLevel = config.logLevel; + }, + async generateBundle(opts, bundle) { + const { minify, root, mode, njsOutputDir, njsFiles, logLevel } = + savedConfig; + if (opts.format === "system") { + const entryChunk = Object.values(bundle).find( + (output) => output.type === "chunk" && output.isEntry, + ); + if (!!entryChunk && entryChunk.fileName.includes("-legacy")) { + return; + } + } + if (njsFiles.length == 0) { + return; + } + const res = await viteBuild({ + mode, + root, + configFile: false, + logLevel, + plugins: [ + getBabelOutputPlugin({ + presets: [ + "babel-preset-njs", + ], + plugins: [ + ], + configFile: false, + }), + ], + build: { + write: false, + minify, + assetsDir: njsOutputDir, + sourcemap: savedConfig.sourcemap, + rollupOptions: { + input: Object.fromEntries( + njsFiles.map((filename) => [ + filename, + path.join(root, filename), + ]), + ), + output: { + format: "esm", + entryFileNames: ({ name }) => { + const shortName = path.basename(name).split(".")[0]; + return path.join(njsOutputDir, `${shortName}.njs`); + }, + chunkFileNames: `${njsOutputDir}/[name].njs`, + }, + preserveEntrySignatures: "strict", + }, + }, + esbuild: false, + }); + const outputs = Array.isArray(res) ? res : [res]; + outputs.forEach((output) => { + output.output.forEach((chunk) => { + bundle[chunk.fileName] = chunk; + }); + }); + }, + }; + })(), legacy({ //use empty array to target the oldest browsers possible targets: [], diff --git a/package-lock.json b/package-lock.json index 022a58e..65415d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,14 +9,17 @@ "dependencies": { "@babel/core": "^7.24.4", "@babel/preset-env": "^7.24.4", + "@rollup/plugin-babel": "^6.0.4", "@vitejs/plugin-legacy": "^5.3.2", "@vitejs/plugin-vue": "^5.0.4", "@webcomponents/template": "^1.5.1", + "babel-preset-njs": "^0.7.0", "bootstrap": "^5.3.3", "bootstrap-sass": "^3.4.3", "core-js": "^3.36.1", "element-polyfill": "^1.1.0", "events-polyfill": "^2.1.2", + "fast-glob": "^3.3.2", "formdata-polyfill": "^4.0.10", "highlight.js": "^11.9.0", "lato-webfont": "^2.15.1", @@ -504,6 +507,90 @@ "@babel/core": "^7.0.0" } }, + "node_modules/@babel/plugin-proposal-export-namespace-from": { + "version": "7.18.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-export-namespace-from/-/plugin-proposal-export-namespace-from-7.18.9.tgz", + "integrity": "sha512-k1NtHyOMvlDDFeb9G5PhUXuGj8m/wiwojgQVEhJ/fsVsMCpLyOP4h0uGEjYJKrRI+EVPlb5Jk+Gt9P97lOGwtA==", + "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-export-namespace-from instead.", + "dependencies": { + "@babel/helper-plugin-utils": "^7.18.9", + "@babel/plugin-syntax-export-namespace-from": "^7.8.3" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-proposal-logical-assignment-operators": { + "version": "7.20.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-logical-assignment-operators/-/plugin-proposal-logical-assignment-operators-7.20.7.tgz", + "integrity": "sha512-y7C7cZgpMIjWlKE5T7eJwp+tnRYM89HmRvWM5EQuB5BoHEONjmQ8lSNmBUwOyy/GFRsohJED51YBF79hE1djug==", + "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-logical-assignment-operators instead.", + "dependencies": { + "@babel/helper-plugin-utils": "^7.20.2", + "@babel/plugin-syntax-logical-assignment-operators": "^7.10.4" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-proposal-object-rest-spread": { + "version": "7.20.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.20.7.tgz", + "integrity": "sha512-d2S98yCiLxDVmBmE8UjGcfPvNEUbA1U5q5WxaWFUGRzJSVAZqm5W6MbPct0jxnegUZ0niLeNX+IOzEs7wYg9Dg==", + "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.", + "dependencies": { + "@babel/compat-data": "^7.20.5", + "@babel/helper-compilation-targets": "^7.20.7", + "@babel/helper-plugin-utils": "^7.20.2", + "@babel/plugin-syntax-object-rest-spread": "^7.8.3", + "@babel/plugin-transform-parameters": "^7.20.7" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-proposal-optional-catch-binding": { + "version": "7.18.6", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-optional-catch-binding/-/plugin-proposal-optional-catch-binding-7.18.6.tgz", + "integrity": "sha512-Q40HEhs9DJQyaZfUjjn6vE8Cv4GmMHCYuMGIWUnlxH6400VGxOuwWsPt4FxXxJkC/5eOzgn0z21M9gMT4MOhbw==", + "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-catch-binding instead.", + "dependencies": { + "@babel/helper-plugin-utils": "^7.18.6", + "@babel/plugin-syntax-optional-catch-binding": "^7.8.3" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-proposal-optional-chaining": { + "version": "7.21.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.21.0.tgz", + "integrity": "sha512-p4zeefM72gpmEe2fkUr/OnOXpWEf8nAgk7ZYVqqfFiyIG7oFfVZcCrU64hWn5xp4tQ9LkV4bTIa5rD0KANpKNA==", + "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.", + "dependencies": { + "@babel/helper-plugin-utils": "^7.20.2", + "@babel/helper-skip-transparent-expression-wrappers": "^7.20.0", + "@babel/plugin-syntax-optional-chaining": "^7.8.3" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/plugin-proposal-private-property-in-object": { "version": "7.21.0-placeholder-for-preset-env.2", "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz", @@ -515,6 +602,22 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/plugin-proposal-unicode-property-regex": { + "version": "7.18.6", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-unicode-property-regex/-/plugin-proposal-unicode-property-regex-7.18.6.tgz", + "integrity": "sha512-2BShG/d5yoZyXZfVePH91urL5wTG6ASZU9M4o03lKK8u8UW1y08OMttBSOADTcJrnPMpvDXRG3G8fyLh4ovs8w==", + "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-unicode-property-regex instead.", + "dependencies": { + "@babel/helper-create-regexp-features-plugin": "^7.18.6", + "@babel/helper-plugin-utils": "^7.18.6" + }, + "engines": { + "node": ">=4" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/plugin-syntax-async-generators": { "version": "7.8.4", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-async-generators/-/plugin-syntax-async-generators-7.8.4.tgz", @@ -2063,6 +2166,31 @@ "url": "https://opencollective.com/popperjs" } }, + "node_modules/@rollup/plugin-babel": { + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/@rollup/plugin-babel/-/plugin-babel-6.0.4.tgz", + "integrity": "sha512-YF7Y52kFdFT/xVSuVdjkV5ZdX/3YtmX0QulG+x0taQOtJdHYzVU61aSSkAgVJ7NOv6qPkIYiJSgSWWN/DM5sGw==", + "dependencies": { + "@babel/helper-module-imports": "^7.18.6", + "@rollup/pluginutils": "^5.0.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0", + "@types/babel__core": "^7.1.9", + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "@types/babel__core": { + "optional": true + }, + "rollup": { + "optional": true + } + } + }, "node_modules/@rollup/pluginutils": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.0.tgz", @@ -2502,6 +2630,32 @@ "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" } }, + "node_modules/babel-preset-njs": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/babel-preset-njs/-/babel-preset-njs-0.7.0.tgz", + "integrity": "sha512-nY1iK+YdlGppIZwY5YSv+GLiik+/kgRyNKgY+9/7c+RgOLN/WgeWMabwCjVFVvqBsannRCWx7qCvXrBlAWfMGg==", + "dependencies": { + "@babel/helper-plugin-utils": "^7.21.5", + "@babel/plugin-proposal-export-namespace-from": "^7.18.9", + "@babel/plugin-proposal-logical-assignment-operators": "^7.20.7", + "@babel/plugin-proposal-object-rest-spread": "^7.20.7", + "@babel/plugin-proposal-optional-catch-binding": "^7.18.6", + "@babel/plugin-proposal-optional-chaining": "^7.21.0", + "@babel/plugin-proposal-unicode-property-regex": "^7.18.6", + "@babel/plugin-transform-classes": "^7.21.0", + "@babel/plugin-transform-destructuring": "^7.21.3", + "@babel/plugin-transform-dotall-regex": "^7.18.6", + "@babel/plugin-transform-for-of": "^7.21.5", + "@babel/plugin-transform-new-target": "^7.18.6", + "@babel/plugin-transform-object-super": "^7.18.6", + "@babel/plugin-transform-parameters": "^7.21.3", + "@babel/plugin-transform-spread": "^7.20.7", + "@babel/plugin-transform-unicode-regex": "^7.18.6" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", diff --git a/package.json b/package.json index 6c8fe92..7b515dd 100644 --- a/package.json +++ b/package.json @@ -9,14 +9,17 @@ "dependencies": { "@babel/core": "^7.24.4", "@babel/preset-env": "^7.24.4", + "@rollup/plugin-babel": "^6.0.4", "@vitejs/plugin-legacy": "^5.3.2", "@vitejs/plugin-vue": "^5.0.4", "@webcomponents/template": "^1.5.1", + "babel-preset-njs": "^0.7.0", "bootstrap": "^5.3.3", "bootstrap-sass": "^3.4.3", "core-js": "^3.36.1", "element-polyfill": "^1.1.0", "events-polyfill": "^2.1.2", + "fast-glob": "^3.3.2", "formdata-polyfill": "^4.0.10", "highlight.js": "^11.9.0", "lato-webfont": "^2.15.1", diff --git a/static/njs/all.njs b/static/njs/all.njs deleted file mode 100644 index dc1b336..0000000 --- a/static/njs/all.njs +++ /dev/null @@ -1,4 +0,0 @@ -import legacyIndexRender from 'legacy_index.njs'; -import _renders from 'fancy_index.njs'; -var fancyIndexBeforeRender = _renders.fancyIndexBeforeRender; -var fancyIndexAfterRender = _renders.fancyIndexAfterRender; diff --git a/static/njs/fancy_index.njs b/static/njs/fancy_index.njs deleted file mode 100644 index 1966301..0000000 --- a/static/njs/fancy_index.njs +++ /dev/null @@ -1,32 +0,0 @@ -import Mark from 'markup.min.njs'; - -function fancyIndexRender(r, templateUrl){ - r.subrequest(templateUrl, { - args: '', - body: '', - method: 'GET' - }, function(rTmpl){ - if(rTmpl.status != 200){ - return r.return(rTmpl.status); - } - var tmpl = rTmpl.responseText; - var result = Mark.up(tmpl, { - url: r.variables.request_uri.replace(/\/+/g, '/').replace(/\?.*$/, ''), - }); - r.status = 200; - r.headersOut['Content-Type'] = 'text/html'; - r.sendHeader(); - r.send(result); - r.finish(); - }); -} - -function fancyIndexBeforeRender(r){ - return fancyIndexRender(r, '/fancy-index/before.html'); -} - -function fancyIndexAfterRender(r){ - return fancyIndexRender(r, '/fancy-index/after.html'); -} - -export default {fancyIndexBeforeRender, fancyIndexAfterRender}; diff --git a/static/njs/legacy_index.njs b/static/njs/legacy_index.njs deleted file mode 100644 index 396ced3..0000000 --- a/static/njs/legacy_index.njs +++ /dev/null @@ -1,101 +0,0 @@ -import Mark from 'markup.min.njs'; - -function legacyIndexRender(r){ - function getMirDate(d){ - var result; - if (d.last_update_ts) { - var date = new Date(d.last_update_ts * 1000); - if (date.getFullYear() > 2000) { - result = `${('000'+date.getFullYear()).substr(-4)}-${('0'+(date.getMonth()+1)).substr(-2)}-${('0'+date.getDate()).substr(-2)}` + - ` ${('0'+date.getHours()).substr(-2)}:${('0'+date.getMinutes()).substr(-2)}`; - } else { - result = "0000-00-00 00:00"; - } - } else { - result = d.last_update.replace(/(\d\d:\d\d):\d\d(\s\+\d\d\d\d)?/, '$1'); - } - return result; - } - r.subrequest('/legacy_index.html', { - args: '', - body: '', - method: 'GET' - }, function(rTmpl){ - if(rTmpl.status != 200){ - return r.return(rTmpl.status); - } - var tmpl = rTmpl.responseText; - - r.subrequest('/static/njs/options.json', { - args: '', - body: '', - method: 'GET' - }, function(rOpt){ - if(rOpt.status != 200){ - return r.return(rOpt.status); - } - var global_options; - try{ - global_options = JSON.parse(rOpt.responseText); - }catch(e){ - return r.return(500); - } - var label_map = global_options.options.label_map; - var help_url = {}; - global_options.helps.forEach((h) => help_url[h.mirrorid] = h.url); - var new_mirrors = {}; - global_options.options.new_mirrors.forEach((m) => new_mirrors[m] = true); - var unlisted = global_options.options.unlisted_mirrors; - var force_help = {} - global_options.options.force_redirect_help_mirrors.forEach((m) => force_help[m] = true); - var descriptions = {}; - global_options.options.mirror_desc.forEach((m) => descriptions[m.name] = m.desc); - r.subrequest('/static/tunasync.json', { - args: '', - body: '', - method: 'GET' - }, function(rMirs){ - var mirs = unlisted; - if(rMirs.status == 200){ - try{ - mirs = mirs.concat(JSON.parse(rMirs.responseText)); - }catch(e){ - } - } - var renMirs = mirs.filter(m => m.status != "disabled" && m.is_master !== false).map(m => { - var status = m.status; - var target = m; - if(m.link_to){ - var _target = mirs.filter(_m => _m.name == m.link_to)[0]; - if(_target){ - target = _target; - status = target.status; - } - } - return { - status: status, - name: m.name, - description: descriptions[m.name], - url: force_help[m.name] ? help_url[m.name] : m.url ? m.url : '/' + m.name + '/', - is_new: !!new_mirrors[m.name], - github_release: m.url && m.url.startsWith('/github-release/'), - help_url: help_url[m.name], - last_update: getMirDate(target), - label: label_map[status], - show_status: status != 'success' - }; - }); - renMirs.sort((a, b) => a.name < b.name ? -1: 1 ); - var result = Mark.up(tmpl, {mirs: renMirs}); - r.status = 200; - r.headersOut['Content-Type'] = 'text/html'; - r.sendHeader(); - r.send(result); - r.finish(); - }) - }) - }); - -} - -export default legacyIndexRender; diff --git a/static/njs/markup.min.njs b/static/njs/markup.min.njs deleted file mode 100644 index dd22ffd..0000000 --- a/static/njs/markup.min.njs +++ /dev/null @@ -1,7 +0,0 @@ -/* - Markup.js v1.5.21: http://github.com/adammark/Markup.js - MIT License - (c) 2011 - 2014 Adam Mark -*/ -var Mark={includes:{},globals:{},delimiter:">",compact:false,_copy:function(d,c){c=c||[];for(var e in d){c[e]=d[e]}return c},_size:function(b){return b instanceof Array?b.length:(b||0)},_iter:function(a,b){this.idx=a;this.size=b;this.length=b;this.sign="#";this.toString=function(){return this.idx+this.sign.length-1}},_pipe:function(h,c){var g,f,b,a;if((g=c.shift())){f=g.split(this.delimiter);b=f.shift().trim();try{a=Mark.pipes[b].apply(null,[h].concat(f));h=this._pipe(a,c)}catch(d){}}return h},_eval:function(e,g,h){var a=this._pipe(e,g),b=a,d=-1,c,f;if(a instanceof Array){a="";c=b.length;while(++d-1){l++}else{m++}if(m===l){break}}m=h.indexOf(p[0]);l=m+p[0].length;j=k+p[o].length;return[h.substring(m,j),h.substring(l,k)]}};Mark.up=function(s,b,e){b=b||{};e=e||{};var m=/\{\{(.+?)\}\}/g,l=s.match(m)||[],t,d,g,h=[],r,c,f,k,o,a,n,q=0,p=0;if(e.pipes){this._copy(e.pipes,this.pipes)}if(e.includes){this._copy(e.includes,this.includes)}if(e.globals){this._copy(e.globals,this.globals)}if(e.delimiter){this.delimiter=e.delimiter}if(e.compact!==undefined){this.compact=e.compact}while((t=l[q++])){k=undefined;f="";r=t.indexOf("/}}")>-1;d=t.substr(2,t.length-(r?5:4));d=d.replace(/`(.+?)`/g,function(i,j){return Mark.up("{{"+j+"}}",b)});c=d.trim().indexOf("if ")===0;h=d.split("|");h.shift();d=d.replace(/^\s*if/,"").split("|").shift().trim();g=c?"if":d.split("|")[0];n=b[d];if(c&&!h.length){h=["notempty"]}if(!r&&s.indexOf("{{/"+g)>-1){k=this._bridge(s,g);t=k[0];f=k[1];q+=t.match(m).length-1}if(/^\{\{\s*else\s*\}\}$/.test(t)){continue}else{if((o=this.globals[d])!==undefined){k=this._eval(o,h,f)}else{if((a=this.includes[d])){if(a instanceof Function){a=a()}k=this._pipe(Mark.up(a,b,e),h)}else{if(d.indexOf("#")>-1){e.iter.sign=d;k=this._pipe(e.iter,h)}else{if(d==="."){k=this._pipe(b,h)}else{if(d.indexOf(".")>-1){d=d.split(".");n=Mark.globals[d[0]];if(n){p=1}else{p=0;n=b}while(n&&p\s+<"):s};Mark.pipes={empty:function(a){return !a||(a+"").trim().length===0?a:false},notempty:function(a){return a&&(a+"").trim().length?a:false},blank:function(b,a){return !!b||b===0?b:a},more:function(d,c){return Mark._size(d)>c?d:false},less:function(d,c){return Mark._size(d)=c?d:false},orless:function(d,c){return Mark._size(d)<=c?d:false},between:function(e,d,f){e=Mark._size(e);return e>=d&&e<=f?e:false},equals:function(d,c){return d==c?d:false},notequals:function(d,c){return d!=c?d:false},like:function(b,a){return new RegExp(a,"i").test(b)?b:false},notlike:function(b,a){return !Mark.pipes.like(b,a)?b:false},upcase:function(a){return String(a).toUpperCase()},downcase:function(a){return String(a).toLowerCase()},capcase:function(a){return a.replace(/(?:^|\s)\S/g,function(b){return b.toUpperCase()})},chop:function(a,b){return a.length>b?a.substr(0,b)+"...":a},tease:function(c,d){var b=c.split(/\s+/);return b.slice(0,d).join(" ")+(b.length>d?"...":"")},trim:function(a){return a.trim()},pack:function(a){return a.trim().replace(/\s{2,}/g," ")},round:function(a){return Math.round(+a)},clean:function(a){return String(a).replace(/<\/?[^>]+>/gi,"")},size:function(a){return a.length},length:function(a){return a.length},reverse:function(a){return[].concat(a).reverse()},join:function(a,b){return a.join(b)},limit:function(b,c,a){return b.slice(+a||0,+c+(+a||0))},split:function(b,a){return b.split(a||",")},choose:function(b,c,a){return !!b?c:(a||"")},toggle:function(c,b,a,d){return a.split(",")[b.match(/\w+/g).indexOf(c+"")]||d},sort:function(a,c){var b=function(e,d){return e[c]>d[c]?1:-1};return[].concat(a).sort(c?b:undefined)},fix:function(a,b){return(+a).toFixed(b)},mod:function(a,b){return(+a)%(+b)},divisible:function(a,b){return a&&(+a%b)===0?a:false},even:function(a){return a&&(+a&1)===0?a:false},odd:function(a){return a&&(+a&1)===1?a:false},number:function(a){return parseFloat(a.replace(/[^\-\d\.]/g,""))},url:function(a){return encodeURI(a)},bool:function(a){return !!a},falsy:function(a){return !a},first:function(a){return a.idx===0},last:function(a){return a.idx===a.size-1},call:function(b,a){return b[a].apply(b,[].slice.call(arguments,2))},set:function(b,a){Mark.globals[a]=b;return""},log:function(a){console.log(a);return a}};if(typeof String.prototype.trim!=="function"){String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}}if(typeof module!=="undefined"&&module.exports){module.exports=Mark}else{if(typeof define==="function"&&define.amd){define(function(){return Mark})}}; -export default Mark;