MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / componentPlugin

Function componentPlugin

www/js/_hyperscript-max.js:11034–11278  ·  view source on GitHub ↗
(_hyperscript2)

Source from the content-addressed store, hash-verified

11032
11033 // src/ext/component.js
11034 function componentPlugin(_hyperscript2) {
11035 const { runtime: runtime2, createParser, reactivity: reactivity2 } = _hyperscript2.internals;
11036 const tokenizer2 = new Tokenizer();
11037 function ensureFouceGuard() {
11038 if (typeof document === "undefined" || !document.head) return;
11039 if (document.head.querySelector('style[data-hyperscript-component="fouce-guard"]')) return;
11040 var styleEl = document.createElement("style");
11041 styleEl.setAttribute("data-hyperscript-component", "fouce-guard");
11042 styleEl.textContent = ":not(:defined) { visibility: hidden; }";
11043 document.head.appendChild(styleEl);
11044 }
11045 function substituteSlots(templateSource, slotContent, scopeSel) {
11046 if (!slotContent) return templateSource;
11047 var tmp = document.createElement("div");
11048 tmp.innerHTML = slotContent;
11049 var named = {};
11050 var defaultParts = [];
11051 for (var child of Array.from(tmp.childNodes)) {
11052 if (child.nodeType === 1 && scopeSel && !child.hasAttribute("dom-scope")) {
11053 child.setAttribute("dom-scope", "parent of " + scopeSel);
11054 }
11055 var slotName = child.nodeType === 1 && child.getAttribute("slot");
11056 if (slotName) {
11057 child.removeAttribute("slot");
11058 if (!named[slotName]) named[slotName] = "";
11059 named[slotName] += child.outerHTML;
11060 } else {
11061 defaultParts.push(child.nodeType === 1 ? child.outerHTML : child.nodeType === 3 ? child.textContent : "");
11062 }
11063 }
11064 var defaultContent = defaultParts.join("");
11065 var source = templateSource.replace(
11066 /<slot\s+name\s*=\s*["']([^"']+)["']\s*\/?\s*>(\s*<\/slot>)?/g,
11067 function(_, name) {
11068 return named[name] || "";
11069 }
11070 );
11071 source = source.replace(/<slot\s*\/?\s*>(\s*<\/slot>)?/g, defaultContent);
11072 return source;
11073 }
11074 function parseArg(componentEl, prop) {
11075 if (typeof prop !== "string") return null;
11076 var cache = componentEl._attrsCache || (componentEl._attrsCache = {});
11077 if (!cache[prop]) {
11078 var attrValue = componentEl.getAttribute(prop);
11079 if (attrValue == null) return null;
11080 try {
11081 cache[prop] = createParser(tokenizer2.tokenize(attrValue)).requireElement("expression");
11082 } catch (e) {
11083 console.error("component: failed to parse attrs." + prop + ":", e.message);
11084 return null;
11085 }
11086 }
11087 return cache[prop];
11088 }
11089 function parentContext(componentEl) {
11090 var parent = componentEl.parentElement;
11091 return parent ? runtime2.makeContext(parent, null, parent, null) : null;

Callers

nothing calls this directly

Calls 6

ensureFouceGuardFunction · 0.70
registerTemplateFunction · 0.70
loadComponentBundleFunction · 0.70
addBeforeProcessHookMethod · 0.45
forEachMethod · 0.45
addAfterProcessHookMethod · 0.45

Tested by

no test coverage detected