| 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 = {}); |