@garfish/utils
Advanced tools
Comparing version 0.0.34 to 0.0.35-alpha.0
@@ -6,2 +6,2 @@ import { interfaces } from '@garfish/core'; | ||
}; | ||
export declare function getRenderNode(domGetter: interfaces.DomGetter): Element; | ||
export declare function getRenderNode(domGetter: interfaces.DomGetter): Promise<Element>; |
@@ -13,3 +13,5 @@ export interface Text { | ||
declare type Attributes = Array<Record<string, string | null>>; | ||
export declare const DOMApis: { | ||
export declare class DOMApis { | ||
document: Document; | ||
constructor(cusDocument?: Document); | ||
isText(node: Node | Text): boolean; | ||
@@ -32,3 +34,3 @@ isNode(node: Node | Text): boolean; | ||
applyAttributes(el: Element, attributes: Attributes): void; | ||
}; | ||
} | ||
export {}; |
@@ -550,12 +550,15 @@ 'use strict'; | ||
} | ||
const DOMApis = { | ||
class DOMApis { | ||
constructor(cusDocument) { | ||
this.document = cusDocument || document; | ||
} | ||
isText(node) { | ||
return node && node.type === 'text'; | ||
}, | ||
} | ||
isNode(node) { | ||
return node && node.type === 'element'; | ||
}, | ||
} | ||
isCommentNode(node) { | ||
return node && node.type === 'comment'; | ||
}, | ||
} | ||
isCssLinkNode(node) { | ||
@@ -566,3 +569,3 @@ if (this.isNode(node) && node.tagName === 'link') { | ||
return false; | ||
}, | ||
} | ||
isIconLinkNode(node) { | ||
@@ -573,3 +576,3 @@ if (this.isNode(node) && node.tagName === 'link') { | ||
return false; | ||
}, | ||
} | ||
isPrefetchJsLinkNode(node) { | ||
@@ -593,3 +596,3 @@ if (!this.isNode(node) || node.tagName !== 'link') | ||
return Boolean(hasRelAttr && hasAsAttr); | ||
}, | ||
} | ||
isRemoteModule(node) { | ||
@@ -614,3 +617,3 @@ if (!this.isNode(node) || node.tagName !== 'meta') | ||
return Boolean(hasNameAttr && hasSrcAttr); | ||
}, | ||
} | ||
removeElement(el) { | ||
@@ -621,20 +624,20 @@ const parentNode = el && el.parentNode; | ||
} | ||
}, | ||
} | ||
createElement(node) { | ||
const { tagName, attributes } = node; | ||
const el = isSVG(tagName) | ||
? document.createElementNS(ns, tagName) | ||
: document.createElement(tagName); | ||
? this.document.createElementNS(ns, tagName) | ||
: this.document.createElement(tagName); | ||
this.applyAttributes(el, attributes); | ||
return el; | ||
}, | ||
} | ||
createTextNode(node) { | ||
return document.createTextNode(node.content); | ||
}, | ||
return this.document.createTextNode(node.content); | ||
} | ||
createStyleNode(content) { | ||
const el = document.createElement('style'); | ||
const el = this.document.createElement('style'); | ||
content && (el.textContent = content); | ||
this.applyAttributes(el, [{ key: 'type', value: 'text/css' }]); | ||
return el; | ||
}, | ||
} | ||
createLinkCommentNode(node) { | ||
@@ -647,5 +650,5 @@ if (this.isNode(node)) { | ||
node = node ? `src="${node}" ` : ''; | ||
return document.createComment(`<link ${node}execute by garfish(dynamic)></link>`); | ||
return this.document.createComment(`<link ${node}execute by garfish(dynamic)></link>`); | ||
} | ||
}, | ||
} | ||
createScriptCommentNode(node) { | ||
@@ -656,3 +659,3 @@ if (this.isNode(node)) { | ||
const code = (children === null || children === void 0 ? void 0 : children[0]) ? children[0].content : ''; | ||
return document.createComment(`<script ${ps} execute by garfish>${code}</script>`); | ||
return this.document.createComment(`<script ${ps} execute by garfish>${code}</script>`); | ||
} | ||
@@ -662,5 +665,5 @@ else { | ||
const url = src ? `src="${src}" ` : ''; | ||
return document.createComment(`<script ${url}execute by garfish(dynamic)>${code}</script>`); | ||
return this.document.createComment(`<script ${url}execute by garfish(dynamic)>${code}</script>`); | ||
} | ||
}, | ||
} | ||
applyAttributes(el, attributes) { | ||
@@ -688,4 +691,4 @@ if (!attributes || attributes.length === 0) | ||
} | ||
}, | ||
}; | ||
} | ||
} | ||
@@ -772,2 +775,27 @@ const __GARFISH_FLAG__ = Symbol.for('__GARFISH_FLAG__'); | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function createAppContainer(name) { | ||
@@ -786,11 +814,17 @@ // Create a temporary node, which is destroyed by the module itself | ||
function getRenderNode(domGetter) { | ||
assert(domGetter, `Invalid domGetter:\n ${domGetter}.`); | ||
// prettier-ignore | ||
const appWrapperNode = typeof domGetter === 'string' | ||
? document.querySelector(domGetter) | ||
: typeof domGetter === 'function' | ||
? domGetter() | ||
: domGetter; | ||
assert(appWrapperNode, `Invalid domGetter: ${domGetter}`); | ||
return appWrapperNode; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
assert(domGetter, `Invalid domGetter:\n ${domGetter}.`); | ||
let appWrapperNode = domGetter; | ||
if (typeof domGetter === 'string') { | ||
appWrapperNode = document.querySelector(domGetter); | ||
} | ||
else if (typeof domGetter === 'function') { | ||
appWrapperNode = yield domGetter(); | ||
} | ||
else if (typeof domGetter === 'object') { | ||
appWrapperNode = domGetter; | ||
} | ||
assert(appWrapperNode, `Invalid domGetter: ${domGetter}`); | ||
return appWrapperNode; | ||
}); | ||
} | ||
@@ -797,0 +831,0 @@ |
@@ -542,12 +542,15 @@ 'use strict'; | ||
} | ||
const DOMApis = { | ||
class DOMApis { | ||
constructor(cusDocument) { | ||
this.document = cusDocument || document; | ||
} | ||
isText(node) { | ||
return node && node.type === 'text'; | ||
}, | ||
} | ||
isNode(node) { | ||
return node && node.type === 'element'; | ||
}, | ||
} | ||
isCommentNode(node) { | ||
return node && node.type === 'comment'; | ||
}, | ||
} | ||
isCssLinkNode(node) { | ||
@@ -558,3 +561,3 @@ if (this.isNode(node) && node.tagName === 'link') { | ||
return false; | ||
}, | ||
} | ||
isIconLinkNode(node) { | ||
@@ -565,3 +568,3 @@ if (this.isNode(node) && node.tagName === 'link') { | ||
return false; | ||
}, | ||
} | ||
isPrefetchJsLinkNode(node) { | ||
@@ -585,3 +588,3 @@ if (!this.isNode(node) || node.tagName !== 'link') | ||
return Boolean(hasRelAttr && hasAsAttr); | ||
}, | ||
} | ||
isRemoteModule(node) { | ||
@@ -606,3 +609,3 @@ if (!this.isNode(node) || node.tagName !== 'meta') | ||
return Boolean(hasNameAttr && hasSrcAttr); | ||
}, | ||
} | ||
removeElement(el) { | ||
@@ -613,20 +616,20 @@ const parentNode = el && el.parentNode; | ||
} | ||
}, | ||
} | ||
createElement(node) { | ||
const { tagName, attributes } = node; | ||
const el = isSVG(tagName) | ||
? document.createElementNS(ns, tagName) | ||
: document.createElement(tagName); | ||
? this.document.createElementNS(ns, tagName) | ||
: this.document.createElement(tagName); | ||
this.applyAttributes(el, attributes); | ||
return el; | ||
}, | ||
} | ||
createTextNode(node) { | ||
return document.createTextNode(node.content); | ||
}, | ||
return this.document.createTextNode(node.content); | ||
} | ||
createStyleNode(content) { | ||
const el = document.createElement('style'); | ||
const el = this.document.createElement('style'); | ||
content && (el.textContent = content); | ||
this.applyAttributes(el, [{ key: 'type', value: 'text/css' }]); | ||
return el; | ||
}, | ||
} | ||
createLinkCommentNode(node) { | ||
@@ -639,5 +642,5 @@ if (this.isNode(node)) { | ||
node = node ? `src="${node}" ` : ''; | ||
return document.createComment(`<link ${node}execute by garfish(dynamic)></link>`); | ||
return this.document.createComment(`<link ${node}execute by garfish(dynamic)></link>`); | ||
} | ||
}, | ||
} | ||
createScriptCommentNode(node) { | ||
@@ -648,3 +651,3 @@ if (this.isNode(node)) { | ||
const code = (children === null || children === void 0 ? void 0 : children[0]) ? children[0].content : ''; | ||
return document.createComment(`<script ${ps} execute by garfish>${code}</script>`); | ||
return this.document.createComment(`<script ${ps} execute by garfish>${code}</script>`); | ||
} | ||
@@ -654,5 +657,5 @@ else { | ||
const url = src ? `src="${src}" ` : ''; | ||
return document.createComment(`<script ${url}execute by garfish(dynamic)>${code}</script>`); | ||
return this.document.createComment(`<script ${url}execute by garfish(dynamic)>${code}</script>`); | ||
} | ||
}, | ||
} | ||
applyAttributes(el, attributes) { | ||
@@ -680,4 +683,4 @@ if (!attributes || attributes.length === 0) | ||
} | ||
}, | ||
}; | ||
} | ||
} | ||
@@ -764,2 +767,27 @@ const __GARFISH_FLAG__ = Symbol.for('__GARFISH_FLAG__'); | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function createAppContainer(name) { | ||
@@ -778,11 +806,17 @@ // Create a temporary node, which is destroyed by the module itself | ||
function getRenderNode(domGetter) { | ||
assert(domGetter, `Invalid domGetter:\n ${domGetter}.`); | ||
// prettier-ignore | ||
const appWrapperNode = typeof domGetter === 'string' | ||
? document.querySelector(domGetter) | ||
: typeof domGetter === 'function' | ||
? domGetter() | ||
: domGetter; | ||
assert(appWrapperNode, `Invalid domGetter: ${domGetter}`); | ||
return appWrapperNode; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
assert(domGetter, `Invalid domGetter:\n ${domGetter}.`); | ||
let appWrapperNode = domGetter; | ||
if (typeof domGetter === 'string') { | ||
appWrapperNode = document.querySelector(domGetter); | ||
} | ||
else if (typeof domGetter === 'function') { | ||
appWrapperNode = yield domGetter(); | ||
} | ||
else if (typeof domGetter === 'object') { | ||
appWrapperNode = domGetter; | ||
} | ||
assert(appWrapperNode, `Invalid domGetter: ${domGetter}`); | ||
return appWrapperNode; | ||
}); | ||
} | ||
@@ -789,0 +823,0 @@ |
@@ -546,12 +546,15 @@ const objectToString = Object.prototype.toString; | ||
} | ||
const DOMApis = { | ||
class DOMApis { | ||
constructor(cusDocument) { | ||
this.document = cusDocument || document; | ||
} | ||
isText(node) { | ||
return node && node.type === 'text'; | ||
}, | ||
} | ||
isNode(node) { | ||
return node && node.type === 'element'; | ||
}, | ||
} | ||
isCommentNode(node) { | ||
return node && node.type === 'comment'; | ||
}, | ||
} | ||
isCssLinkNode(node) { | ||
@@ -562,3 +565,3 @@ if (this.isNode(node) && node.tagName === 'link') { | ||
return false; | ||
}, | ||
} | ||
isIconLinkNode(node) { | ||
@@ -569,3 +572,3 @@ if (this.isNode(node) && node.tagName === 'link') { | ||
return false; | ||
}, | ||
} | ||
isPrefetchJsLinkNode(node) { | ||
@@ -589,3 +592,3 @@ if (!this.isNode(node) || node.tagName !== 'link') | ||
return Boolean(hasRelAttr && hasAsAttr); | ||
}, | ||
} | ||
isRemoteModule(node) { | ||
@@ -610,3 +613,3 @@ if (!this.isNode(node) || node.tagName !== 'meta') | ||
return Boolean(hasNameAttr && hasSrcAttr); | ||
}, | ||
} | ||
removeElement(el) { | ||
@@ -617,20 +620,20 @@ const parentNode = el && el.parentNode; | ||
} | ||
}, | ||
} | ||
createElement(node) { | ||
const { tagName, attributes } = node; | ||
const el = isSVG(tagName) | ||
? document.createElementNS(ns, tagName) | ||
: document.createElement(tagName); | ||
? this.document.createElementNS(ns, tagName) | ||
: this.document.createElement(tagName); | ||
this.applyAttributes(el, attributes); | ||
return el; | ||
}, | ||
} | ||
createTextNode(node) { | ||
return document.createTextNode(node.content); | ||
}, | ||
return this.document.createTextNode(node.content); | ||
} | ||
createStyleNode(content) { | ||
const el = document.createElement('style'); | ||
const el = this.document.createElement('style'); | ||
content && (el.textContent = content); | ||
this.applyAttributes(el, [{ key: 'type', value: 'text/css' }]); | ||
return el; | ||
}, | ||
} | ||
createLinkCommentNode(node) { | ||
@@ -643,5 +646,5 @@ if (this.isNode(node)) { | ||
node = node ? `src="${node}" ` : ''; | ||
return document.createComment(`<link ${node}execute by garfish(dynamic)></link>`); | ||
return this.document.createComment(`<link ${node}execute by garfish(dynamic)></link>`); | ||
} | ||
}, | ||
} | ||
createScriptCommentNode(node) { | ||
@@ -652,3 +655,3 @@ if (this.isNode(node)) { | ||
const code = (children === null || children === void 0 ? void 0 : children[0]) ? children[0].content : ''; | ||
return document.createComment(`<script ${ps} execute by garfish>${code}</script>`); | ||
return this.document.createComment(`<script ${ps} execute by garfish>${code}</script>`); | ||
} | ||
@@ -658,5 +661,5 @@ else { | ||
const url = src ? `src="${src}" ` : ''; | ||
return document.createComment(`<script ${url}execute by garfish(dynamic)>${code}</script>`); | ||
return this.document.createComment(`<script ${url}execute by garfish(dynamic)>${code}</script>`); | ||
} | ||
}, | ||
} | ||
applyAttributes(el, attributes) { | ||
@@ -684,4 +687,4 @@ if (!attributes || attributes.length === 0) | ||
} | ||
}, | ||
}; | ||
} | ||
} | ||
@@ -768,2 +771,27 @@ const __GARFISH_FLAG__ = Symbol.for('__GARFISH_FLAG__'); | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function createAppContainer(name) { | ||
@@ -782,13 +810,19 @@ // Create a temporary node, which is destroyed by the module itself | ||
function getRenderNode(domGetter) { | ||
assert(domGetter, `Invalid domGetter:\n ${domGetter}.`); | ||
// prettier-ignore | ||
const appWrapperNode = typeof domGetter === 'string' | ||
? document.querySelector(domGetter) | ||
: typeof domGetter === 'function' | ||
? domGetter() | ||
: domGetter; | ||
assert(appWrapperNode, `Invalid domGetter: ${domGetter}`); | ||
return appWrapperNode; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
assert(domGetter, `Invalid domGetter:\n ${domGetter}.`); | ||
let appWrapperNode = domGetter; | ||
if (typeof domGetter === 'string') { | ||
appWrapperNode = document.querySelector(domGetter); | ||
} | ||
else if (typeof domGetter === 'function') { | ||
appWrapperNode = yield domGetter(); | ||
} | ||
else if (typeof domGetter === 'object') { | ||
appWrapperNode = domGetter; | ||
} | ||
assert(appWrapperNode, `Invalid domGetter: ${domGetter}`); | ||
return appWrapperNode; | ||
}); | ||
} | ||
export { DOMApis, __GARFISH_FLAG__, __extends, assert, callTestCallback, computeErrorUrl, computeStackTraceFromStackProp, createAppContainer, createKey, deepMerge, def, error, evalWithEnv, filterAndWrapEventListener, findTarget, getRenderNode, hasOwn, inBrowser, internFunc, isAbsolute, isCss, isHtml, isJs, isObject, isPlainObject, isPrimitive, isPromise, makeMap, nextTick, noop, objectToString, parseContentType, remove, setDocCurrentScript, sourceListTags, sourceNode, toBoolean, transformUrl, unique, validURL, warn }; |
@@ -546,12 +546,15 @@ const objectToString = Object.prototype.toString; | ||
} | ||
const DOMApis = { | ||
class DOMApis { | ||
constructor(cusDocument) { | ||
this.document = cusDocument || document; | ||
} | ||
isText(node) { | ||
return node && node.type === 'text'; | ||
}, | ||
} | ||
isNode(node) { | ||
return node && node.type === 'element'; | ||
}, | ||
} | ||
isCommentNode(node) { | ||
return node && node.type === 'comment'; | ||
}, | ||
} | ||
isCssLinkNode(node) { | ||
@@ -562,3 +565,3 @@ if (this.isNode(node) && node.tagName === 'link') { | ||
return false; | ||
}, | ||
} | ||
isIconLinkNode(node) { | ||
@@ -569,3 +572,3 @@ if (this.isNode(node) && node.tagName === 'link') { | ||
return false; | ||
}, | ||
} | ||
isPrefetchJsLinkNode(node) { | ||
@@ -589,3 +592,3 @@ if (!this.isNode(node) || node.tagName !== 'link') | ||
return Boolean(hasRelAttr && hasAsAttr); | ||
}, | ||
} | ||
isRemoteModule(node) { | ||
@@ -610,3 +613,3 @@ if (!this.isNode(node) || node.tagName !== 'meta') | ||
return Boolean(hasNameAttr && hasSrcAttr); | ||
}, | ||
} | ||
removeElement(el) { | ||
@@ -617,20 +620,20 @@ const parentNode = el && el.parentNode; | ||
} | ||
}, | ||
} | ||
createElement(node) { | ||
const { tagName, attributes } = node; | ||
const el = isSVG(tagName) | ||
? document.createElementNS(ns, tagName) | ||
: document.createElement(tagName); | ||
? this.document.createElementNS(ns, tagName) | ||
: this.document.createElement(tagName); | ||
this.applyAttributes(el, attributes); | ||
return el; | ||
}, | ||
} | ||
createTextNode(node) { | ||
return document.createTextNode(node.content); | ||
}, | ||
return this.document.createTextNode(node.content); | ||
} | ||
createStyleNode(content) { | ||
const el = document.createElement('style'); | ||
const el = this.document.createElement('style'); | ||
content && (el.textContent = content); | ||
this.applyAttributes(el, [{ key: 'type', value: 'text/css' }]); | ||
return el; | ||
}, | ||
} | ||
createLinkCommentNode(node) { | ||
@@ -643,5 +646,5 @@ if (this.isNode(node)) { | ||
node = node ? `src="${node}" ` : ''; | ||
return document.createComment(`<link ${node}execute by garfish(dynamic)></link>`); | ||
return this.document.createComment(`<link ${node}execute by garfish(dynamic)></link>`); | ||
} | ||
}, | ||
} | ||
createScriptCommentNode(node) { | ||
@@ -652,3 +655,3 @@ if (this.isNode(node)) { | ||
const code = (children === null || children === void 0 ? void 0 : children[0]) ? children[0].content : ''; | ||
return document.createComment(`<script ${ps} execute by garfish>${code}</script>`); | ||
return this.document.createComment(`<script ${ps} execute by garfish>${code}</script>`); | ||
} | ||
@@ -658,5 +661,5 @@ else { | ||
const url = src ? `src="${src}" ` : ''; | ||
return document.createComment(`<script ${url}execute by garfish(dynamic)>${code}</script>`); | ||
return this.document.createComment(`<script ${url}execute by garfish(dynamic)>${code}</script>`); | ||
} | ||
}, | ||
} | ||
applyAttributes(el, attributes) { | ||
@@ -684,4 +687,4 @@ if (!attributes || attributes.length === 0) | ||
} | ||
}, | ||
}; | ||
} | ||
} | ||
@@ -768,2 +771,27 @@ const __GARFISH_FLAG__ = Symbol.for('__GARFISH_FLAG__'); | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function createAppContainer(name) { | ||
@@ -782,13 +810,19 @@ // Create a temporary node, which is destroyed by the module itself | ||
function getRenderNode(domGetter) { | ||
assert(domGetter, `Invalid domGetter:\n ${domGetter}.`); | ||
// prettier-ignore | ||
const appWrapperNode = typeof domGetter === 'string' | ||
? document.querySelector(domGetter) | ||
: typeof domGetter === 'function' | ||
? domGetter() | ||
: domGetter; | ||
assert(appWrapperNode, `Invalid domGetter: ${domGetter}`); | ||
return appWrapperNode; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
assert(domGetter, `Invalid domGetter:\n ${domGetter}.`); | ||
let appWrapperNode = domGetter; | ||
if (typeof domGetter === 'string') { | ||
appWrapperNode = document.querySelector(domGetter); | ||
} | ||
else if (typeof domGetter === 'function') { | ||
appWrapperNode = yield domGetter(); | ||
} | ||
else if (typeof domGetter === 'object') { | ||
appWrapperNode = domGetter; | ||
} | ||
assert(appWrapperNode, `Invalid domGetter: ${domGetter}`); | ||
return appWrapperNode; | ||
}); | ||
} | ||
export { DOMApis, __GARFISH_FLAG__, __extends, assert, callTestCallback, computeErrorUrl, computeStackTraceFromStackProp, createAppContainer, createKey, deepMerge, def, error, evalWithEnv, filterAndWrapEventListener, findTarget, getRenderNode, hasOwn, inBrowser, internFunc, isAbsolute, isCss, isHtml, isJs, isObject, isPlainObject, isPrimitive, isPromise, makeMap, nextTick, noop, objectToString, parseContentType, remove, setDocCurrentScript, sourceListTags, sourceNode, toBoolean, transformUrl, unique, validURL, warn }; |
@@ -552,12 +552,15 @@ (function (global, factory) { | ||
} | ||
const DOMApis = { | ||
class DOMApis { | ||
constructor(cusDocument) { | ||
this.document = cusDocument || document; | ||
} | ||
isText(node) { | ||
return node && node.type === 'text'; | ||
}, | ||
} | ||
isNode(node) { | ||
return node && node.type === 'element'; | ||
}, | ||
} | ||
isCommentNode(node) { | ||
return node && node.type === 'comment'; | ||
}, | ||
} | ||
isCssLinkNode(node) { | ||
@@ -568,3 +571,3 @@ if (this.isNode(node) && node.tagName === 'link') { | ||
return false; | ||
}, | ||
} | ||
isIconLinkNode(node) { | ||
@@ -575,3 +578,3 @@ if (this.isNode(node) && node.tagName === 'link') { | ||
return false; | ||
}, | ||
} | ||
isPrefetchJsLinkNode(node) { | ||
@@ -595,3 +598,3 @@ if (!this.isNode(node) || node.tagName !== 'link') | ||
return Boolean(hasRelAttr && hasAsAttr); | ||
}, | ||
} | ||
isRemoteModule(node) { | ||
@@ -616,3 +619,3 @@ if (!this.isNode(node) || node.tagName !== 'meta') | ||
return Boolean(hasNameAttr && hasSrcAttr); | ||
}, | ||
} | ||
removeElement(el) { | ||
@@ -623,20 +626,20 @@ const parentNode = el && el.parentNode; | ||
} | ||
}, | ||
} | ||
createElement(node) { | ||
const { tagName, attributes } = node; | ||
const el = isSVG(tagName) | ||
? document.createElementNS(ns, tagName) | ||
: document.createElement(tagName); | ||
? this.document.createElementNS(ns, tagName) | ||
: this.document.createElement(tagName); | ||
this.applyAttributes(el, attributes); | ||
return el; | ||
}, | ||
} | ||
createTextNode(node) { | ||
return document.createTextNode(node.content); | ||
}, | ||
return this.document.createTextNode(node.content); | ||
} | ||
createStyleNode(content) { | ||
const el = document.createElement('style'); | ||
const el = this.document.createElement('style'); | ||
content && (el.textContent = content); | ||
this.applyAttributes(el, [{ key: 'type', value: 'text/css' }]); | ||
return el; | ||
}, | ||
} | ||
createLinkCommentNode(node) { | ||
@@ -649,5 +652,5 @@ if (this.isNode(node)) { | ||
node = node ? `src="${node}" ` : ''; | ||
return document.createComment(`<link ${node}execute by garfish(dynamic)></link>`); | ||
return this.document.createComment(`<link ${node}execute by garfish(dynamic)></link>`); | ||
} | ||
}, | ||
} | ||
createScriptCommentNode(node) { | ||
@@ -658,3 +661,3 @@ if (this.isNode(node)) { | ||
const code = (children === null || children === void 0 ? void 0 : children[0]) ? children[0].content : ''; | ||
return document.createComment(`<script ${ps} execute by garfish>${code}</script>`); | ||
return this.document.createComment(`<script ${ps} execute by garfish>${code}</script>`); | ||
} | ||
@@ -664,5 +667,5 @@ else { | ||
const url = src ? `src="${src}" ` : ''; | ||
return document.createComment(`<script ${url}execute by garfish(dynamic)>${code}</script>`); | ||
return this.document.createComment(`<script ${url}execute by garfish(dynamic)>${code}</script>`); | ||
} | ||
}, | ||
} | ||
applyAttributes(el, attributes) { | ||
@@ -690,4 +693,4 @@ if (!attributes || attributes.length === 0) | ||
} | ||
}, | ||
}; | ||
} | ||
} | ||
@@ -774,2 +777,27 @@ const __GARFISH_FLAG__ = Symbol.for('__GARFISH_FLAG__'); | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function createAppContainer(name) { | ||
@@ -788,11 +816,17 @@ // Create a temporary node, which is destroyed by the module itself | ||
function getRenderNode(domGetter) { | ||
assert(domGetter, `Invalid domGetter:\n ${domGetter}.`); | ||
// prettier-ignore | ||
const appWrapperNode = typeof domGetter === 'string' | ||
? document.querySelector(domGetter) | ||
: typeof domGetter === 'function' | ||
? domGetter() | ||
: domGetter; | ||
assert(appWrapperNode, `Invalid domGetter: ${domGetter}`); | ||
return appWrapperNode; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
assert(domGetter, `Invalid domGetter:\n ${domGetter}.`); | ||
let appWrapperNode = domGetter; | ||
if (typeof domGetter === 'string') { | ||
appWrapperNode = document.querySelector(domGetter); | ||
} | ||
else if (typeof domGetter === 'function') { | ||
appWrapperNode = yield domGetter(); | ||
} | ||
else if (typeof domGetter === 'object') { | ||
appWrapperNode = domGetter; | ||
} | ||
assert(appWrapperNode, `Invalid domGetter: ${domGetter}`); | ||
return appWrapperNode; | ||
}); | ||
} | ||
@@ -799,0 +833,0 @@ |
{ | ||
"name": "@garfish/utils", | ||
"version": "0.0.34", | ||
"version": "0.0.35-alpha.0+55e876c", | ||
"description": "utils module.", | ||
@@ -40,3 +40,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "0d29716a21dd8fda627d7cea4c45060edd46b0f9" | ||
"gitHead": "55e876c5c3b278ebd37a91c8580ce83d2ef2bad2" | ||
} |
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
217302
4791
19
1