markmap-lib
Advanced tools
@@ -1,3 +0,4 @@ | ||
/*! markmap-lib v0.14.2-alpha.2+3837810 | MIT License */ | ||
import _extends$1 from '@babel/runtime/helpers/esm/extends'; | ||
/*! markmap-lib v0.14.2-alpha.4+569dd11 | MIT License */ | ||
import _extends from '@babel/runtime/helpers/esm/extends'; | ||
import { persistCSS, persistJS, Hook, wrapFunction } from 'markmap-common'; | ||
import { Remarkable } from 'remarkable'; | ||
@@ -9,172 +10,4 @@ import remarkableKatex from 'remarkable-katex'; | ||
/*! markmap-common v0.14.2-alpha.2+3837810 | MIT License */ | ||
class Hook { | ||
constructor() { | ||
this.listeners = []; | ||
} | ||
tap(fn) { | ||
this.listeners.push(fn); | ||
return () => this.revoke(fn); | ||
} | ||
revoke(fn) { | ||
const i = this.listeners.indexOf(fn); | ||
if (i >= 0) this.listeners.splice(i, 1); | ||
} | ||
revokeAll() { | ||
this.listeners.splice(0); | ||
} | ||
call(...args) { | ||
for (const fn of this.listeners) { | ||
fn(...args); | ||
} | ||
} | ||
} | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
const _excluded = ["textContent"]; | ||
function escapeHtml(html) { | ||
return html.replace(/[&<"]/g, m => ({ | ||
'&': '&', | ||
'<': '<', | ||
'"': '"' | ||
})[m]); | ||
} | ||
function escapeScript(content) { | ||
return content.replace(/<(\/script>)/g, '\\x3c$2'); | ||
} | ||
function htmlOpen(tagName, attrs) { | ||
const attrStr = attrs ? Object.entries(attrs).map(([key, value]) => { | ||
if (value == null || value === false) return; | ||
key = ` ${escapeHtml(key)}`; | ||
if (value === true) return key; | ||
return `${key}="${escapeHtml(value)}"`; | ||
}).filter(Boolean).join('') : ''; | ||
return `<${tagName}${attrStr}>`; | ||
} | ||
function htmlClose(tagName) { | ||
return `</${tagName}>`; | ||
} | ||
function wrapHtml(tagName, content, attrs) { | ||
if (content == null) return htmlOpen(tagName, attrs); | ||
return htmlOpen(tagName, attrs) + (content || '') + htmlClose(tagName); | ||
} | ||
function buildCode(fn, args) { | ||
const params = args.map(arg => { | ||
if (typeof arg === 'function') return arg.toString(); | ||
return JSON.stringify(arg != null ? arg : null); | ||
}).join(','); | ||
return `(${fn.toString()})(${params})`; | ||
} | ||
function persistJS(items, context) { | ||
return items.map(item => { | ||
if (item.type === 'script') { | ||
const _item$data = item.data, | ||
{ | ||
textContent | ||
} = _item$data, | ||
rest = _objectWithoutPropertiesLoose(_item$data, _excluded); | ||
return wrapHtml('script', textContent || '', rest); | ||
} | ||
if (item.type === 'iife') { | ||
const { | ||
fn, | ||
getParams | ||
} = item.data; | ||
return wrapHtml('script', escapeScript(buildCode(fn, (getParams == null ? void 0 : getParams(context)) || []))); | ||
} | ||
return ''; | ||
}); | ||
} | ||
function persistCSS(items) { | ||
return items.map(item => { | ||
if (item.type === 'stylesheet') { | ||
return wrapHtml('link', null, _extends({ | ||
rel: 'stylesheet' | ||
}, item.data)); | ||
} | ||
/* else if (item.type === 'style') */ | ||
return wrapHtml('style', item.data); | ||
}); | ||
} | ||
Math.random().toString(36).slice(2, 8); | ||
function wrapFunction(fn, { | ||
before, | ||
after | ||
}) { | ||
return function wrapped(...args) { | ||
const ctx = { | ||
args, | ||
thisObj: this | ||
}; | ||
try { | ||
if (before) before(ctx); | ||
} catch (_unused) {// ignore | ||
} | ||
ctx.result = fn.apply(ctx.thisObj, ctx.args); | ||
try { | ||
if (after) after(ctx); | ||
} catch (_unused2) {// ignore | ||
} | ||
return ctx.result; | ||
}; | ||
} | ||
const template = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n<title>Markmap</title>\n<style>\n* {\n margin: 0;\n padding: 0;\n}\n#mindmap {\n display: block;\n width: 100vw;\n height: 100vh;\n}\n</style>\n<!--CSS-->\n</head>\n<body>\n<svg id=\"mindmap\"></svg>\n<!--JS-->\n</body>\n</html>\n"; | ||
const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.14.2-alpha.2+3837810"}`].map(src => ({ | ||
const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.14.2-alpha.4+569dd11"}`].map(src => ({ | ||
type: 'script', | ||
@@ -186,3 +19,3 @@ data: { | ||
function fillTemplate(root, assets, extra) { | ||
extra = _extends$1({ | ||
extra = _extends({ | ||
baseJs: BASE_JS | ||
@@ -459,3 +292,3 @@ }, extra); | ||
node.content = item.content; | ||
node.payload = _extends$1({}, node.payload, item.payload); | ||
node.payload = _extends({}, node.payload, item.payload); | ||
} | ||
@@ -478,3 +311,3 @@ | ||
if (item.type === 'list_item') { | ||
item.payload = _extends$1({}, item.payload, { | ||
item.payload = _extends({}, item.payload, { | ||
index | ||
@@ -641,3 +474,3 @@ }); | ||
resetDepth(root); | ||
return _extends$1({}, context, { | ||
return _extends({}, context, { | ||
root | ||
@@ -683,3 +516,3 @@ }); | ||
const transformerVersions = { | ||
'markmap-lib': '0.14.2-alpha.2+3837810', | ||
'markmap-lib': '0.14.2-alpha.4+569dd11', | ||
d3: "6.7.0" | ||
@@ -686,0 +519,0 @@ }; |
@@ -1,5 +0,6 @@ | ||
/*! markmap-lib v0.14.2-alpha.2+3837810 | MIT License */ | ||
/*! markmap-lib v0.14.2-alpha.4+569dd11 | MIT License */ | ||
'use strict'; | ||
var _extends$1 = require('@babel/runtime/helpers/extends'); | ||
var _extends = require('@babel/runtime/helpers/extends'); | ||
var markmapCommon = require('markmap-common'); | ||
var remarkable = require('remarkable'); | ||
@@ -13,3 +14,3 @@ var remarkableKatex = require('remarkable-katex'); | ||
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends$1); | ||
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends); | ||
var remarkableKatex__default = /*#__PURE__*/_interopDefaultLegacy(remarkableKatex); | ||
@@ -20,172 +21,4 @@ var Prism__default = /*#__PURE__*/_interopDefaultLegacy(Prism); | ||
/*! markmap-common v0.14.2-alpha.2+3837810 | MIT License */ | ||
class Hook { | ||
constructor() { | ||
this.listeners = []; | ||
} | ||
tap(fn) { | ||
this.listeners.push(fn); | ||
return () => this.revoke(fn); | ||
} | ||
revoke(fn) { | ||
const i = this.listeners.indexOf(fn); | ||
if (i >= 0) this.listeners.splice(i, 1); | ||
} | ||
revokeAll() { | ||
this.listeners.splice(0); | ||
} | ||
call(...args) { | ||
for (const fn of this.listeners) { | ||
fn(...args); | ||
} | ||
} | ||
} | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
const _excluded = ["textContent"]; | ||
function escapeHtml(html) { | ||
return html.replace(/[&<"]/g, m => ({ | ||
'&': '&', | ||
'<': '<', | ||
'"': '"' | ||
})[m]); | ||
} | ||
function escapeScript(content) { | ||
return content.replace(/<(\/script>)/g, '\\x3c$2'); | ||
} | ||
function htmlOpen(tagName, attrs) { | ||
const attrStr = attrs ? Object.entries(attrs).map(([key, value]) => { | ||
if (value == null || value === false) return; | ||
key = ` ${escapeHtml(key)}`; | ||
if (value === true) return key; | ||
return `${key}="${escapeHtml(value)}"`; | ||
}).filter(Boolean).join('') : ''; | ||
return `<${tagName}${attrStr}>`; | ||
} | ||
function htmlClose(tagName) { | ||
return `</${tagName}>`; | ||
} | ||
function wrapHtml(tagName, content, attrs) { | ||
if (content == null) return htmlOpen(tagName, attrs); | ||
return htmlOpen(tagName, attrs) + (content || '') + htmlClose(tagName); | ||
} | ||
function buildCode(fn, args) { | ||
const params = args.map(arg => { | ||
if (typeof arg === 'function') return arg.toString(); | ||
return JSON.stringify(arg != null ? arg : null); | ||
}).join(','); | ||
return `(${fn.toString()})(${params})`; | ||
} | ||
function persistJS(items, context) { | ||
return items.map(item => { | ||
if (item.type === 'script') { | ||
const _item$data = item.data, | ||
{ | ||
textContent | ||
} = _item$data, | ||
rest = _objectWithoutPropertiesLoose(_item$data, _excluded); | ||
return wrapHtml('script', textContent || '', rest); | ||
} | ||
if (item.type === 'iife') { | ||
const { | ||
fn, | ||
getParams | ||
} = item.data; | ||
return wrapHtml('script', escapeScript(buildCode(fn, (getParams == null ? void 0 : getParams(context)) || []))); | ||
} | ||
return ''; | ||
}); | ||
} | ||
function persistCSS(items) { | ||
return items.map(item => { | ||
if (item.type === 'stylesheet') { | ||
return wrapHtml('link', null, _extends({ | ||
rel: 'stylesheet' | ||
}, item.data)); | ||
} | ||
/* else if (item.type === 'style') */ | ||
return wrapHtml('style', item.data); | ||
}); | ||
} | ||
Math.random().toString(36).slice(2, 8); | ||
function wrapFunction(fn, { | ||
before, | ||
after | ||
}) { | ||
return function wrapped(...args) { | ||
const ctx = { | ||
args, | ||
thisObj: this | ||
}; | ||
try { | ||
if (before) before(ctx); | ||
} catch (_unused) {// ignore | ||
} | ||
ctx.result = fn.apply(ctx.thisObj, ctx.args); | ||
try { | ||
if (after) after(ctx); | ||
} catch (_unused2) {// ignore | ||
} | ||
return ctx.result; | ||
}; | ||
} | ||
const template = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n<title>Markmap</title>\n<style>\n* {\n margin: 0;\n padding: 0;\n}\n#mindmap {\n display: block;\n width: 100vw;\n height: 100vh;\n}\n</style>\n<!--CSS-->\n</head>\n<body>\n<svg id=\"mindmap\"></svg>\n<!--JS-->\n</body>\n</html>\n"; | ||
const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.14.2-alpha.2+3837810"}`].map(src => ({ | ||
const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.14.2-alpha.4+569dd11"}`].map(src => ({ | ||
type: 'script', | ||
@@ -204,3 +37,3 @@ data: { | ||
} = assets; | ||
const cssList = [...(styles ? persistCSS(styles) : [])]; | ||
const cssList = [...(styles ? markmapCommon.persistCSS(styles) : [])]; | ||
const context = { | ||
@@ -212,3 +45,3 @@ getMarkmap: () => window.markmap, | ||
}; | ||
const jsList = [...persistJS([...extra.baseJs, ...(scripts || []), { | ||
const jsList = [...markmapCommon.persistJS([...extra.baseJs, ...(scripts || []), { | ||
type: 'iife', | ||
@@ -283,7 +116,7 @@ data: { | ||
return { | ||
parser: new Hook(), | ||
beforeParse: new Hook(), | ||
afterParse: new Hook(), | ||
htmltag: new Hook(), | ||
retransform: new Hook() | ||
parser: new markmapCommon.Hook(), | ||
beforeParse: new markmapCommon.Hook(), | ||
afterParse: new markmapCommon.Hook(), | ||
htmltag: new markmapCommon.Hook(), | ||
retransform: new markmapCommon.Hook() | ||
}; | ||
@@ -309,3 +142,3 @@ } | ||
md.use(remarkableKatex__default); | ||
md.renderer.rules.katex = wrapFunction(md.renderer.rules.katex, { | ||
md.renderer.rules.katex = markmapCommon.wrapFunction(md.renderer.rules.katex, { | ||
after: () => { | ||
@@ -398,3 +231,3 @@ enableFeature(); | ||
const origParse = md.parse; | ||
md.parse = wrapFunction(origParse, { | ||
md.parse = markmapCommon.wrapFunction(origParse, { | ||
before(ctx) { | ||
@@ -540,3 +373,3 @@ const [content] = ctx.args; | ||
}); | ||
md.renderer.rules.htmltag = wrapFunction(md.renderer.rules.htmltag, { | ||
md.renderer.rules.htmltag = markmapCommon.wrapFunction(md.renderer.rules.htmltag, { | ||
after: ctx => { | ||
@@ -696,3 +529,3 @@ this.hooks.htmltag.call(ctx); | ||
const transformerVersions = { | ||
'markmap-lib': '0.14.2-alpha.2+3837810', | ||
'markmap-lib': '0.14.2-alpha.4+569dd11', | ||
d3: "6.7.0" | ||
@@ -699,0 +532,0 @@ }; |
{ | ||
"name": "markmap-lib", | ||
"version": "0.14.2-alpha.2+3837810", | ||
"version": "0.14.2-alpha.4+569dd11", | ||
"description": "Visualize your Markdown as mindmaps with Markmap", | ||
@@ -46,4 +46,4 @@ "author": "Gerald <gera2ld@live.com>", | ||
"@types/remarkable": "^2.0.3", | ||
"markmap-common": "^0.14.2-alpha.2+3837810", | ||
"markmap-view": "^0.14.2-alpha.2+3837810", | ||
"markmap-common": "^0.14.0", | ||
"markmap-view": "^0.14.2-alpha.4+569dd11", | ||
"webfontloader": "^1.6.28" | ||
@@ -62,3 +62,3 @@ }, | ||
}, | ||
"gitHead": "383781072bc17aa572b0cdffcfcf8d2d38d69f39" | ||
"gitHead": "569dd1128d16297708b4fb3789dbc43b082c2ee9" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
470622
-1.44%12471
-2.1%