MCPcopy
hub / github.com/sveltejs/svelte / from_html

Function from_html

packages/svelte/src/internal/client/dom/template.js:53–92  ·  view source on GitHub ↗
(content, flags)

Source from the content-addressed store, hash-verified

51 */
52/*#__NO_SIDE_EFFECTS__*/
53export function from_html(content, flags) {
54 var is_fragment = (flags & TEMPLATE_FRAGMENT) !== 0;
55 var use_import_node = (flags & TEMPLATE_USE_IMPORT_NODE) !== 0;
56
57 /** @type {Node} */
58 var node;
59
60 /**
61 * Whether or not the first item is a text/element node. If not, we need to
62 * create an additional comment node to act as `effect.nodes.start`
63 */
64 var has_start = !content.startsWith('<!>');
65
66 return () => {
67 if (hydrating) {
68 assign_nodes(hydrate_node, null);
69 return hydrate_node;
70 }
71
72 if (node === undefined) {
73 node = create_fragment_from_html(has_start ? content : '<!>' + content);
74 if (!is_fragment) node = /** @type {TemplateNode} */ (get_first_child(node));
75 }
76
77 var clone = /** @type {TemplateNode} */ (
78 use_import_node || is_firefox ? document.importNode(node, true) : node.cloneNode(true)
79 );
80
81 if (is_fragment) {
82 var start = /** @type {TemplateNode} */ (get_first_child(clone));
83 var end = /** @type {TemplateNode} */ (clone.lastChild);
84
85 assign_nodes(start, end);
86 } else {
87 assign_nodes(clone, clone);
88 }
89
90 return clone;
91 };
92}
93
94/**
95 * @param {string} content

Callers

nothing calls this directly

Calls 3

get_first_childFunction · 0.90
assign_nodesFunction · 0.85

Tested by

no test coverage detected