(elt, target)
| 819 | } |
| 820 | |
| 821 | #initElement(elt, target) { |
| 822 | if (elt.closest && elt.closest(config.disableSelector)) { |
| 823 | return; |
| 824 | } |
| 825 | var internalData = this.getInternalData(elt); |
| 826 | var src = this.#getScript(elt); |
| 827 | if (!src) return; |
| 828 | var hash = this.#hashScript(src); |
| 829 | if (internalData.initialized) { |
| 830 | if (internalData.scriptHash === hash) { |
| 831 | this.#resolveTemplateScopes(elt); |
| 832 | return; |
| 833 | } |
| 834 | // Script changed (e.g. morph swap) - clean up and reinitialize |
| 835 | this.cleanup(elt); |
| 836 | internalData = this.getInternalData(elt); |
| 837 | } |
| 838 | |
| 839 | if (!this.triggerEvent(elt, "hyperscript:before:init")) return; |
| 840 | |
| 841 | internalData.initialized = true; |
| 842 | internalData.scriptHash = hash; |
| 843 | try { |
| 844 | var tokens = this.#tokenizer.tokenize(src); |
| 845 | var hyperScript = this.#kernel.parseHyperScript(tokens); |
| 846 | if (!hyperScript) return; |
| 847 | |
| 848 | if (hyperScript.errors?.length) { |
| 849 | this.triggerEvent(elt, "hyperscript:parse-error", { |
| 850 | errors: hyperScript.errors, |
| 851 | }); |
| 852 | console.error( |
| 853 | "hyperscript: " + hyperScript.errors.length + " parse error(s) on:", |
| 854 | elt, |
| 855 | "\n\n" + Parser.formatErrors(hyperScript.errors) |
| 856 | ); |
| 857 | return; |
| 858 | } |
| 859 | |
| 860 | this.#resolveTemplateScopes(elt); |
| 861 | hyperScript.apply(target || elt, elt, null, this); |
| 862 | elt.setAttribute('data-hyperscript-powered', 'true'); |
| 863 | this.triggerEvent(elt, "hyperscript:after:init"); |
| 864 | setTimeout(() => { |
| 865 | this.triggerEvent(target || elt, "load", { |
| 866 | hyperscript: true, |
| 867 | }); |
| 868 | }, 1); |
| 869 | } catch (e) { |
| 870 | this.triggerEvent(elt, "exception", { |
| 871 | error: e, |
| 872 | }); |
| 873 | console.error( |
| 874 | "hyperscript errors were found on the following element:", |
| 875 | elt, |
| 876 | "\n\n", |
| 877 | e.message, |
| 878 | e.stack |
no test coverage detected