markmap-common
Advanced tools
Comparing version 0.14.5-alpha.21 to 0.14.5-alpha.22
@@ -1,4 +0,63 @@ | ||
/*! markmap-common v0.14.5-alpha.21+fb81f2c | MIT License */ | ||
/*! markmap-common v0.14.5-alpha.22+04afb38 | 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); | ||
} | ||
const testPath = "npm2url/dist/index.cjs"; | ||
const defaultProviders = { | ||
jsdelivr: path => `https://cdn.jsdelivr.net/npm/${path}`, | ||
unpkg: path => `https://unpkg.com/${path}` | ||
}; | ||
class UrlBuilder { | ||
constructor() { | ||
this.providers = _extends({}, defaultProviders); | ||
this.provider = "jsdelivr"; | ||
} | ||
getFastestProvider(path = testPath) { | ||
return Promise.any(Object.entries(this.providers).map(async ([name, factory]) => { | ||
const res = await fetch(factory(path)); | ||
if (!res.ok) { | ||
throw res; | ||
} | ||
await res.text(); | ||
return name; | ||
})); | ||
} | ||
async findFastestProvider() { | ||
this.provider = await this.getFastestProvider(); | ||
return this.provider; | ||
} | ||
setProvider(name, factory) { | ||
if (factory) { | ||
this.providers[name] = factory; | ||
} else { | ||
delete this.providers[name]; | ||
} | ||
} | ||
getFullUrl(path, provider = this.provider) { | ||
if (path.includes("://")) { | ||
return path; | ||
} | ||
const factory = this.providers[provider]; | ||
if (!factory) { | ||
throw new Error(`Provider ${provider} not found`); | ||
} | ||
return factory(path); | ||
} | ||
} | ||
const urlBuilder = new UrlBuilder(); | ||
class Hook { | ||
@@ -26,17 +85,2 @@ constructor() { | ||
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); | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
@@ -340,25 +384,2 @@ if (source == null) return {}; | ||
const testPath = "@gera2ld/jsx-dom/dist/index.js"; | ||
const providers = { | ||
jsdelivr: path => `https://cdn.jsdelivr.net/npm/${path}`, | ||
unpkg: path => `https://unpkg.com/${path}` | ||
}; | ||
function cdnUrl(provider, path) { | ||
const factory = providers[provider]; | ||
if (!factory) { | ||
throw new Error(`Provider ${provider} not found`); | ||
} | ||
return factory(path); | ||
} | ||
function getFastestProvider(path = testPath) { | ||
return Promise.any(Object.entries(providers).map(async ([name, factory]) => { | ||
const res = await fetch(factory(path)); | ||
if (!res.ok) { | ||
throw res; | ||
} | ||
await res.text(); | ||
return name; | ||
})); | ||
} | ||
const memoizedPreloadJS = memoize(url => { | ||
@@ -429,31 +450,15 @@ document.head.append(hm('link', { | ||
} | ||
let provider = 'jsdelivr'; | ||
async function findFastestProvider() { | ||
provider = await getFastestProvider(); | ||
return provider; | ||
} | ||
function setProvider(name, factory) { | ||
if (factory) { | ||
providers[name] = factory; | ||
} | ||
provider = name; | ||
return provider; | ||
} | ||
function getFullUrl(path, overrideProvider = provider) { | ||
if (path.includes('://')) return path; | ||
return cdnUrl(overrideProvider, path); | ||
} | ||
function buildJSItem(path, overrideProvider) { | ||
function buildJSItem(path) { | ||
return { | ||
type: 'script', | ||
data: { | ||
src: getFullUrl(path, overrideProvider) | ||
src: path | ||
} | ||
}; | ||
} | ||
function buildCSSItem(path, overrideProvider) { | ||
function buildCSSItem(path) { | ||
return { | ||
type: 'stylesheet', | ||
data: { | ||
href: getFullUrl(path, overrideProvider) | ||
href: path | ||
} | ||
@@ -464,2 +469,3 @@ }; | ||
exports.Hook = Hook; | ||
exports.UrlBuilder = UrlBuilder; | ||
exports.addClass = addClass; | ||
@@ -473,4 +479,2 @@ exports.buildCSSItem = buildCSSItem; | ||
exports.escapeScript = escapeScript; | ||
exports.findFastestProvider = findFastestProvider; | ||
exports.getFullUrl = getFullUrl; | ||
exports.getId = getId; | ||
@@ -485,5 +489,5 @@ exports.htmlClose = htmlClose; | ||
exports.persistJS = persistJS; | ||
exports.setProvider = setProvider; | ||
exports.urlBuilder = urlBuilder; | ||
exports.walkTree = walkTree; | ||
exports.wrapFunction = wrapFunction; | ||
exports.wrapHtml = wrapHtml; |
{ | ||
"name": "markmap-common", | ||
"version": "0.14.5-alpha.21+fb81f2c", | ||
"version": "0.14.5-alpha.22+04afb38", | ||
"description": "", | ||
@@ -35,5 +35,5 @@ "author": "", | ||
"@gera2ld/jsx-dom": "^2.2.2", | ||
"npm2url": "^0.1.1" | ||
"npm2url": "^0.2.0" | ||
}, | ||
"gitHead": "fb81f2cb688f400f17f911774539267219f639ce" | ||
"gitHead": "04afb38dd0a6f3b5e8eaffde3c29e9e38b215c35" | ||
} |
@@ -0,1 +1,2 @@ | ||
export * from 'npm2url'; | ||
export * from './hook'; | ||
@@ -2,0 +3,0 @@ export * from './html'; |
import { JSItem, JSScriptItem, CSSItem, CSSStylesheetItem } from './types'; | ||
export declare function loadJS(items: JSItem[], context?: object): Promise<void>; | ||
export declare function loadCSS(items: CSSItem[]): void; | ||
export declare function findFastestProvider(): Promise<string>; | ||
export declare function setProvider(name: string, factory?: (path: string) => string): string; | ||
export declare function getFullUrl(path: string, overrideProvider?: string): string; | ||
export declare function buildJSItem(path: string, overrideProvider?: string): JSScriptItem; | ||
export declare function buildCSSItem(path: string, overrideProvider?: string): CSSStylesheetItem; | ||
export declare function buildJSItem(path: string): JSScriptItem; | ||
export declare function buildCSSItem(path: string): CSSStylesheetItem; |
Sorry, the diff of this file is not supported yet
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
1099
32358
+ Addednpm2url@0.2.4(transitive)
- Removednpm2url@0.1.1(transitive)
Updatednpm2url@^0.2.0