Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

markmap-common

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markmap-common - npm Package Compare versions

Comparing version 0.15.5 to 0.15.6

dist/hook.d.ts

403

dist/index.js

@@ -1,46 +0,52 @@

/*! markmap-common v0.15.5 | MIT License */
'use strict';
function _extends() {
_extends = Object.assign ? Object.assign.bind() : 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);
}
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const testPath = "npm2url/dist/index.cjs";
const defaultProviders = {
jsdelivr: path => `https://cdn.jsdelivr.net/npm/${path}`,
unpkg: path => `https://unpkg.com/${path}`
jsdelivr: (path) => `https://cdn.jsdelivr.net/npm/${path}`,
unpkg: (path) => `https://unpkg.com/${path}`
};
async function checkUrl(url, signal) {
const res = await fetch(url, {
signal
});
if (!res.ok) {
throw res;
}
await res.text();
}
class UrlBuilder {
constructor() {
this.providers = _extends({}, defaultProviders);
this.providers = { ...defaultProviders };
this.provider = "jsdelivr";
}
getFastestProvider(timeout = 5e3, path = testPath) {
return new Promise((resolve, reject) => {
Promise.all(Object.entries(this.providers).map(async ([name, factory]) => {
try {
const res = await fetch(factory(path));
if (!res.ok) {
throw res;
}
await res.text();
resolve(name);
} catch (_unused) {}
})).then(() => reject(new Error("All providers failed")));
setTimeout(reject, timeout, new Error("Timed out"));
});
/**
* Get the fastest provider name.
* If none of the providers returns a valid response within `timeout`, an error will be thrown.
*/
async getFastestProvider(timeout = 5e3, path = testPath) {
const controller = new AbortController();
let timer = 0;
try {
return await new Promise((resolve, reject) => {
Promise.all(
Object.entries(this.providers).map(async ([name, factory]) => {
try {
await checkUrl(factory(path), controller.signal);
resolve(name);
} catch {
}
})
).then(() => reject(new Error("All providers failed")));
timer = setTimeout(reject, timeout, new Error("Timed out"));
});
} finally {
controller.abort();
clearTimeout(timer);
}
}
async findFastestProvider(timeout) {
this.provider = await this.getFastestProvider(timeout);
/**
* Set the current provider to the fastest provider found by `getFastestProvider`.
*/
async findFastestProvider(timeout, path) {
this.provider = await this.getFastestProvider(timeout, path);
return this.provider;

@@ -67,3 +73,2 @@ }

const urlBuilder = new UrlBuilder();
class Hook {

@@ -79,3 +84,4 @@ constructor() {

const i = this.listeners.indexOf(fn);
if (i >= 0) this.listeners.splice(i, 1);
if (i >= 0)
this.listeners.splice(i, 1);
}

@@ -91,35 +97,22 @@ revokeAll() {

}
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"];
const escapeChars = {
'&': '&amp;',
'<': '&lt;',
'"': '&quot;'
"&": "&amp;",
"<": "&lt;",
'"': "&quot;"
};
function escapeHtml(html) {
return html.replace(/[&<"]/g, m => escapeChars[m]);
return html.replace(/[&<"]/g, (m) => escapeChars[m]);
}
function escapeScript(content) {
return content.replace(/<(\/script>)/g, '\\x3c$2');
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;
if (value == null || value === false)
return;
key = ` ${escapeHtml(key)}`;
if (value === true) return key;
if (value === true)
return key;
return `${key}="${escapeHtml(value)}"`;
}).filter(Boolean).join('') : '';
}).filter(Boolean).join("") : "";
return `<${tagName}${attrStr}>`;

@@ -131,44 +124,45 @@ }

function wrapHtml(tagName, content, attrs) {
if (content == null) return htmlOpen(tagName, attrs);
return htmlOpen(tagName, attrs) + (content || '') + htmlClose(tagName);
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(',');
const params = args.map((arg) => {
if (typeof arg === "function")
return arg.toString();
return JSON.stringify(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);
return items.map((item) => {
if (item.type === "script") {
const { textContent, ...rest } = item.data;
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)) || [])));
if (item.type === "iife") {
const { fn, getParams } = item.data;
return wrapHtml(
"script",
escapeScript(buildCode(fn, (getParams == null ? void 0 : getParams(context)) || []))
);
}
return '';
return "";
});
}
function persistCSS(items) {
return items.map(item => {
if (item.type === 'stylesheet') {
return wrapHtml('link', null, _extends({
rel: 'stylesheet'
}, item.data));
return items.map((item) => {
if (item.type === "stylesheet") {
return wrapHtml("link", null, {
rel: "stylesheet",
...item.data
});
}
/* else if (item.type === 'style') */
return wrapHtml('style', item.data);
return wrapHtml("style", item.data);
});
}
const uniqId = Math.random().toString(36).slice(2, 8);

@@ -181,24 +175,28 @@ let globalIndex = 0;

function noop() {
// noop
}
function walkTree(tree, callback) {
const walk = (item, parent) => callback(item, () => {
var _item$children;
(_item$children = item.children) == null || _item$children.forEach(child => {
walk(child, item);
});
}, parent);
const walk = (item, parent) => callback(
item,
() => {
var _a;
(_a = item.children) == null ? void 0 : _a.forEach((child) => {
walk(child, item);
});
},
parent
);
walk(tree);
}
function addClass(className, ...rest) {
const classList = (className || '').split(' ').filter(Boolean);
rest.forEach(item => {
if (item && classList.indexOf(item) < 0) classList.push(item);
const classList = (className || "").split(" ").filter(Boolean);
rest.forEach((item) => {
if (item && classList.indexOf(item) < 0)
classList.push(item);
});
return classList.join(' ');
return classList.join(" ");
}
function childSelector(filter) {
if (typeof filter === 'string') {
if (typeof filter === "string") {
const tagName = filter;
filter = el => el.tagName === tagName;
filter = (el) => el.tagName === tagName;
}

@@ -208,3 +206,4 @@ const filterFn = filter;

let nodes = Array.from(this.childNodes);
if (filterFn) nodes = nodes.filter(node => filterFn(node));
if (filterFn)
nodes = nodes.filter((node) => filterFn(node));
return nodes;

@@ -238,8 +237,7 @@ };

}
/*! @gera2ld/jsx-dom v2.2.2 | ISC License */
const VTYPE_ELEMENT = 1;
const VTYPE_FUNCTION = 2;
const SVG_NS = 'http://www.w3.org/2000/svg';
const XLINK_NS = 'http://www.w3.org/1999/xlink';
const SVG_NS = "http://www.w3.org/2000/svg";
const XLINK_NS = "http://www.w3.org/1999/xlink";
const NS_ATTRS = {

@@ -250,5 +248,5 @@ show: XLINK_NS,

};
const isLeaf = c => typeof c === 'string' || typeof c === 'number';
const isElement = c => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
const isRenderFunction = c => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
const isLeaf = (c) => typeof c === "string" || typeof c === "number";
const isElement = (c) => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
const isRenderFunction = (c) => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
function h(type, props, ...children) {

@@ -262,3 +260,8 @@ props = Object.assign({}, props, {

let vtype;
if (typeof type === 'string') vtype = VTYPE_ELEMENT;else if (typeof type === 'function') vtype = VTYPE_FUNCTION;else throw new Error('Invalid VNode type');
if (typeof type === "string")
vtype = VTYPE_ELEMENT;
else if (typeof type === "function")
vtype = VTYPE_FUNCTION;
else
throw new Error("Invalid VNode type");
return {

@@ -277,15 +280,19 @@ vtype,

function insertDom(parent, nodes) {
if (!Array.isArray(nodes)) nodes = [nodes];
if (!Array.isArray(nodes))
nodes = [nodes];
nodes = nodes.filter(Boolean);
if (nodes.length) parent.append(...nodes);
if (nodes.length)
parent.append(...nodes);
}
function mountAttributes(domElement, props, env) {
for (const key in props) {
if (key === 'key' || key === 'children' || key === 'ref') continue;
if (key === 'dangerouslySetInnerHTML') {
if (key === "key" || key === "children" || key === "ref")
continue;
if (key === "dangerouslySetInnerHTML") {
domElement.innerHTML = props[key].__html;
} else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText' || key === 'value' && ['textarea', 'select'].includes(domElement.tagName)) {
} else if (key === "innerHTML" || key === "textContent" || key === "innerText" || key === "value" && ["textarea", "select"].includes(domElement.tagName)) {
const value = props[key];
if (value != null) domElement[key] = value;
} else if (key.startsWith('on')) {
if (value != null)
domElement[key] = value;
} else if (key.startsWith("on")) {
domElement[key.toLowerCase()] = props[key];

@@ -298,4 +305,4 @@ } else {

const attrMap = {
className: 'class',
labelFor: 'for'
className: "class",
labelFor: "for"
};

@@ -305,8 +312,8 @@ function setDOMAttribute(el, attr, value, isSVG) {

if (value === true) {
el.setAttribute(attr, '');
el.setAttribute(attr, "");
} else if (value === false) {
el.removeAttribute(attr);
} else {
const namespace = isSVG ? NS_ATTRS[attr] : undefined;
if (namespace !== undefined) {
const namespace = isSVG ? NS_ATTRS[attr] : void 0;
if (namespace !== void 0) {
el.setAttributeNS(namespace, attr, value);

@@ -322,6 +329,6 @@ } else {

function mountChildren(children, env) {
return Array.isArray(children) ? flatten(children.map(child => mountChildren(child, env))) : mount(children, env);
return Array.isArray(children) ? flatten(children.map((child) => mountChildren(child, env))) : mount(children, env);
}
function mount(vnode, env = DEFAULT_ENV) {
if (vnode == null || typeof vnode === 'boolean') {
if (vnode == null || typeof vnode === "boolean") {
return null;

@@ -357,3 +364,3 @@ }

} = vnode;
if (!env.isSvg && type === 'svg') {
if (!env.isSvg && type === "svg") {
env = Object.assign({}, env, {

@@ -371,3 +378,3 @@ isSvg: true

let childEnv = env;
if (env.isSvg && type === 'foreignObject') {
if (env.isSvg && type === "foreignObject") {
childEnv = Object.assign({}, childEnv, {

@@ -378,3 +385,4 @@ isSvg: false

const children = mountChildren(props.children, childEnv);
if (children != null) insertDom(node, children);
if (children != null)
insertDom(node, children);
}

@@ -384,28 +392,22 @@ const {

} = props;
if (typeof ref === 'function') ref(node);
if (typeof ref === "function")
ref(node);
return node;
}
throw new Error('mount: Invalid Vnode!');
throw new Error("mount: Invalid Vnode!");
}
/**
* Mount vdom as real DOM nodes.
*/
function mountDom(vnode) {
return mount(vnode);
}
/**
* Render and mount without returning VirtualDOM, useful when you don't need SVG support.
*/
function hm(...args) {
return mountDom(h(...args));
}
const memoizedPreloadJS = memoize(url => {
document.head.append(hm('link', {
rel: 'preload',
as: 'script',
href: url
}));
const memoizedPreloadJS = memoize((url) => {
document.head.append(
hm("link", {
rel: "preload",
as: "script",
href: url
})
);
});

@@ -415,28 +417,26 @@ const jsCache = {};

async function loadJSItem(item, context) {
var _item$data;
const src = item.type === 'script' && ((_item$data = item.data) == null ? void 0 : _item$data.src) || '';
var _a;
const src = item.type === "script" && ((_a = item.data) == null ? void 0 : _a.src) || "";
item.loaded || (item.loaded = jsCache[src]);
if (!item.loaded) {
if (item.type === 'script') {
item.loaded = new Promise((resolve, reject) => {
document.head.append(hm('script', _extends({}, item.data, {
onLoad: resolve,
onError: reject
})));
if (!src) {
// Run inline script synchronously
resolve(undefined);
}
}).then(() => {
item.loaded = true;
});
if (src) jsCache[src] = item.loaded;
const deferred = defer();
item.loaded = deferred.promise;
if (item.type === "script") {
document.head.append(
hm("script", {
...item.data,
onLoad: () => deferred.resolve(),
onError: deferred.reject
})
);
if (!src) {
deferred.resolve();
} else {
jsCache[src] = item.loaded;
}
}
if (item.type === 'iife') {
const {
fn,
getParams
} = item.data;
fn(...((getParams == null ? void 0 : getParams(context)) || []));
item.loaded = true;
if (item.type === "iife") {
const { fn, getParams } = item.data;
fn(...(getParams == null ? void 0 : getParams(context)) || []);
deferred.resolve();
}

@@ -446,28 +446,44 @@ }

}
function loadCSSItem(item) {
const url = item.type === 'stylesheet' && item.data.href || '';
async function loadCSSItem(item) {
const url = item.type === "stylesheet" && item.data.href || "";
item.loaded || (item.loaded = cssCache[url]);
if (item.loaded) return;
item.loaded = true;
if (url) cssCache[url] = true;
if (item.type === 'style') {
document.head.append(hm('style', {
textContent: item.data
}));
} else if (item.type === 'stylesheet') {
document.head.append(hm('link', _extends({
rel: 'stylesheet'
}, item.data)));
if (!item.loaded) {
const deferred = defer();
item.loaded = deferred.promise;
if (url)
cssCache[url] = item.loaded;
if (item.type === "style") {
document.head.append(
hm("style", {
textContent: item.data
})
);
deferred.resolve();
} else if (url) {
document.head.append(
hm("link", {
rel: "stylesheet",
...item.data
})
);
fetch(url).then((res) => {
if (res.ok)
return res.text();
throw res;
}).then(() => deferred.resolve(), deferred.reject);
}
}
await item.loaded;
}
async function loadJS(items, context) {
items.forEach(item => {
var _item$data2;
if (item.type === 'script' && (_item$data2 = item.data) != null && _item$data2.src) {
items.forEach((item) => {
var _a;
if (item.type === "script" && ((_a = item.data) == null ? void 0 : _a.src)) {
memoizedPreloadJS(item.data.src);
}
});
context = _extends({
getMarkmap: () => window.markmap
}, context);
context = {
getMarkmap: () => window.markmap,
...context
};
for (const item of items) {

@@ -477,10 +493,8 @@ await loadJSItem(item, context);

}
function loadCSS(items) {
for (const item of items) {
loadCSSItem(item);
}
async function loadCSS(items) {
await Promise.all(items.map((item) => loadCSSItem(item)));
}
function buildJSItem(path) {
return {
type: 'script',
type: "script",
data: {

@@ -493,3 +507,3 @@ src: path

return {
type: 'stylesheet',
type: "stylesheet",
data: {

@@ -500,3 +514,2 @@ href: path

}
exports.Hook = Hook;

@@ -503,0 +516,0 @@ exports.UrlBuilder = UrlBuilder;

{
"name": "markmap-common",
"version": "0.15.5",
"version": "0.15.6",
"description": "",

@@ -8,6 +8,5 @@ "author": "",

"scripts": {
"dev": "rollup -wc rollup.conf.js",
"clean": "del-cli dist types",
"clean": "del-cli dist",
"build:types": "tsc",
"build:js": "rollup -c rollup.conf.js"
"build:js": "vite build"
},

@@ -17,4 +16,3 @@ "main": "dist/index.js",

"files": [
"dist",
"types"
"dist"
],

@@ -33,9 +31,9 @@ "publishConfig": {

},
"typings": "types/index.d.ts",
"typings": "dist/index.d.ts",
"dependencies": {
"@babel/runtime": "^7.22.6",
"@gera2ld/jsx-dom": "^2.2.2",
"npm2url": "^0.2.1"
"npm2url": "^0.2.4"
},
"gitHead": "f7bda12b219cba3833dec1dae1daad14c3b53db6"
"gitHead": "7309ee74a3fed2c40a2fc37f1b5df208f25f3c3a"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc