diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..a65b417 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +lib diff --git a/.woodpecker.yml b/.woodpecker.yml index 5e23d44..44d3c6c 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -16,5 +16,13 @@ pipeline: - pull_request image: node:16 commands: - - npm install - npm run test + + build: + when: + event: + - push + - pull_request + image: node:16 + commands: + - npm run build diff --git a/lib/index.cjs b/lib/index.cjs new file mode 100644 index 0000000..1e6767f --- /dev/null +++ b/lib/index.cjs @@ -0,0 +1,274 @@ +'use strict'; + +function _wrapRegExp() { + _wrapRegExp = function (re, groups) { + return new BabelRegExp(re, void 0, groups); + }; + + var _super = RegExp.prototype, + _groups = new WeakMap(); + + function BabelRegExp(re, flags, groups) { + var _this = new RegExp(re, flags); + + return _groups.set(_this, groups || _groups.get(re)), _setPrototypeOf(_this, BabelRegExp.prototype); + } + + function buildGroups(result, re) { + var g = _groups.get(re); + + return Object.keys(g).reduce(function (groups, name) { + return groups[name] = result[g[name]], groups; + }, Object.create(null)); + } + + return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (str) { + var result = _super.exec.call(this, str); + + return result && (result.groups = buildGroups(result, this)), result; + }, BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { + if ("string" == typeof substitution) { + var groups = _groups.get(this); + + return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { + return "$" + groups[name]; + })); + } + + if ("function" == typeof substitution) { + var _this = this; + + return _super[Symbol.replace].call(this, str, function () { + var args = arguments; + return "object" != typeof args[args.length - 1] && (args = [].slice.call(args)).push(buildGroups(args, _this)), substitution.apply(this, args); + }); + } + + return _super[Symbol.replace].call(this, str, substitution); + }, _wrapRegExp.apply(this, arguments); +} + +function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + Object.defineProperty(subClass, "prototype", { + writable: false + }); + if (superClass) _setPrototypeOf(subClass, superClass); +} + +function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + return _setPrototypeOf(o, p); +} + +var index = { + extensions: [{ + name: 'mfm', + level: 'inline', + start: function start(src) { + var _src$match; + + return (_src$match = src.match(/\$\[/)) == null ? void 0 : _src$match.index; + }, + tokenizer: function tokenizer(src, tokens) { + // regex doesn't do well finding MFM tags: it's always either too lazy + // or too greedy. + var level = 0; + var walk = 0; + + while (level > 0 || walk === 0) { + if (src[walk] + src[walk + 1] === '$[') { + level++; + walk++; + } else if (src[walk] === ']') { + level--; + } + + walk++; + } // original regex, now definitely on the correct tag + + + var rule = /*#__PURE__*/_wrapRegExp(/^\$\[([\w\d]+)(?:\.(\S+))? ([\S\s]+)\]/, { + markup: 1, + options: 2, + text: 3 + }); + + var match = rule.exec(src.slice(0, walk)); + + if (match) { + var token = { + type: 'mfm', + raw: match[0], + markup: match.groups.markup, + options: match.groups.options, + text: match.groups.text, + tokens: [] + }; + this.lexer.inline(token.text, token.tokens); + return token; + } + }, + renderer: function renderer(token) { + var _this = this; + + var options = {}; + + if (token.options) { + options = token.options.split(',').reduce(function (i, opt) { + i[opt.split('=')[0]] = opt.split('=')[1] || true; + return i; + }, {}); + } + + var el = function el(mfmClass, mfmStyle) { + if (mfmStyle === void 0) { + mfmStyle = ''; + } + + return "" + _this.parser.parseInline(token.tokens) + ""; + }; + + switch (token.markup) { + case 'blur': + { + return el('_mfm_blur_'); + } + + case 'bounce': + { + return el('_mfm_bounce_'); + } + + case 'flip': + { + var transform = options.x && options.v ? 'scale(-1, -1)' : options.v ? 'scaleY(-1)' : 'scaleX(-1)'; + return el('_mfm_flip_', " transform: " + transform + ";"); + } + + case 'font': + { + var family = options.serif ? 'serif' : options.monospace ? 'monospace' : options.cursive ? 'cursive' : options.fantasy ? 'fantasy' : options.emoji ? 'emoji' : options.math ? 'math' : 'inherit'; + return el('_mfm_font_', " font-family: " + family + ";"); + } + + case 'jelly': + { + var speed = options.speed || '1s'; + return el('_mfm_jelly_', " animation: mfm-rubberBand " + speed + " linear infinite both;"); + } + + case 'jump': + { + return el('_mfm_jump_'); + } + + case 'rainbow': + { + return el('_mfm_rainbow_'); + } + + case 'rotate': + { + var degrees = options.deg || '90'; + return el('_mfm_rotate_', " transform: rotate(" + degrees + "deg); transform-origin: center center;"); + } + + case 'shake': + { + var _speed = options.speed || '0.5s'; + + return el('_mfm_shake_', " animation: mfm-shake " + _speed + " ease infinite;"); + } + + case 'spin': + { + var direction = options.left ? 'reverse' : options.alternate ? 'alternate' : 'normal'; + var anime = options.x ? 'mfm-spinX' : options.y ? 'mfm-spinY' : 'mfm-spin'; + + var _speed2 = options.speed || '1.5s'; + + return el('_mfm_spin_', " animation: " + anime + " " + _speed2 + " linear infinite; animation-direction: " + direction + ";"); + } + + case 'tada': + { + return el('_mfm_tada_'); + } + + case 'twitch': + { + var _speed3 = options.speed || '0.5s'; + + return el('_mfm_twitch_', " animation: mfm-twitch " + _speed3 + " ease infinite;"); + } + + case 'sparkle': + { + return el('_mfm_sparkle_'); + } + + case 'x2': + { + return el('_mfm_x2_'); + } + + case 'x3': + { + return el('_mfm_x3_'); + } + + case 'x4': + { + return el('_mfm_x4_'); + } + + default: + { + return "$[" + token.markup + " " + this.parser.parseInline(token.tokens) + "]"; + } + } + } + }, { + name: 'mfmSearch', + level: 'block', + start: function start(src) { + var _src$match2; + + return (_src$match2 = src.match(/[^\n]+ search/)) == null ? void 0 : _src$match2.index; + }, + tokenizer: function tokenizer(src, tokens) { + var rule = /^([^\n]+) search$/; + var match = rule.exec(src); + + if (match) { + var token = { + type: 'mfmSearch', + raw: match[0], + query: match[1].trim(), + tokens: [] + }; + this.lexer.inline(token.text, token.tokens); + return token; + } + }, + renderer: function renderer(token) { + return "" + token.raw + ""; + } + }] +}; + +module.exports = index; diff --git a/lib/index.umd.js b/lib/index.umd.js new file mode 100644 index 0000000..7ea7019 --- /dev/null +++ b/lib/index.umd.js @@ -0,0 +1,280 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.markedMfm = factory()); +})(this, (function () { 'use strict'; + + function _wrapRegExp() { + _wrapRegExp = function (re, groups) { + return new BabelRegExp(re, void 0, groups); + }; + + var _super = RegExp.prototype, + _groups = new WeakMap(); + + function BabelRegExp(re, flags, groups) { + var _this = new RegExp(re, flags); + + return _groups.set(_this, groups || _groups.get(re)), _setPrototypeOf(_this, BabelRegExp.prototype); + } + + function buildGroups(result, re) { + var g = _groups.get(re); + + return Object.keys(g).reduce(function (groups, name) { + return groups[name] = result[g[name]], groups; + }, Object.create(null)); + } + + return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (str) { + var result = _super.exec.call(this, str); + + return result && (result.groups = buildGroups(result, this)), result; + }, BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { + if ("string" == typeof substitution) { + var groups = _groups.get(this); + + return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { + return "$" + groups[name]; + })); + } + + if ("function" == typeof substitution) { + var _this = this; + + return _super[Symbol.replace].call(this, str, function () { + var args = arguments; + return "object" != typeof args[args.length - 1] && (args = [].slice.call(args)).push(buildGroups(args, _this)), substitution.apply(this, args); + }); + } + + return _super[Symbol.replace].call(this, str, substitution); + }, _wrapRegExp.apply(this, arguments); + } + + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + Object.defineProperty(subClass, "prototype", { + writable: false + }); + if (superClass) _setPrototypeOf(subClass, superClass); + } + + function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + return _setPrototypeOf(o, p); + } + + var index = { + extensions: [{ + name: 'mfm', + level: 'inline', + start: function start(src) { + var _src$match; + + return (_src$match = src.match(/\$\[/)) == null ? void 0 : _src$match.index; + }, + tokenizer: function tokenizer(src, tokens) { + // regex doesn't do well finding MFM tags: it's always either too lazy + // or too greedy. + var level = 0; + var walk = 0; + + while (level > 0 || walk === 0) { + if (src[walk] + src[walk + 1] === '$[') { + level++; + walk++; + } else if (src[walk] === ']') { + level--; + } + + walk++; + } // original regex, now definitely on the correct tag + + + var rule = /*#__PURE__*/_wrapRegExp(/^\$\[([\w\d]+)(?:\.(\S+))? ([\S\s]+)\]/, { + markup: 1, + options: 2, + text: 3 + }); + + var match = rule.exec(src.slice(0, walk)); + + if (match) { + var token = { + type: 'mfm', + raw: match[0], + markup: match.groups.markup, + options: match.groups.options, + text: match.groups.text, + tokens: [] + }; + this.lexer.inline(token.text, token.tokens); + return token; + } + }, + renderer: function renderer(token) { + var _this = this; + + var options = {}; + + if (token.options) { + options = token.options.split(',').reduce(function (i, opt) { + i[opt.split('=')[0]] = opt.split('=')[1] || true; + return i; + }, {}); + } + + var el = function el(mfmClass, mfmStyle) { + if (mfmStyle === void 0) { + mfmStyle = ''; + } + + return "" + _this.parser.parseInline(token.tokens) + ""; + }; + + switch (token.markup) { + case 'blur': + { + return el('_mfm_blur_'); + } + + case 'bounce': + { + return el('_mfm_bounce_'); + } + + case 'flip': + { + var transform = options.x && options.v ? 'scale(-1, -1)' : options.v ? 'scaleY(-1)' : 'scaleX(-1)'; + return el('_mfm_flip_', " transform: " + transform + ";"); + } + + case 'font': + { + var family = options.serif ? 'serif' : options.monospace ? 'monospace' : options.cursive ? 'cursive' : options.fantasy ? 'fantasy' : options.emoji ? 'emoji' : options.math ? 'math' : 'inherit'; + return el('_mfm_font_', " font-family: " + family + ";"); + } + + case 'jelly': + { + var speed = options.speed || '1s'; + return el('_mfm_jelly_', " animation: mfm-rubberBand " + speed + " linear infinite both;"); + } + + case 'jump': + { + return el('_mfm_jump_'); + } + + case 'rainbow': + { + return el('_mfm_rainbow_'); + } + + case 'rotate': + { + var degrees = options.deg || '90'; + return el('_mfm_rotate_', " transform: rotate(" + degrees + "deg); transform-origin: center center;"); + } + + case 'shake': + { + var _speed = options.speed || '0.5s'; + + return el('_mfm_shake_', " animation: mfm-shake " + _speed + " ease infinite;"); + } + + case 'spin': + { + var direction = options.left ? 'reverse' : options.alternate ? 'alternate' : 'normal'; + var anime = options.x ? 'mfm-spinX' : options.y ? 'mfm-spinY' : 'mfm-spin'; + + var _speed2 = options.speed || '1.5s'; + + return el('_mfm_spin_', " animation: " + anime + " " + _speed2 + " linear infinite; animation-direction: " + direction + ";"); + } + + case 'tada': + { + return el('_mfm_tada_'); + } + + case 'twitch': + { + var _speed3 = options.speed || '0.5s'; + + return el('_mfm_twitch_', " animation: mfm-twitch " + _speed3 + " ease infinite;"); + } + + case 'sparkle': + { + return el('_mfm_sparkle_'); + } + + case 'x2': + { + return el('_mfm_x2_'); + } + + case 'x3': + { + return el('_mfm_x3_'); + } + + case 'x4': + { + return el('_mfm_x4_'); + } + + default: + { + return "$[" + token.markup + " " + this.parser.parseInline(token.tokens) + "]"; + } + } + } + }, { + name: 'mfmSearch', + level: 'block', + start: function start(src) { + var _src$match2; + + return (_src$match2 = src.match(/[^\n]+ search/)) == null ? void 0 : _src$match2.index; + }, + tokenizer: function tokenizer(src, tokens) { + var rule = /^([^\n]+) search$/; + var match = rule.exec(src); + + if (match) { + var token = { + type: 'mfmSearch', + raw: match[0], + query: match[1].trim(), + tokens: [] + }; + this.lexer.inline(token.text, token.tokens); + return token; + } + }, + renderer: function renderer(token) { + return "" + token.raw + ""; + } + }] + }; + + return index; + +})); diff --git a/package-lock.json b/package-lock.json index 5a5fb1c..5936239 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,11 +11,14 @@ "dependencies": { "@babel/core": "^7.18.6", "@babel/preset-env": "^7.18.6", + "@rollup/plugin-babel": "^5.3.1", + "@rollup/plugin-commonjs": "^22.0.1", "babel-jest": "^28.1.2", "eslint": "^8.19.0", "eslint-config-standard": "^17.0.0", "eslint-plugin-jest": "^26.5.3", - "jest-cli": "^28.1.2" + "jest-cli": "^28.1.2", + "rollup": "^2.76.0" }, "peerDependencies": { "marked": "^4.0.17" @@ -2164,6 +2167,69 @@ "node": ">= 8" } }, + "node_modules/@rollup/plugin-babel": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-babel/-/plugin-babel-5.3.1.tgz", + "integrity": "sha512-WFfdLWU/xVWKeRQnKmIAQULUI7Il0gZnBIH/ZFO069wYIfPu+8zrfp/KMW0atmELoRDq8FbiP3VCss9MhCut7Q==", + "dependencies": { + "@babel/helper-module-imports": "^7.10.4", + "@rollup/pluginutils": "^3.1.0" + }, + "engines": { + "node": ">= 10.0.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0", + "@types/babel__core": "^7.1.9", + "rollup": "^1.20.0||^2.0.0" + }, + "peerDependenciesMeta": { + "@types/babel__core": { + "optional": true + } + } + }, + "node_modules/@rollup/plugin-commonjs": { + "version": "22.0.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-22.0.1.tgz", + "integrity": "sha512-dGfEZvdjDHObBiP5IvwTKMVeq/tBZGMBHZFMdIV1ClMM/YoWS34xrHFGfag9SN2ZtMgNZRFruqvxZQEa70O6nQ==", + "dependencies": { + "@rollup/pluginutils": "^3.1.0", + "commondir": "^1.0.1", + "estree-walker": "^2.0.1", + "glob": "^7.1.6", + "is-reference": "^1.2.1", + "magic-string": "^0.25.7", + "resolve": "^1.17.0" + }, + "engines": { + "node": ">= 12.0.0" + }, + "peerDependencies": { + "rollup": "^2.68.0" + } + }, + "node_modules/@rollup/pluginutils": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", + "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", + "dependencies": { + "@types/estree": "0.0.39", + "estree-walker": "^1.0.1", + "picomatch": "^2.2.2" + }, + "engines": { + "node": ">= 8.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0" + } + }, + "node_modules/@rollup/pluginutils/node_modules/estree-walker": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", + "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==" + }, "node_modules/@sinclair/typebox": { "version": "0.23.5", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.23.5.tgz", @@ -2222,6 +2288,11 @@ "@babel/types": "^7.3.0" } }, + "node_modules/@types/estree": { + "version": "0.0.39", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", + "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==" + }, "node_modules/@types/graceful-fs": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.5.tgz", @@ -2874,6 +2945,11 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, + "node_modules/commondir": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", + "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==" + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -3493,6 +3569,11 @@ "node": ">=4.0" } }, + "node_modules/estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==" + }, "node_modules/esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -4137,6 +4218,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-reference": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", + "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", + "dependencies": { + "@types/estree": "*" + } + }, "node_modules/is-regex": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", @@ -4923,6 +5012,14 @@ "node": ">=10" } }, + "node_modules/magic-string": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz", + "integrity": "sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==", + "dependencies": { + "sourcemap-codec": "^1.4.8" + } + }, "node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -5597,6 +5694,20 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/rollup": { + "version": "2.76.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.76.0.tgz", + "integrity": "sha512-9jwRIEY1jOzKLj3nsY/yot41r19ITdQrhs+q3ggNWhr9TQgduHqANvPpS32RNpzGklJu3G1AJfvlZLi/6wFgWA==", + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=10.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -5706,6 +5817,11 @@ "source-map": "^0.6.0" } }, + "node_modules/sourcemap-codec": { + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz", + "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==" + }, "node_modules/sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", @@ -7721,6 +7837,46 @@ "fastq": "^1.6.0" } }, + "@rollup/plugin-babel": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-babel/-/plugin-babel-5.3.1.tgz", + "integrity": "sha512-WFfdLWU/xVWKeRQnKmIAQULUI7Il0gZnBIH/ZFO069wYIfPu+8zrfp/KMW0atmELoRDq8FbiP3VCss9MhCut7Q==", + "requires": { + "@babel/helper-module-imports": "^7.10.4", + "@rollup/pluginutils": "^3.1.0" + } + }, + "@rollup/plugin-commonjs": { + "version": "22.0.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-22.0.1.tgz", + "integrity": "sha512-dGfEZvdjDHObBiP5IvwTKMVeq/tBZGMBHZFMdIV1ClMM/YoWS34xrHFGfag9SN2ZtMgNZRFruqvxZQEa70O6nQ==", + "requires": { + "@rollup/pluginutils": "^3.1.0", + "commondir": "^1.0.1", + "estree-walker": "^2.0.1", + "glob": "^7.1.6", + "is-reference": "^1.2.1", + "magic-string": "^0.25.7", + "resolve": "^1.17.0" + } + }, + "@rollup/pluginutils": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", + "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", + "requires": { + "@types/estree": "0.0.39", + "estree-walker": "^1.0.1", + "picomatch": "^2.2.2" + }, + "dependencies": { + "estree-walker": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", + "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==" + } + } + }, "@sinclair/typebox": { "version": "0.23.5", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.23.5.tgz", @@ -7779,6 +7935,11 @@ "@babel/types": "^7.3.0" } }, + "@types/estree": { + "version": "0.0.39", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", + "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==" + }, "@types/graceful-fs": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.5.tgz", @@ -8250,6 +8411,11 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, + "commondir": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", + "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==" + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -8691,6 +8857,11 @@ "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==" }, + "estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==" + }, "esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -9141,6 +9312,14 @@ "has-tostringtag": "^1.0.0" } }, + "is-reference": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", + "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", + "requires": { + "@types/estree": "*" + } + }, "is-regex": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", @@ -9738,6 +9917,14 @@ "yallist": "^4.0.0" } }, + "magic-string": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz", + "integrity": "sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==", + "requires": { + "sourcemap-codec": "^1.4.8" + } + }, "make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -10212,6 +10399,14 @@ "glob": "^7.1.3" } }, + "rollup": { + "version": "2.76.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.76.0.tgz", + "integrity": "sha512-9jwRIEY1jOzKLj3nsY/yot41r19ITdQrhs+q3ggNWhr9TQgduHqANvPpS32RNpzGklJu3G1AJfvlZLi/6wFgWA==", + "requires": { + "fsevents": "~2.3.2" + } + }, "run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -10286,6 +10481,11 @@ "source-map": "^0.6.0" } }, + "sourcemap-codec": { + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz", + "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==" + }, "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", diff --git a/package.json b/package.json index 0096b01..1977e6f 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,13 @@ "version": "0.1.1", "description": "Marked.js extension for Misskey-flavored Markdown", "main": "./src/index.js", + "browser": "./lib/index.umd.js", "type": "module", "scripts": { "lint": "eslint .", "lint-fix": "eslint --fix .", - "test": "jest --verbose" + "test": "jest --verbose", + "build": "rollup -c rollup.config.umd.js" }, "repository": { "type": "git", @@ -24,10 +26,13 @@ "dependencies": { "@babel/core": "^7.18.6", "@babel/preset-env": "^7.18.6", + "@rollup/plugin-babel": "^5.3.1", + "@rollup/plugin-commonjs": "^22.0.1", "babel-jest": "^28.1.2", "eslint": "^8.19.0", "eslint-config-standard": "^17.0.0", "eslint-plugin-jest": "^26.5.3", - "jest-cli": "^28.1.2" + "jest-cli": "^28.1.2", + "rollup": "^2.76.0" } } diff --git a/rollup.config.umd.js b/rollup.config.umd.js new file mode 100644 index 0000000..b92047a --- /dev/null +++ b/rollup.config.umd.js @@ -0,0 +1,14 @@ +const babel = require('@rollup/plugin-babel').default + +export default { + input: 'src/index.js', + output: { + name: 'markedMfm', + file: 'lib/index.umd.js', + exports: 'default', + format: 'umd', + }, + plugins: [ + babel({ presets: [['@babel/preset-env', { loose: true }]] }), + ], +}