|
import { contenteditable_truthy_values, has_prop } from './utils.js'; |
|
|
|
import { ResizeObserverSingleton } from './ResizeObserverSingleton.js'; |
|
|
|
|
|
|
|
let is_hydrating = false; |
|
|
|
|
|
|
|
|
|
export function start_hydrating() { |
|
is_hydrating = true; |
|
} |
|
|
|
|
|
|
|
|
|
export function end_hydrating() { |
|
is_hydrating = false; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function upper_bound(low, high, key, value) { |
|
|
|
while (low < high) { |
|
const mid = low + ((high - low) >> 1); |
|
if (key(mid) <= value) { |
|
low = mid + 1; |
|
} else { |
|
high = mid; |
|
} |
|
} |
|
return low; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
function init_hydrate(target) { |
|
if (target.hydrate_init) return; |
|
target.hydrate_init = true; |
|
|
|
|
|
let children = (target.childNodes); |
|
|
|
if (target.nodeName === 'HEAD') { |
|
const my_children = []; |
|
for (let i = 0; i < children.length; i++) { |
|
const node = children[i]; |
|
if (node.claim_order !== undefined) { |
|
my_children.push(node); |
|
} |
|
} |
|
children = my_children; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const m = new Int32Array(children.length + 1); |
|
|
|
const p = new Int32Array(children.length); |
|
m[0] = -1; |
|
let longest = 0; |
|
for (let i = 0; i < children.length; i++) { |
|
const current = children[i].claim_order; |
|
|
|
|
|
|
|
const seq_len = |
|
(longest > 0 && children[m[longest]].claim_order <= current |
|
? longest + 1 |
|
: upper_bound(1, longest, (idx) => children[m[idx]].claim_order, current)) - 1; |
|
p[i] = m[seq_len] + 1; |
|
const new_len = seq_len + 1; |
|
|
|
m[new_len] = i; |
|
longest = Math.max(new_len, longest); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
const lis = []; |
|
|
|
|
|
|
|
|
|
|
|
const to_move = []; |
|
let last = children.length - 1; |
|
for (let cur = m[longest] + 1; cur != 0; cur = p[cur - 1]) { |
|
lis.push(children[cur - 1]); |
|
for (; last >= cur; last--) { |
|
to_move.push(children[last]); |
|
} |
|
last--; |
|
} |
|
for (; last >= 0; last--) { |
|
to_move.push(children[last]); |
|
} |
|
lis.reverse(); |
|
|
|
to_move.sort((a, b) => a.claim_order - b.claim_order); |
|
|
|
for (let i = 0, j = 0; i < to_move.length; i++) { |
|
while (j < lis.length && to_move[i].claim_order >= lis[j].claim_order) { |
|
j++; |
|
} |
|
const anchor = j < lis.length ? lis[j] : null; |
|
target.insertBefore(to_move[i], anchor); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
export function append(target, node) { |
|
target.appendChild(node); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function append_styles(target, style_sheet_id, styles) { |
|
const append_styles_to = get_root_for_style(target); |
|
if (!append_styles_to.getElementById(style_sheet_id)) { |
|
const style = element('style'); |
|
style.id = style_sheet_id; |
|
style.textContent = styles; |
|
append_stylesheet(append_styles_to, style); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function get_root_for_style(node) { |
|
if (!node) return document; |
|
const root = node.getRootNode ? node.getRootNode() : node.ownerDocument; |
|
if (root && (root).host) { |
|
return (root); |
|
} |
|
return node.ownerDocument; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function append_empty_stylesheet(node) { |
|
const style_element = element('style'); |
|
|
|
|
|
|
|
|
|
|
|
style_element.textContent = '/* empty */'; |
|
append_stylesheet(get_root_for_style(node), style_element); |
|
return style_element.sheet; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
function append_stylesheet(node, style) { |
|
append( (node).head || node, style); |
|
return style.sheet; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
export function append_hydration(target, node) { |
|
if (is_hydrating) { |
|
init_hydrate(target); |
|
if ( |
|
target.actual_end_child === undefined || |
|
(target.actual_end_child !== null && target.actual_end_child.parentNode !== target) |
|
) { |
|
target.actual_end_child = target.firstChild; |
|
} |
|
|
|
while (target.actual_end_child !== null && target.actual_end_child.claim_order === undefined) { |
|
target.actual_end_child = target.actual_end_child.nextSibling; |
|
} |
|
if (node !== target.actual_end_child) { |
|
|
|
if (node.claim_order !== undefined || node.parentNode !== target) { |
|
target.insertBefore(node, target.actual_end_child); |
|
} |
|
} else { |
|
target.actual_end_child = node.nextSibling; |
|
} |
|
} else if (node.parentNode !== target || node.nextSibling !== null) { |
|
target.appendChild(node); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function insert(target, node, anchor) { |
|
target.insertBefore(node, anchor || null); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function insert_hydration(target, node, anchor) { |
|
if (is_hydrating && !anchor) { |
|
append_hydration(target, node); |
|
} else if (node.parentNode !== target || node.nextSibling != anchor) { |
|
target.insertBefore(node, anchor || null); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function detach(node) { |
|
if (node.parentNode) { |
|
node.parentNode.removeChild(node); |
|
} |
|
} |
|
|
|
|
|
|
|
export function destroy_each(iterations, detaching) { |
|
for (let i = 0; i < iterations.length; i += 1) { |
|
if (iterations[i]) iterations[i].d(detaching); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
export function element(name) { |
|
return document.createElement(name); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function element_is(name, is) { |
|
return document.createElement(name, { is }); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function object_without_properties(obj, exclude) { |
|
const target = ({}); |
|
for (const k in obj) { |
|
if ( |
|
has_prop(obj, k) && |
|
|
|
exclude.indexOf(k) === -1 |
|
) { |
|
|
|
target[k] = obj[k]; |
|
} |
|
} |
|
return target; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
export function svg_element(name) { |
|
return document.createElementNS('http://www.w3.org/2000/svg', name); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function text(data) { |
|
return document.createTextNode(data); |
|
} |
|
|
|
|
|
|
|
export function space() { |
|
return text(' '); |
|
} |
|
|
|
|
|
|
|
export function empty() { |
|
return text(''); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function comment(content) { |
|
return document.createComment(content); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function listen(node, event, handler, options) { |
|
node.addEventListener(event, handler, options); |
|
return () => node.removeEventListener(event, handler, options); |
|
} |
|
|
|
|
|
|
|
export function prevent_default(fn) { |
|
return function (event) { |
|
event.preventDefault(); |
|
|
|
return fn.call(this, event); |
|
}; |
|
} |
|
|
|
|
|
|
|
export function stop_propagation(fn) { |
|
return function (event) { |
|
event.stopPropagation(); |
|
|
|
return fn.call(this, event); |
|
}; |
|
} |
|
|
|
|
|
|
|
export function stop_immediate_propagation(fn) { |
|
return function (event) { |
|
event.stopImmediatePropagation(); |
|
|
|
return fn.call(this, event); |
|
}; |
|
} |
|
|
|
|
|
|
|
export function self(fn) { |
|
return function (event) { |
|
|
|
if (event.target === this) fn.call(this, event); |
|
}; |
|
} |
|
|
|
|
|
|
|
export function trusted(fn) { |
|
return function (event) { |
|
|
|
if (event.isTrusted) fn.call(this, event); |
|
}; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function attr(node, attribute, value) { |
|
if (value == null) node.removeAttribute(attribute); |
|
else if (node.getAttribute(attribute) !== value) node.setAttribute(attribute, value); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const always_set_through_set_attribute = ['width', 'height']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
export function set_attributes(node, attributes) { |
|
|
|
const descriptors = Object.getOwnPropertyDescriptors(node.__proto__); |
|
for (const key in attributes) { |
|
if (attributes[key] == null) { |
|
node.removeAttribute(key); |
|
} else if (key === 'style') { |
|
node.style.cssText = attributes[key]; |
|
} else if (key === '__value') { |
|
(node).value = node[key] = attributes[key]; |
|
} else if ( |
|
descriptors[key] && |
|
descriptors[key].set && |
|
always_set_through_set_attribute.indexOf(key) === -1 |
|
) { |
|
node[key] = attributes[key]; |
|
} else { |
|
attr(node, key, attributes[key]); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
export function set_svg_attributes(node, attributes) { |
|
for (const key in attributes) { |
|
attr(node, key, attributes[key]); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function set_custom_element_data_map(node, data_map) { |
|
Object.keys(data_map).forEach((key) => { |
|
set_custom_element_data(node, key, data_map[key]); |
|
}); |
|
} |
|
|
|
|
|
|
|
export function set_custom_element_data(node, prop, value) { |
|
const lower = prop.toLowerCase(); |
|
if (lower in node) { |
|
node[lower] = typeof node[lower] === 'boolean' && value === '' ? true : value; |
|
} else if (prop in node) { |
|
node[prop] = typeof node[prop] === 'boolean' && value === '' ? true : value; |
|
} else { |
|
attr(node, prop, value); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
export function set_dynamic_element_data(tag) { |
|
return /-/.test(tag) ? set_custom_element_data_map : set_attributes; |
|
} |
|
|
|
|
|
|
|
|
|
export function xlink_attr(node, attribute, value) { |
|
node.setAttributeNS('http://www.w3.org/1999/xlink', attribute, value); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function get_svelte_dataset(node) { |
|
return node.dataset.svelteH; |
|
} |
|
|
|
|
|
|
|
export function get_binding_group_value(group, __value, checked) { |
|
const value = new Set(); |
|
for (let i = 0; i < group.length; i += 1) { |
|
if (group[i].checked) value.add(group[i].__value); |
|
} |
|
if (!checked) { |
|
value.delete(__value); |
|
} |
|
return Array.from(value); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function init_binding_group(group) { |
|
|
|
|
|
let _inputs; |
|
return { |
|
p(...inputs) { |
|
_inputs = inputs; |
|
_inputs.forEach((input) => group.push(input)); |
|
}, |
|
r() { |
|
_inputs.forEach((input) => group.splice(group.indexOf(input), 1)); |
|
} |
|
}; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function init_binding_group_dynamic(group, indexes) { |
|
|
|
|
|
let _group = get_binding_group(group); |
|
|
|
|
|
|
|
let _inputs; |
|
|
|
function get_binding_group(group) { |
|
for (let i = 0; i < indexes.length; i++) { |
|
group = group[indexes[i]] = group[indexes[i]] || []; |
|
} |
|
return group; |
|
} |
|
|
|
|
|
|
|
function push() { |
|
_inputs.forEach((input) => _group.push(input)); |
|
} |
|
|
|
|
|
|
|
function remove() { |
|
_inputs.forEach((input) => _group.splice(_group.indexOf(input), 1)); |
|
} |
|
return { |
|
u(new_indexes) { |
|
indexes = new_indexes; |
|
const new_group = get_binding_group(group); |
|
if (new_group !== _group) { |
|
remove(); |
|
_group = new_group; |
|
push(); |
|
} |
|
}, |
|
p(...inputs) { |
|
_inputs = inputs; |
|
push(); |
|
}, |
|
r: remove |
|
}; |
|
} |
|
|
|
|
|
export function to_number(value) { |
|
return value === '' ? null : +value; |
|
} |
|
|
|
|
|
export function time_ranges_to_array(ranges) { |
|
const array = []; |
|
for (let i = 0; i < ranges.length; i += 1) { |
|
array.push({ start: ranges.start(i), end: ranges.end(i) }); |
|
} |
|
return array; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function children(element) { |
|
return Array.from(element.childNodes); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
function init_claim_info(nodes) { |
|
if (nodes.claim_info === undefined) { |
|
nodes.claim_info = { last_index: 0, total_claimed: 0 }; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function claim_node(nodes, predicate, process_node, create_node, dont_update_last_index = false) { |
|
|
|
init_claim_info(nodes); |
|
const result_node = (() => { |
|
|
|
for (let i = nodes.claim_info.last_index; i < nodes.length; i++) { |
|
const node = nodes[i]; |
|
if (predicate(node)) { |
|
const replacement = process_node(node); |
|
if (replacement === undefined) { |
|
nodes.splice(i, 1); |
|
} else { |
|
nodes[i] = replacement; |
|
} |
|
if (!dont_update_last_index) { |
|
nodes.claim_info.last_index = i; |
|
} |
|
return node; |
|
} |
|
} |
|
|
|
|
|
for (let i = nodes.claim_info.last_index - 1; i >= 0; i--) { |
|
const node = nodes[i]; |
|
if (predicate(node)) { |
|
const replacement = process_node(node); |
|
if (replacement === undefined) { |
|
nodes.splice(i, 1); |
|
} else { |
|
nodes[i] = replacement; |
|
} |
|
if (!dont_update_last_index) { |
|
nodes.claim_info.last_index = i; |
|
} else if (replacement === undefined) { |
|
|
|
nodes.claim_info.last_index--; |
|
} |
|
return node; |
|
} |
|
} |
|
|
|
return create_node(); |
|
})(); |
|
result_node.claim_order = nodes.claim_info.total_claimed; |
|
nodes.claim_info.total_claimed += 1; |
|
return result_node; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function claim_element_base(nodes, name, attributes, create_element) { |
|
return claim_node( |
|
nodes, |
|
|
|
(node) => node.nodeName === name, |
|
|
|
(node) => { |
|
const remove = []; |
|
for (let j = 0; j < node.attributes.length; j++) { |
|
const attribute = node.attributes[j]; |
|
if (!attributes[attribute.name]) { |
|
remove.push(attribute.name); |
|
} |
|
} |
|
remove.forEach((v) => node.removeAttribute(v)); |
|
return undefined; |
|
}, |
|
() => create_element(name) |
|
); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function claim_element(nodes, name, attributes) { |
|
return claim_element_base(nodes, name, attributes, element); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function claim_svg_element(nodes, name, attributes) { |
|
return claim_element_base(nodes, name, attributes, svg_element); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function claim_text(nodes, data) { |
|
return claim_node( |
|
nodes, |
|
|
|
(node) => node.nodeType === 3, |
|
|
|
(node) => { |
|
const data_str = '' + data; |
|
if (node.data.startsWith(data_str)) { |
|
if (node.data.length !== data_str.length) { |
|
return node.splitText(data_str.length); |
|
} |
|
} else { |
|
node.data = data_str; |
|
} |
|
}, |
|
() => text(data), |
|
true |
|
); |
|
} |
|
|
|
|
|
|
|
export function claim_space(nodes) { |
|
return claim_text(nodes, ' '); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function claim_comment(nodes, data) { |
|
return claim_node( |
|
nodes, |
|
|
|
(node) => node.nodeType === 8, |
|
|
|
(node) => { |
|
node.data = '' + data; |
|
return undefined; |
|
}, |
|
() => comment(data), |
|
true |
|
); |
|
} |
|
|
|
function get_comment_idx(nodes, text, start) { |
|
for (let i = start; i < nodes.length; i += 1) { |
|
const node = nodes[i]; |
|
if (node.nodeType === 8 && node.textContent.trim() === text) { |
|
return i; |
|
} |
|
} |
|
return -1; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function claim_html_tag(nodes, is_svg) { |
|
|
|
const start_index = get_comment_idx(nodes, 'HTML_TAG_START', 0); |
|
const end_index = get_comment_idx(nodes, 'HTML_TAG_END', start_index + 1); |
|
if (start_index === -1 || end_index === -1) { |
|
return new HtmlTagHydration(is_svg); |
|
} |
|
|
|
init_claim_info(nodes); |
|
const html_tag_nodes = nodes.splice(start_index, end_index - start_index + 1); |
|
detach(html_tag_nodes[0]); |
|
detach(html_tag_nodes[html_tag_nodes.length - 1]); |
|
const claimed_nodes = html_tag_nodes.slice(1, html_tag_nodes.length - 1); |
|
if (claimed_nodes.length === 0) { |
|
return new HtmlTagHydration(is_svg); |
|
} |
|
for (const n of claimed_nodes) { |
|
n.claim_order = nodes.claim_info.total_claimed; |
|
nodes.claim_info.total_claimed += 1; |
|
} |
|
return new HtmlTagHydration(is_svg, claimed_nodes); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
export function set_data(text, data) { |
|
data = '' + data; |
|
if (text.data === data) return; |
|
text.data = (data); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
export function set_data_contenteditable(text, data) { |
|
data = '' + data; |
|
if (text.wholeText === data) return; |
|
text.data = (data); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function set_data_maybe_contenteditable(text, data, attr_value) { |
|
if (~contenteditable_truthy_values.indexOf(attr_value)) { |
|
set_data_contenteditable(text, data); |
|
} else { |
|
set_data(text, data); |
|
} |
|
} |
|
|
|
|
|
|
|
export function set_input_value(input, value) { |
|
input.value = value == null ? '' : value; |
|
} |
|
|
|
|
|
|
|
export function set_input_type(input, type) { |
|
try { |
|
input.type = type; |
|
} catch (e) { |
|
|
|
} |
|
} |
|
|
|
|
|
|
|
export function set_style(node, key, value, important) { |
|
if (value == null) { |
|
node.style.removeProperty(key); |
|
} else { |
|
node.style.setProperty(key, value, important ? 'important' : ''); |
|
} |
|
} |
|
|
|
|
|
|
|
export function select_option(select, value, mounting) { |
|
for (let i = 0; i < select.options.length; i += 1) { |
|
const option = select.options[i]; |
|
if (option.__value === value) { |
|
option.selected = true; |
|
return; |
|
} |
|
} |
|
if (!mounting || value !== undefined) { |
|
select.selectedIndex = -1; |
|
} |
|
} |
|
|
|
|
|
|
|
export function select_options(select, value) { |
|
for (let i = 0; i < select.options.length; i += 1) { |
|
const option = select.options[i]; |
|
option.selected = ~value.indexOf(option.__value); |
|
} |
|
} |
|
|
|
export function select_value(select) { |
|
const selected_option = select.querySelector(':checked'); |
|
return selected_option && selected_option.__value; |
|
} |
|
|
|
export function select_multiple_value(select) { |
|
return [].map.call(select.querySelectorAll(':checked'), (option) => option.__value); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
let crossorigin; |
|
|
|
|
|
|
|
export function is_crossorigin() { |
|
if (crossorigin === undefined) { |
|
crossorigin = false; |
|
try { |
|
if (typeof window !== 'undefined' && window.parent) { |
|
void window.parent.document; |
|
} |
|
} catch (error) { |
|
crossorigin = true; |
|
} |
|
} |
|
return crossorigin; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
export function add_iframe_resize_listener(node, fn) { |
|
const computed_style = getComputedStyle(node); |
|
if (computed_style.position === 'static') { |
|
node.style.position = 'relative'; |
|
} |
|
const iframe = element('iframe'); |
|
iframe.setAttribute( |
|
'style', |
|
'display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; ' + |
|
'overflow: hidden; border: 0; opacity: 0; pointer-events: none; z-index: -1;' |
|
); |
|
iframe.setAttribute('aria-hidden', 'true'); |
|
iframe.tabIndex = -1; |
|
const crossorigin = is_crossorigin(); |
|
|
|
|
|
|
|
|
|
let unsubscribe; |
|
if (crossorigin) { |
|
iframe.src = "data:text/html,<script>onresize=function(){parent.postMessage(0,'*')}</script>"; |
|
unsubscribe = listen( |
|
window, |
|
'message', |
|
(event) => { |
|
if (event.source === iframe.contentWindow) fn(); |
|
} |
|
); |
|
} else { |
|
iframe.src = 'about:blank'; |
|
iframe.onload = () => { |
|
unsubscribe = listen(iframe.contentWindow, 'resize', fn); |
|
|
|
|
|
fn(); |
|
}; |
|
} |
|
append(node, iframe); |
|
return () => { |
|
if (crossorigin) { |
|
unsubscribe(); |
|
} else if (unsubscribe && iframe.contentWindow) { |
|
unsubscribe(); |
|
} |
|
detach(iframe); |
|
}; |
|
} |
|
export const resize_observer_content_box = new ResizeObserverSingleton({ |
|
box: 'content-box' |
|
}); |
|
export const resize_observer_border_box = new ResizeObserverSingleton({ |
|
box: 'border-box' |
|
}); |
|
export const resize_observer_device_pixel_content_box = new ResizeObserverSingleton( |
|
{ box: 'device-pixel-content-box' } |
|
); |
|
export { ResizeObserverSingleton }; |
|
|
|
|
|
|
|
export function toggle_class(element, name, toggle) { |
|
|
|
element.classList.toggle(name, !!toggle); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function custom_event(type, detail, { bubbles = false, cancelable = false } = {}) { |
|
return new CustomEvent(type, { detail, bubbles, cancelable }); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
export function query_selector_all(selector, parent = document.body) { |
|
return Array.from(parent.querySelectorAll(selector)); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
export function head_selector(nodeId, head) { |
|
const result = []; |
|
let started = 0; |
|
for (const node of head.childNodes) { |
|
if (node.nodeType === 8 ) { |
|
const comment = node.textContent.trim(); |
|
if (comment === `HEAD_${nodeId}_END`) { |
|
started -= 1; |
|
result.push(node); |
|
} else if (comment === `HEAD_${nodeId}_START`) { |
|
started += 1; |
|
result.push(node); |
|
} |
|
} else if (started > 0) { |
|
result.push(node); |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
export class HtmlTag { |
|
|
|
|
|
|
|
|
|
is_svg = false; |
|
|
|
e = undefined; |
|
|
|
n = undefined; |
|
|
|
t = undefined; |
|
|
|
a = undefined; |
|
constructor(is_svg = false) { |
|
this.is_svg = is_svg; |
|
this.e = this.n = null; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
c(html) { |
|
this.h(html); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m(html, target, anchor = null) { |
|
if (!this.e) { |
|
if (this.is_svg) |
|
this.e = svg_element( (target.nodeName)); |
|
else |
|
this.e = element( |
|
( |
|
target.nodeType === 11 ? 'TEMPLATE' : target.nodeName |
|
) |
|
); |
|
this.t = |
|
target.tagName !== 'TEMPLATE' |
|
? target |
|
: (target).content; |
|
this.c(html); |
|
} |
|
this.i(anchor); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
h(html) { |
|
this.e.innerHTML = html; |
|
this.n = Array.from( |
|
this.e.nodeName === 'TEMPLATE' ? this.e.content.childNodes : this.e.childNodes |
|
); |
|
} |
|
|
|
|
|
|
|
i(anchor) { |
|
for (let i = 0; i < this.n.length; i += 1) { |
|
insert(this.t, this.n[i], anchor); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
p(html) { |
|
this.d(); |
|
this.h(html); |
|
this.i(this.a); |
|
} |
|
|
|
|
|
|
|
d() { |
|
this.n.forEach(detach); |
|
} |
|
} |
|
|
|
export class HtmlTagHydration extends HtmlTag { |
|
|
|
l = undefined; |
|
|
|
constructor(is_svg = false, claimed_nodes) { |
|
super(is_svg); |
|
this.e = this.n = null; |
|
this.l = claimed_nodes; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
c(html) { |
|
if (this.l) { |
|
this.n = this.l; |
|
} else { |
|
super.c(html); |
|
} |
|
} |
|
|
|
|
|
|
|
i(anchor) { |
|
for (let i = 0; i < this.n.length; i += 1) { |
|
insert_hydration(this.t, this.n[i], anchor); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function attribute_to_object(attributes) { |
|
const result = {}; |
|
for (const attribute of attributes) { |
|
result[attribute.name] = attribute.value; |
|
} |
|
return result; |
|
} |
|
|
|
const escaped = { |
|
'"': '"', |
|
'&': '&', |
|
'<': '<' |
|
}; |
|
|
|
const regex_attribute_characters_to_escape = /["&<]/g; |
|
|
|
|
|
|
|
|
|
|
|
function escape_attribute(attribute) { |
|
return String(attribute).replace(regex_attribute_characters_to_escape, (match) => escaped[match]); |
|
} |
|
|
|
|
|
|
|
|
|
export function stringify_spread(attributes) { |
|
let str = ' '; |
|
for (const key in attributes) { |
|
if (attributes[key] != null) { |
|
str += `${key}="${escape_attribute(attributes[key])}" `; |
|
} |
|
} |
|
|
|
return str; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function get_custom_elements_slots(element) { |
|
const result = {}; |
|
element.childNodes.forEach( |
|
(node) => { |
|
result[node.slot || 'default'] = true; |
|
} |
|
); |
|
return result; |
|
} |
|
|
|
export function construct_svelte_component(component, props) { |
|
return new component(props); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|