Lint and format ./src/runtime/internal/dom.js

pull/8569/head
Simon Holthausen 3 years ago
parent 8e03ef9fb9
commit 67bcdc6df8

@ -29,8 +29,7 @@ function upper_bound(low, high, key, value) {
const mid = low + ((high - low) >> 1);
if (key(mid) <= value) {
low = mid + 1;
}
else {
} else {
high = mid;
}
}
@ -42,8 +41,7 @@ function upper_bound(low, high, key, value) {
* @returns {void}
*/
function init_hydrate(target) {
if (target.hydrate_init)
return;
if (target.hydrate_init) return;
target.hydrate_init = true;
// We know that all children have claim_order values since the unclaimed have been detached if target is not <head>
@ -89,7 +87,8 @@ function init_hydrate(target) {
// Find the largest subsequence length such that it ends in a value less than our current value
// upper_bound returns first greater value, so we subtract one
// with fast path for when we are on the current longest subsequence
const seqLen = (longest > 0 && children[m[longest]].claim_order <= current
const seqLen =
(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[seqLen] + 1;
@ -162,8 +161,7 @@ export function append_styles(target, style_sheet_id, styles) {
* @returns {ShadowRoot | Document}
*/
export function get_root_for_style(node) {
if (!node)
return document;
if (!node) return document;
const root = node.getRootNode ? node.getRootNode() : node.ownerDocument;
if (root && root.host) {
return root;
@ -205,8 +203,10 @@ function append_stylesheet(node, style) {
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)) {
if (
target.actual_end_child === undefined ||
(target.actual_end_child !== null && target.actual_end_child.parentNode !== target)
) {
target.actual_end_child = target.firstChild;
}
// Skip nodes of undefined ordering
@ -218,12 +218,10 @@ export function append_hydration(target, node) {
if (node.claim_order !== undefined || node.parentNode !== target) {
target.insertBefore(node, target.actual_end_child);
}
}
else {
} else {
target.actual_end_child = node.nextSibling;
}
}
else if (node.parentNode !== target || node.nextSibling !== null) {
} else if (node.parentNode !== target || node.nextSibling !== null) {
target.appendChild(node);
}
}
@ -247,8 +245,7 @@ export function insert(target, node, anchor) {
export function insert_hydration(target, node, anchor) {
if (is_hydrating && !anchor) {
append_hydration(target, node);
}
else if (node.parentNode !== target || node.nextSibling != anchor) {
} else if (node.parentNode !== target || node.nextSibling != anchor) {
target.insertBefore(node, anchor || null);
}
}
@ -267,8 +264,7 @@ export function detach(node) {
* @returns {void} */
export function destroy_each(iterations, detaching) {
for (let i = 0; i < iterations.length; i += 1) {
if (iterations[i])
iterations[i].d(detaching);
if (iterations[i]) iterations[i].d(detaching);
}
}
@ -297,9 +293,11 @@ export function element_is(name, is) {
export function object_without_properties(obj, exclude) {
const target = {};
for (const k in obj) {
if (has_prop(obj, k) &&
if (
has_prop(obj, k) &&
// @ts-ignore
exclude.indexOf(k) === -1) {
exclude.indexOf(k) === -1
) {
// @ts-ignore
target[k] = obj[k];
}
@ -390,8 +388,7 @@ export function stop_immediate_propagation(fn) {
export function self(fn) {
return function (event) {
// @ts-ignore
if (event.target === this)
fn.call(this, event);
if (event.target === this) fn.call(this, event);
};
}
@ -400,8 +397,7 @@ export function self(fn) {
export function trusted(fn) {
return function (event) {
// @ts-ignore
if (event.isTrusted)
fn.call(this, event);
if (event.isTrusted) fn.call(this, event);
};
}
@ -412,10 +408,8 @@ export function trusted(fn) {
* @returns {void}
*/
export function attr(node, attribute, value) {
if (value == null)
node.removeAttribute(attribute);
else if (node.getAttribute(attribute) !== value)
node.setAttribute(attribute, value);
if (value == null) node.removeAttribute(attribute);
else if (node.getAttribute(attribute) !== value) node.setAttribute(attribute, value);
}
/**
* List of attributes that should always be set through the attr method,
@ -437,19 +431,17 @@ export function set_attributes(node, attributes) {
for (const key in attributes) {
if (attributes[key] == null) {
node.removeAttribute(key);
}
else if (key === 'style') {
} else if (key === 'style') {
node.style.cssText = attributes[key];
}
else if (key === '__value') {
} else if (key === '__value') {
node.value = node[key] = attributes[key];
}
else if (descriptors[key] &&
} else if (
descriptors[key] &&
descriptors[key].set &&
always_set_through_set_attribute.indexOf(key) === -1) {
always_set_through_set_attribute.indexOf(key) === -1
) {
node[key] = attributes[key];
}
else {
} else {
attr(node, key, attributes[key]);
}
}
@ -481,8 +473,7 @@ export function set_custom_element_data_map(node, data_map) {
export function set_custom_element_data(node, prop, value) {
if (prop in node) {
node[prop] = typeof node[prop] === 'boolean' && value === '' ? true : value;
}
else {
} else {
attr(node, prop, value);
}
}
@ -514,8 +505,7 @@ export function get_svelte_dataset(node) {
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 (group[i].checked) value.add(group[i].__value);
}
if (!checked) {
value.delete(__value);
@ -528,7 +518,6 @@ export function get_binding_group_value(group, __value, checked) {
* @returns {{ p(...inputs: HTMLInputElement[]): void; r(): void; }}
*/
export function init_binding_group(group) {
/**
* @type {HTMLInputElement[]} */
let _inputs;
@ -548,7 +537,6 @@ export function init_binding_group(group) {
* @returns {{ u(new_indexes: number[]): void; p(...inputs: HTMLInputElement[]): void; r: () => void; }}
*/
export function init_binding_group_dynamic(group, indexes) {
/**
* @type {HTMLInputElement[]} */
let _group = get_binding_group(group);
@ -648,8 +636,7 @@ function claim_node(nodes, predicate, processNode, createNode, dontUpdateLastInd
const replacement = processNode(node);
if (replacement === undefined) {
nodes.splice(i, 1);
}
else {
} else {
nodes[i] = replacement;
}
if (!dontUpdateLastIndex) {
@ -666,14 +653,12 @@ function claim_node(nodes, predicate, processNode, createNode, dontUpdateLastInd
const replacement = processNode(node);
if (replacement === undefined) {
nodes.splice(i, 1);
}
else {
} else {
nodes[i] = replacement;
}
if (!dontUpdateLastIndex) {
nodes.claim_info.last_index = i;
}
else if (replacement === undefined) {
} else if (replacement === undefined) {
// Since we spliced before the last_index, we decrease it
nodes.claim_info.last_index--;
}
@ -696,7 +681,10 @@ function claim_node(nodes, predicate, processNode, createNode, dontUpdateLastInd
* @returns {Element | SVGElement}
*/
function claim_element_base(nodes, name, attributes, create_element) {
return claim_node(nodes, (node) => node.nodeName === name, (node) => {
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];
@ -706,7 +694,9 @@ function claim_element_base(nodes, name, attributes, create_element) {
}
remove.forEach((v) => node.removeAttribute(v));
return undefined;
}, () => create_element(name));
},
() => create_element(name)
);
}
/**
@ -734,17 +724,21 @@ export function claim_svg_element(nodes, name, attributes) {
* @returns {Text}
*/
export function claim_text(nodes, data) {
return claim_node(nodes, (node) => node.nodeType === 3, (node) => {
return claim_node(
nodes,
(node) => node.nodeType === 3,
(node) => {
const dataStr = '' + data;
if (node.data.startsWith(dataStr)) {
if (node.data.length !== dataStr.length) {
return node.splitText(dataStr.length);
}
}
else {
} else {
node.data = dataStr;
}
}, () => text(data), true // Text nodes should not update last index since it is likely not worth it to eliminate an increasing subsequence of actual elements
},
() => text(data),
true // Text nodes should not update last index since it is likely not worth it to eliminate an increasing subsequence of actual elements
);
}
@ -759,10 +753,16 @@ export function claim_space(nodes) {
* @returns {Comment}
*/
export function claim_comment(nodes, data) {
return claim_node(nodes, (node) => node.nodeType === 8, (node) => {
return claim_node(
nodes,
(node) => node.nodeType === 8,
(node) => {
node.data = '' + data;
return undefined;
}, () => comment(data), true);
},
() => comment(data),
true
);
}
/**
@ -807,8 +807,7 @@ export function claim_html_tag(nodes, is_svg) {
*/
export function set_data(text, data) {
data = '' + data;
if (text.data === data)
return;
if (text.data === data) return;
text.data = data;
}
@ -819,8 +818,7 @@ export function set_data(text, data) {
*/
export function set_data_contenteditable(text, data) {
data = '' + data;
if (text.wholeText === data)
return;
if (text.wholeText === data) return;
text.data = data;
}
@ -833,8 +831,7 @@ export function set_data_contenteditable(text, data) {
export function set_data_maybe_contenteditable(text, data, attr_value) {
if (~contenteditable_truthy_values.indexOf(attr_value)) {
set_data_contenteditable(text, data);
}
else {
} else {
set_data(text, data);
}
}
@ -850,8 +847,7 @@ export function set_input_value(input, value) {
export function set_input_type(input, type) {
try {
input.type = type;
}
catch (e) {
} catch (e) {
// do nothing
}
}
@ -861,8 +857,7 @@ export function set_input_type(input, type) {
export function set_style(node, key, value, important) {
if (value == null) {
node.style.removeProperty(key);
}
else {
} else {
node.style.setProperty(key, value, important ? 'important' : '');
}
}
@ -919,8 +914,7 @@ export function is_crossorigin() {
if (typeof window !== 'undefined' && window.parent) {
void window.parent.document;
}
}
catch (error) {
} catch (error) {
crossorigin = true;
}
}
@ -938,8 +932,11 @@ export function add_iframe_resize_listener(node, fn) {
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(
'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();
@ -950,11 +947,9 @@ export function add_iframe_resize_listener(node, fn) {
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();
if (event.source === iframe.contentWindow) fn();
});
}
else {
} else {
iframe.src = 'about:blank';
iframe.onload = () => {
unsubscribe = listen(iframe.contentWindow, 'resize', fn);
@ -967,8 +962,7 @@ export function add_iframe_resize_listener(node, fn) {
return () => {
if (crossorigin) {
unsubscribe();
}
else if (unsubscribe && iframe.contentWindow) {
} else if (unsubscribe && iframe.contentWindow) {
unsubscribe();
}
detach(iframe);
@ -980,7 +974,9 @@ export const resize_observer_content_box = /* @__PURE__ */ new ResizeObserverSin
export const resize_observer_border_box = /* @__PURE__ */ new ResizeObserverSingleton({
box: 'border-box'
});
export const resize_observer_device_pixel_content_box = /* @__PURE__ */ new ResizeObserverSingleton({ box: 'device-pixel-content-box' });
export const resize_observer_device_pixel_content_box = /* @__PURE__ */ new ResizeObserverSingleton(
{ box: 'device-pixel-content-box' }
);
export { ResizeObserverSingleton };
/**
@ -995,7 +991,6 @@ export function toggle_class(element, name, toggle) {
* @returns {CustomEvent<T>}
*/
export function custom_event(type, detail, { bubbles = false, cancelable = false } = {}) {
/**
* @type {CustomEvent<T>} */
const e = document.createEvent('CustomEvent');
@ -1026,13 +1021,11 @@ export function head_selector(nodeId, head) {
if (comment === `HEAD_${nodeId}_END`) {
started -= 1;
result.push(node);
}
else if (comment === `HEAD_${nodeId}_START`) {
} else if (comment === `HEAD_${nodeId}_START`) {
started += 1;
result.push(node);
}
}
else if (started > 0) {
} else if (started > 0) {
result.push(node);
}
}
@ -1040,7 +1033,6 @@ export function head_selector(nodeId, head) {
}
/** */
export class HtmlTag {
/**
* @private
* @default false
@ -1079,10 +1071,9 @@ export class HtmlTag {
*/
m(html, target, anchor = null) {
if (!this.e) {
if (this.is_svg)
this.e = svg_element(target.nodeName);
if (this.is_svg) this.e = svg_element(target.nodeName);
/** #7364 target for <template> may be provided as #document-fragment(11) */ else
this.e = element((target.nodeType === 11 ? 'TEMPLATE' : target.nodeName));
this.e = element(target.nodeType === 11 ? 'TEMPLATE' : target.nodeName);
this.t = target.tagName !== 'TEMPLATE' ? target : target.content;
this.c(html);
}
@ -1095,9 +1086,9 @@ export class HtmlTag {
*/
h(html) {
this.e.innerHTML = html;
this.n = Array.from(this.e.nodeName === 'TEMPLATE'
? this.e.content.childNodes
: this.e.childNodes);
this.n = Array.from(
this.e.nodeName === 'TEMPLATE' ? this.e.content.childNodes : this.e.childNodes
);
}
/**
@ -1144,8 +1135,7 @@ export class HtmlTagHydration extends HtmlTag {
c(html) {
if (this.l) {
this.n = this.l;
}
else {
} else {
super.c(html);
}
}
@ -1189,7 +1179,6 @@ export function construct_svelte_component(component, props) {
return new component(props);
}
/**
* @typedef {Node & {
* claim_order?: number;
@ -1209,4 +1198,3 @@ export function construct_svelte_component(component, props) {
* };
* }} ChildNodeArray
*/

Loading…
Cancel
Save