| 707 | }); |
| 708 | } |
| 709 | function registerComponent(templateEl, componentScript) { |
| 710 | const tagName = templateEl.getAttribute("component"); |
| 711 | if (!tagName.includes("-")) { |
| 712 | console.error("component name must contain a dash: '" + tagName + "'"); |
| 713 | return; |
| 714 | } |
| 715 | var raw = templateEl.textContent; |
| 716 | var combined = ""; |
| 717 | var styleRegex = /<style[^>]*>([\s\S]*?)<\/style>/gi; |
| 718 | var match; |
| 719 | while ((match = styleRegex.exec(raw)) !== null) { |
| 720 | combined += match[1] + "\n"; |
| 721 | } |
| 722 | if (combined) { |
| 723 | raw = raw.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, ""); |
| 724 | templateEl.textContent = raw; |
| 725 | var scopedStyle = document.createElement("style"); |
| 726 | scopedStyle.setAttribute("data-hyperscript-component", tagName); |
| 727 | scopedStyle.textContent = "@scope (" + tagName + ") {\n" + combined + "}"; |
| 728 | document.head.appendChild(scopedStyle); |
| 729 | } |
| 730 | const templateSource = templateEl.textContent; |
| 731 | const ComponentClass = class extends HTMLElement { |
| 732 | connectedCallback() { |
| 733 | if (this._hypercomp_initialized) return; |
| 734 | this._hypercomp_initialized = true; |
| 735 | this.setAttribute("dom-scope", "isolated"); |
| 736 | this._slotContent = this.innerHTML; |
| 737 | this.innerHTML = ""; |
| 738 | var internalData = runtime.getInternalData(this); |
| 739 | if (!internalData.elementScope) internalData.elementScope = {}; |
| 740 | internalData.elementScope.attrs = createAttrs(this); |
| 741 | if (componentScript) { |
| 742 | this.setAttribute("_", componentScript); |
| 743 | _hyperscript.process(this); |
| 744 | } |
| 745 | const self2 = this; |
| 746 | var source = substituteSlots(templateSource, self2._slotContent, tagName); |
| 747 | queueMicrotask(function() { |
| 748 | var result = self2._renderTemplate(source); |
| 749 | if (result && result.then) { |
| 750 | result.then(function(html) { |
| 751 | self2._stampTemplate(html); |
| 752 | self2._setupReactiveEffect(source); |
| 753 | }); |
| 754 | } else { |
| 755 | self2._stampTemplate(result); |
| 756 | self2._setupReactiveEffect(source); |
| 757 | } |
| 758 | }); |
| 759 | } |
| 760 | disconnectedCallback() { |
| 761 | reactivity.stopElementEffects(this); |
| 762 | runtime.cleanup(this); |
| 763 | this._hypercomp_initialized = false; |
| 764 | this._hypercomp_stamped = false; |
| 765 | } |
| 766 | _setupReactiveEffect(source) { |