(_hyperscript)
| 621 | |
| 622 | // src/ext/component.js |
| 623 | function componentPlugin(_hyperscript) { |
| 624 | const { runtime, createParser, reactivity } = _hyperscript.internals; |
| 625 | const tokenizer = new Tokenizer(); |
| 626 | function ensureFouceGuard() { |
| 627 | if (typeof document === "undefined" || !document.head) return; |
| 628 | if (document.head.querySelector('style[data-hyperscript-component="fouce-guard"]')) return; |
| 629 | var styleEl = document.createElement("style"); |
| 630 | styleEl.setAttribute("data-hyperscript-component", "fouce-guard"); |
| 631 | styleEl.textContent = ":not(:defined) { visibility: hidden; }"; |
| 632 | document.head.appendChild(styleEl); |
| 633 | } |
| 634 | function substituteSlots(templateSource, slotContent, scopeSel) { |
| 635 | if (!slotContent) return templateSource; |
| 636 | var tmp = document.createElement("div"); |
| 637 | tmp.innerHTML = slotContent; |
| 638 | var named = {}; |
| 639 | var defaultParts = []; |
| 640 | for (var child of Array.from(tmp.childNodes)) { |
| 641 | if (child.nodeType === 1 && scopeSel && !child.hasAttribute("dom-scope")) { |
| 642 | child.setAttribute("dom-scope", "parent of " + scopeSel); |
| 643 | } |
| 644 | var slotName = child.nodeType === 1 && child.getAttribute("slot"); |
| 645 | if (slotName) { |
| 646 | child.removeAttribute("slot"); |
| 647 | if (!named[slotName]) named[slotName] = ""; |
| 648 | named[slotName] += child.outerHTML; |
| 649 | } else { |
| 650 | defaultParts.push(child.nodeType === 1 ? child.outerHTML : child.nodeType === 3 ? child.textContent : ""); |
| 651 | } |
| 652 | } |
| 653 | var defaultContent = defaultParts.join(""); |
| 654 | var source = templateSource.replace( |
| 655 | /<slot\s+name\s*=\s*["']([^"']+)["']\s*\/?\s*>(\s*<\/slot>)?/g, |
| 656 | function(_, name) { |
| 657 | return named[name] || ""; |
| 658 | } |
| 659 | ); |
| 660 | source = source.replace(/<slot\s*\/?\s*>(\s*<\/slot>)?/g, defaultContent); |
| 661 | return source; |
| 662 | } |
| 663 | function parseArg(componentEl, prop) { |
| 664 | if (typeof prop !== "string") return null; |
| 665 | var cache = componentEl._attrsCache || (componentEl._attrsCache = {}); |
| 666 | if (!cache[prop]) { |
| 667 | var attrValue = componentEl.getAttribute(prop); |
| 668 | if (attrValue == null) return null; |
| 669 | try { |
| 670 | cache[prop] = createParser(tokenizer.tokenize(attrValue)).requireElement("expression"); |
| 671 | } catch (e) { |
| 672 | console.error("component: failed to parse attrs." + prop + ":", e.message); |
| 673 | return null; |
| 674 | } |
| 675 | } |
| 676 | return cache[prop]; |
| 677 | } |
| 678 | function parentContext(componentEl) { |
| 679 | var parent = componentEl.parentElement; |
| 680 | return parent ? runtime.makeContext(parent, null, parent, null) : null; |
nothing calls this directly
no test coverage detected