Last active
January 17, 2020 12:14
-
-
Save gushogg-blake/052516002970b47a30a95f40b6f0828c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<style> | |
.yellow.svelte-77u8jk{background:yellow} | |
</style> | |
</head> | |
<body> | |
<div id="a" class="svelte-77u8jk yellow"></div> | |
<script> | |
var Test = (function () { | |
'use strict'; | |
function noop() { } | |
function run(fn) { | |
return fn(); | |
} | |
function blank_object() { | |
return Object.create(null); | |
} | |
function run_all(fns) { | |
fns.forEach(run); | |
} | |
function is_function(thing) { | |
return typeof thing === 'function'; | |
} | |
function safe_not_equal(a, b) { | |
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); | |
} | |
function append(target, node) { | |
target.appendChild(node); | |
} | |
function insert(target, node, anchor) { | |
target.insertBefore(node, anchor || null); | |
} | |
function detach(node) { | |
node.parentNode.removeChild(node); | |
} | |
function element(name) { | |
return document.createElement(name); | |
} | |
function svg_element(name) { | |
return document.createElementNS('http://www.w3.org/2000/svg', name); | |
} | |
function text(data) { | |
return document.createTextNode(data); | |
} | |
function space() { | |
return text(' '); | |
} | |
function attr(node, attribute, value) { | |
if (value == null) | |
node.removeAttribute(attribute); | |
else if (node.getAttribute(attribute) !== value) | |
node.setAttribute(attribute, value); | |
} | |
function children(element) { | |
return Array.from(element.childNodes); | |
} | |
function claim_element(nodes, name, attributes, svg) { | |
for (let i = 0; i < nodes.length; i += 1) { | |
const node = nodes[i]; | |
if (node.nodeName === name) { | |
for (let j = 0; j < node.attributes.length; j += 1) { | |
const attribute = node.attributes[j]; | |
if (!attributes[attribute.name]) | |
node.removeAttribute(attribute.name); | |
} | |
return nodes.splice(i, 1)[0]; // TODO strip unwanted attributes | |
} | |
} | |
return svg ? svg_element(name) : element(name); | |
} | |
function claim_text(nodes, data) { | |
for (let i = 0; i < nodes.length; i += 1) { | |
const node = nodes[i]; | |
if (node.nodeType === 3) { | |
node.data = '' + data; | |
return nodes.splice(i, 1)[0]; | |
} | |
} | |
return text(data); | |
} | |
function claim_space(nodes) { | |
return claim_text(nodes, ' '); | |
} | |
function toggle_class(element, name, toggle) { | |
element.classList[toggle ? 'add' : 'remove'](name); | |
} | |
let current_component; | |
function set_current_component(component) { | |
current_component = component; | |
} | |
const dirty_components = []; | |
const binding_callbacks = []; | |
const render_callbacks = []; | |
const flush_callbacks = []; | |
const resolved_promise = Promise.resolve(); | |
let update_scheduled = false; | |
function schedule_update() { | |
if (!update_scheduled) { | |
update_scheduled = true; | |
resolved_promise.then(flush); | |
} | |
} | |
function add_render_callback(fn) { | |
render_callbacks.push(fn); | |
} | |
function flush() { | |
const seen_callbacks = new Set(); | |
do { | |
// first, call beforeUpdate functions | |
// and update components | |
while (dirty_components.length) { | |
const component = dirty_components.shift(); | |
set_current_component(component); | |
update(component.$$); | |
} | |
while (binding_callbacks.length) | |
binding_callbacks.pop()(); | |
// then, once components are updated, call | |
// afterUpdate functions. This may cause | |
// subsequent updates... | |
for (let i = 0; i < render_callbacks.length; i += 1) { | |
const callback = render_callbacks[i]; | |
if (!seen_callbacks.has(callback)) { | |
callback(); | |
// ...so guard against infinite loops | |
seen_callbacks.add(callback); | |
} | |
} | |
render_callbacks.length = 0; | |
} while (dirty_components.length); | |
while (flush_callbacks.length) { | |
flush_callbacks.pop()(); | |
} | |
update_scheduled = false; | |
} | |
function update($$) { | |
if ($$.fragment !== null) { | |
$$.update(); | |
run_all($$.before_update); | |
const dirty = $$.dirty; | |
$$.dirty = [-1]; | |
$$.fragment && $$.fragment.p($$.ctx, dirty); | |
$$.after_update.forEach(add_render_callback); | |
} | |
} | |
const outroing = new Set(); | |
function transition_in(block, local) { | |
if (block && block.i) { | |
outroing.delete(block); | |
block.i(local); | |
} | |
} | |
function mount_component(component, target, anchor) { | |
const { fragment, on_mount, on_destroy, after_update } = component.$$; | |
fragment && fragment.m(target, anchor); | |
// onMount happens before the initial afterUpdate | |
add_render_callback(() => { | |
const new_on_destroy = on_mount.map(run).filter(is_function); | |
if (on_destroy) { | |
on_destroy.push(...new_on_destroy); | |
} | |
else { | |
// Edge case - component was destroyed immediately, | |
// most likely as a result of a binding initialising | |
run_all(new_on_destroy); | |
} | |
component.$$.on_mount = []; | |
}); | |
after_update.forEach(add_render_callback); | |
} | |
function destroy_component(component, detaching) { | |
const $$ = component.$$; | |
if ($$.fragment !== null) { | |
run_all($$.on_destroy); | |
$$.fragment && $$.fragment.d(detaching); | |
// TODO null out other refs, including component.$$ (but need to | |
// preserve final state?) | |
$$.on_destroy = $$.fragment = null; | |
$$.ctx = []; | |
} | |
} | |
function make_dirty(component, i) { | |
if (component.$$.dirty[0] === -1) { | |
dirty_components.push(component); | |
schedule_update(); | |
component.$$.dirty.fill(0); | |
} | |
component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31)); | |
} | |
function init(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) { | |
const parent_component = current_component; | |
set_current_component(component); | |
const prop_values = options.props || {}; | |
const $$ = component.$$ = { | |
fragment: null, | |
ctx: null, | |
// state | |
props, | |
update: noop, | |
not_equal, | |
bound: blank_object(), | |
// lifecycle | |
on_mount: [], | |
on_destroy: [], | |
before_update: [], | |
after_update: [], | |
context: new Map(parent_component ? parent_component.$$.context : []), | |
// everything else | |
callbacks: blank_object(), | |
dirty | |
}; | |
let ready = false; | |
$$.ctx = instance | |
? instance(component, prop_values, (i, ret, ...rest) => { | |
const value = rest.length ? rest[0] : ret; | |
if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) { | |
if ($$.bound[i]) | |
$$.bound[i](value); | |
if (ready) | |
make_dirty(component, i); | |
} | |
return ret; | |
}) | |
: []; | |
$$.update(); | |
ready = true; | |
run_all($$.before_update); | |
// `false` as a special case of no DOM component | |
$$.fragment = create_fragment ? create_fragment($$.ctx) : false; | |
if (options.target) { | |
if (options.hydrate) { | |
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | |
$$.fragment && $$.fragment.l(children(options.target)); | |
} | |
else { | |
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | |
$$.fragment && $$.fragment.c(); | |
} | |
if (options.intro) | |
transition_in(component.$$.fragment); | |
mount_component(component, options.target, options.anchor); | |
flush(); | |
} | |
set_current_component(parent_component); | |
} | |
class SvelteComponent { | |
$destroy() { | |
destroy_component(this, 1); | |
this.$destroy = noop; | |
} | |
$on(type, callback) { | |
const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = [])); | |
callbacks.push(callback); | |
return () => { | |
const index = callbacks.indexOf(callback); | |
if (index !== -1) | |
callbacks.splice(index, 1); | |
}; | |
} | |
$set() { | |
// overridden by instance, if it has props | |
} | |
} | |
/* pages/Test.html generated by Svelte v3.17.0 */ | |
function create_if_block(ctx) { | |
let div; | |
let t; | |
return { | |
c() { | |
div = element("div"); | |
t = text("Test"); | |
}, | |
l(nodes) { | |
div = claim_element(nodes, "DIV", {}); | |
var div_nodes = children(div); | |
t = claim_text(div_nodes, "Test"); | |
div_nodes.forEach(detach); | |
}, | |
m(target, anchor) { | |
insert(target, div, anchor); | |
append(div, t); | |
}, | |
d(detaching) { | |
if (detaching) detach(div); | |
} | |
}; | |
} | |
function create_fragment(ctx) { | |
let t; | |
let div; | |
let if_block = /*x*/ ctx[0] && create_if_block(); | |
return { | |
c() { | |
if (if_block) if_block.c(); | |
t = space(); | |
div = element("div"); | |
this.h(); | |
}, | |
l(nodes) { | |
if (if_block) if_block.l(nodes); | |
t = claim_space(nodes); | |
div = claim_element(nodes, "DIV", { id: true, class: true }); | |
children(div).forEach(detach); | |
this.h(); | |
}, | |
h() { | |
attr(div, "id", "a"); | |
attr(div, "class", "svelte-77u8jk"); | |
toggle_class(div, "yellow", yellow); | |
}, | |
m(target, anchor) { | |
if (if_block) if_block.m(target, anchor); | |
insert(target, t, anchor); | |
insert(target, div, anchor); | |
}, | |
p(ctx, [dirty]) { | |
if (dirty & /*yellow*/ 0) { | |
toggle_class(div, "yellow", yellow); | |
} | |
}, | |
i: noop, | |
o: noop, | |
d(detaching) { | |
if (if_block) if_block.d(detaching); | |
if (detaching) detach(t); | |
if (detaching) detach(div); | |
} | |
}; | |
} | |
let yellow = true; | |
function instance($$self) { | |
let x = typeof window !== "undefined"; | |
return [x]; | |
} | |
class Test extends SvelteComponent { | |
constructor(options) { | |
super(); | |
init(this, options, instance, create_fragment, safe_not_equal, {}); | |
} | |
} | |
return Test; | |
}()); | |
new Test({ | |
target: document.body, | |
hydrate: true, | |
}); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<style> | |
.yellow.svelte-77u8jk{background:yellow} | |
</style> | |
</head> | |
<body> | |
<div> | |
Test | |
</div> | |
<div id="a" class="svelte-77u8jk yellow"></div> | |
<script> | |
var Test = (function () { | |
'use strict'; | |
function noop() { } | |
function run(fn) { | |
return fn(); | |
} | |
function blank_object() { | |
return Object.create(null); | |
} | |
function run_all(fns) { | |
fns.forEach(run); | |
} | |
function is_function(thing) { | |
return typeof thing === 'function'; | |
} | |
function safe_not_equal(a, b) { | |
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); | |
} | |
function append(target, node) { | |
target.appendChild(node); | |
} | |
function insert(target, node, anchor) { | |
target.insertBefore(node, anchor || null); | |
} | |
function detach(node) { | |
node.parentNode.removeChild(node); | |
} | |
function element(name) { | |
return document.createElement(name); | |
} | |
function svg_element(name) { | |
return document.createElementNS('http://www.w3.org/2000/svg', name); | |
} | |
function text(data) { | |
return document.createTextNode(data); | |
} | |
function space() { | |
return text(' '); | |
} | |
function attr(node, attribute, value) { | |
if (value == null) | |
node.removeAttribute(attribute); | |
else if (node.getAttribute(attribute) !== value) | |
node.setAttribute(attribute, value); | |
} | |
function children(element) { | |
return Array.from(element.childNodes); | |
} | |
function claim_element(nodes, name, attributes, svg) { | |
for (let i = 0; i < nodes.length; i += 1) { | |
const node = nodes[i]; | |
if (node.nodeName === name) { | |
for (let j = 0; j < node.attributes.length; j += 1) { | |
const attribute = node.attributes[j]; | |
if (!attributes[attribute.name]) | |
node.removeAttribute(attribute.name); | |
} | |
return nodes.splice(i, 1)[0]; // TODO strip unwanted attributes | |
} | |
} | |
return svg ? svg_element(name) : element(name); | |
} | |
function claim_text(nodes, data) { | |
for (let i = 0; i < nodes.length; i += 1) { | |
const node = nodes[i]; | |
if (node.nodeType === 3) { | |
node.data = '' + data; | |
return nodes.splice(i, 1)[0]; | |
} | |
} | |
return text(data); | |
} | |
function claim_space(nodes) { | |
return claim_text(nodes, ' '); | |
} | |
function toggle_class(element, name, toggle) { | |
element.classList[toggle ? 'add' : 'remove'](name); | |
} | |
let current_component; | |
function set_current_component(component) { | |
current_component = component; | |
} | |
const dirty_components = []; | |
const binding_callbacks = []; | |
const render_callbacks = []; | |
const flush_callbacks = []; | |
const resolved_promise = Promise.resolve(); | |
let update_scheduled = false; | |
function schedule_update() { | |
if (!update_scheduled) { | |
update_scheduled = true; | |
resolved_promise.then(flush); | |
} | |
} | |
function add_render_callback(fn) { | |
render_callbacks.push(fn); | |
} | |
function flush() { | |
const seen_callbacks = new Set(); | |
do { | |
// first, call beforeUpdate functions | |
// and update components | |
while (dirty_components.length) { | |
const component = dirty_components.shift(); | |
set_current_component(component); | |
update(component.$$); | |
} | |
while (binding_callbacks.length) | |
binding_callbacks.pop()(); | |
// then, once components are updated, call | |
// afterUpdate functions. This may cause | |
// subsequent updates... | |
for (let i = 0; i < render_callbacks.length; i += 1) { | |
const callback = render_callbacks[i]; | |
if (!seen_callbacks.has(callback)) { | |
callback(); | |
// ...so guard against infinite loops | |
seen_callbacks.add(callback); | |
} | |
} | |
render_callbacks.length = 0; | |
} while (dirty_components.length); | |
while (flush_callbacks.length) { | |
flush_callbacks.pop()(); | |
} | |
update_scheduled = false; | |
} | |
function update($$) { | |
if ($$.fragment !== null) { | |
$$.update(); | |
run_all($$.before_update); | |
const dirty = $$.dirty; | |
$$.dirty = [-1]; | |
$$.fragment && $$.fragment.p($$.ctx, dirty); | |
$$.after_update.forEach(add_render_callback); | |
} | |
} | |
const outroing = new Set(); | |
function transition_in(block, local) { | |
if (block && block.i) { | |
outroing.delete(block); | |
block.i(local); | |
} | |
} | |
function mount_component(component, target, anchor) { | |
const { fragment, on_mount, on_destroy, after_update } = component.$$; | |
fragment && fragment.m(target, anchor); | |
// onMount happens before the initial afterUpdate | |
add_render_callback(() => { | |
const new_on_destroy = on_mount.map(run).filter(is_function); | |
if (on_destroy) { | |
on_destroy.push(...new_on_destroy); | |
} | |
else { | |
// Edge case - component was destroyed immediately, | |
// most likely as a result of a binding initialising | |
run_all(new_on_destroy); | |
} | |
component.$$.on_mount = []; | |
}); | |
after_update.forEach(add_render_callback); | |
} | |
function destroy_component(component, detaching) { | |
const $$ = component.$$; | |
if ($$.fragment !== null) { | |
run_all($$.on_destroy); | |
$$.fragment && $$.fragment.d(detaching); | |
// TODO null out other refs, including component.$$ (but need to | |
// preserve final state?) | |
$$.on_destroy = $$.fragment = null; | |
$$.ctx = []; | |
} | |
} | |
function make_dirty(component, i) { | |
if (component.$$.dirty[0] === -1) { | |
dirty_components.push(component); | |
schedule_update(); | |
component.$$.dirty.fill(0); | |
} | |
component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31)); | |
} | |
function init(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) { | |
const parent_component = current_component; | |
set_current_component(component); | |
const prop_values = options.props || {}; | |
const $$ = component.$$ = { | |
fragment: null, | |
ctx: null, | |
// state | |
props, | |
update: noop, | |
not_equal, | |
bound: blank_object(), | |
// lifecycle | |
on_mount: [], | |
on_destroy: [], | |
before_update: [], | |
after_update: [], | |
context: new Map(parent_component ? parent_component.$$.context : []), | |
// everything else | |
callbacks: blank_object(), | |
dirty | |
}; | |
let ready = false; | |
$$.ctx = instance | |
? instance(component, prop_values, (i, ret, ...rest) => { | |
const value = rest.length ? rest[0] : ret; | |
if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) { | |
if ($$.bound[i]) | |
$$.bound[i](value); | |
if (ready) | |
make_dirty(component, i); | |
} | |
return ret; | |
}) | |
: []; | |
$$.update(); | |
ready = true; | |
run_all($$.before_update); | |
// `false` as a special case of no DOM component | |
$$.fragment = create_fragment ? create_fragment($$.ctx) : false; | |
if (options.target) { | |
if (options.hydrate) { | |
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | |
$$.fragment && $$.fragment.l(children(options.target)); | |
} | |
else { | |
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | |
$$.fragment && $$.fragment.c(); | |
} | |
if (options.intro) | |
transition_in(component.$$.fragment); | |
mount_component(component, options.target, options.anchor); | |
flush(); | |
} | |
set_current_component(parent_component); | |
} | |
class SvelteComponent { | |
$destroy() { | |
destroy_component(this, 1); | |
this.$destroy = noop; | |
} | |
$on(type, callback) { | |
const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = [])); | |
callbacks.push(callback); | |
return () => { | |
const index = callbacks.indexOf(callback); | |
if (index !== -1) | |
callbacks.splice(index, 1); | |
}; | |
} | |
$set() { | |
// overridden by instance, if it has props | |
} | |
} | |
/* pages/Test.html generated by Svelte v3.17.0 */ | |
function create_if_block(ctx) { | |
let div; | |
let t; | |
return { | |
c() { | |
div = element("div"); | |
t = text("Test"); | |
}, | |
l(nodes) { | |
div = claim_element(nodes, "DIV", {}); | |
var div_nodes = children(div); | |
t = claim_text(div_nodes, "Test"); | |
div_nodes.forEach(detach); | |
}, | |
m(target, anchor) { | |
insert(target, div, anchor); | |
append(div, t); | |
}, | |
d(detaching) { | |
if (detaching) detach(div); | |
} | |
}; | |
} | |
function create_fragment(ctx) { | |
let t; | |
let div; | |
let if_block = create_if_block(); | |
return { | |
c() { | |
if (if_block) if_block.c(); | |
t = space(); | |
div = element("div"); | |
this.h(); | |
}, | |
l(nodes) { | |
if (if_block) if_block.l(nodes); | |
t = claim_space(nodes); | |
div = claim_element(nodes, "DIV", { id: true, class: true }); | |
children(div).forEach(detach); | |
this.h(); | |
}, | |
h() { | |
attr(div, "id", "a"); | |
attr(div, "class", "svelte-77u8jk"); | |
toggle_class(div, "yellow", yellow); | |
}, | |
m(target, anchor) { | |
if (if_block) if_block.m(target, anchor); | |
insert(target, t, anchor); | |
insert(target, div, anchor); | |
}, | |
p(ctx, [dirty]) { | |
if (dirty & /*yellow*/ 0) { | |
toggle_class(div, "yellow", yellow); | |
} | |
}, | |
i: noop, | |
o: noop, | |
d(detaching) { | |
if (if_block) if_block.d(detaching); | |
if (detaching) detach(t); | |
if (detaching) detach(div); | |
} | |
}; | |
} | |
let yellow = true; | |
class Test extends SvelteComponent { | |
constructor(options) { | |
super(); | |
init(this, options, null, create_fragment, safe_not_equal, {}); | |
} | |
} | |
return Test; | |
}()); | |
new Test({ | |
target: document.body, | |
hydrate: true, | |
}); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<style> | |
.yellow.svelte-77u8jk{background:yellow} | |
</style> | |
</head> | |
<body> | |
<div class="svelte-77u8jk yellow"></div> | |
<script> | |
var Test = (function () { | |
'use strict'; | |
function noop() { } | |
function run(fn) { | |
return fn(); | |
} | |
function blank_object() { | |
return Object.create(null); | |
} | |
function run_all(fns) { | |
fns.forEach(run); | |
} | |
function is_function(thing) { | |
return typeof thing === 'function'; | |
} | |
function safe_not_equal(a, b) { | |
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); | |
} | |
function append(target, node) { | |
target.appendChild(node); | |
} | |
function insert(target, node, anchor) { | |
target.insertBefore(node, anchor || null); | |
} | |
function detach(node) { | |
node.parentNode.removeChild(node); | |
} | |
function element(name) { | |
return document.createElement(name); | |
} | |
function svg_element(name) { | |
return document.createElementNS('http://www.w3.org/2000/svg', name); | |
} | |
function text(data) { | |
return document.createTextNode(data); | |
} | |
function space() { | |
return text(' '); | |
} | |
function attr(node, attribute, value) { | |
if (value == null) | |
node.removeAttribute(attribute); | |
else if (node.getAttribute(attribute) !== value) | |
node.setAttribute(attribute, value); | |
} | |
function children(element) { | |
return Array.from(element.childNodes); | |
} | |
function claim_element(nodes, name, attributes, svg) { | |
for (let i = 0; i < nodes.length; i += 1) { | |
const node = nodes[i]; | |
if (node.nodeName === name) { | |
for (let j = 0; j < node.attributes.length; j += 1) { | |
const attribute = node.attributes[j]; | |
if (!attributes[attribute.name]) | |
node.removeAttribute(attribute.name); | |
} | |
return nodes.splice(i, 1)[0]; // TODO strip unwanted attributes | |
} | |
} | |
return svg ? svg_element(name) : element(name); | |
} | |
function claim_text(nodes, data) { | |
for (let i = 0; i < nodes.length; i += 1) { | |
const node = nodes[i]; | |
if (node.nodeType === 3) { | |
node.data = '' + data; | |
return nodes.splice(i, 1)[0]; | |
} | |
} | |
return text(data); | |
} | |
function claim_space(nodes) { | |
return claim_text(nodes, ' '); | |
} | |
function toggle_class(element, name, toggle) { | |
element.classList[toggle ? 'add' : 'remove'](name); | |
} | |
let current_component; | |
function set_current_component(component) { | |
current_component = component; | |
} | |
const dirty_components = []; | |
const binding_callbacks = []; | |
const render_callbacks = []; | |
const flush_callbacks = []; | |
const resolved_promise = Promise.resolve(); | |
let update_scheduled = false; | |
function schedule_update() { | |
if (!update_scheduled) { | |
update_scheduled = true; | |
resolved_promise.then(flush); | |
} | |
} | |
function add_render_callback(fn) { | |
render_callbacks.push(fn); | |
} | |
function flush() { | |
const seen_callbacks = new Set(); | |
do { | |
// first, call beforeUpdate functions | |
// and update components | |
while (dirty_components.length) { | |
const component = dirty_components.shift(); | |
set_current_component(component); | |
update(component.$$); | |
} | |
while (binding_callbacks.length) | |
binding_callbacks.pop()(); | |
// then, once components are updated, call | |
// afterUpdate functions. This may cause | |
// subsequent updates... | |
for (let i = 0; i < render_callbacks.length; i += 1) { | |
const callback = render_callbacks[i]; | |
if (!seen_callbacks.has(callback)) { | |
callback(); | |
// ...so guard against infinite loops | |
seen_callbacks.add(callback); | |
} | |
} | |
render_callbacks.length = 0; | |
} while (dirty_components.length); | |
while (flush_callbacks.length) { | |
flush_callbacks.pop()(); | |
} | |
update_scheduled = false; | |
} | |
function update($$) { | |
if ($$.fragment !== null) { | |
$$.update(); | |
run_all($$.before_update); | |
const dirty = $$.dirty; | |
$$.dirty = [-1]; | |
$$.fragment && $$.fragment.p($$.ctx, dirty); | |
$$.after_update.forEach(add_render_callback); | |
} | |
} | |
const outroing = new Set(); | |
function transition_in(block, local) { | |
if (block && block.i) { | |
outroing.delete(block); | |
block.i(local); | |
} | |
} | |
function mount_component(component, target, anchor) { | |
const { fragment, on_mount, on_destroy, after_update } = component.$$; | |
fragment && fragment.m(target, anchor); | |
// onMount happens before the initial afterUpdate | |
add_render_callback(() => { | |
const new_on_destroy = on_mount.map(run).filter(is_function); | |
if (on_destroy) { | |
on_destroy.push(...new_on_destroy); | |
} | |
else { | |
// Edge case - component was destroyed immediately, | |
// most likely as a result of a binding initialising | |
run_all(new_on_destroy); | |
} | |
component.$$.on_mount = []; | |
}); | |
after_update.forEach(add_render_callback); | |
} | |
function destroy_component(component, detaching) { | |
const $$ = component.$$; | |
if ($$.fragment !== null) { | |
run_all($$.on_destroy); | |
$$.fragment && $$.fragment.d(detaching); | |
// TODO null out other refs, including component.$$ (but need to | |
// preserve final state?) | |
$$.on_destroy = $$.fragment = null; | |
$$.ctx = []; | |
} | |
} | |
function make_dirty(component, i) { | |
if (component.$$.dirty[0] === -1) { | |
dirty_components.push(component); | |
schedule_update(); | |
component.$$.dirty.fill(0); | |
} | |
component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31)); | |
} | |
function init(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) { | |
const parent_component = current_component; | |
set_current_component(component); | |
const prop_values = options.props || {}; | |
const $$ = component.$$ = { | |
fragment: null, | |
ctx: null, | |
// state | |
props, | |
update: noop, | |
not_equal, | |
bound: blank_object(), | |
// lifecycle | |
on_mount: [], | |
on_destroy: [], | |
before_update: [], | |
after_update: [], | |
context: new Map(parent_component ? parent_component.$$.context : []), | |
// everything else | |
callbacks: blank_object(), | |
dirty | |
}; | |
let ready = false; | |
$$.ctx = instance | |
? instance(component, prop_values, (i, ret, ...rest) => { | |
const value = rest.length ? rest[0] : ret; | |
if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) { | |
if ($$.bound[i]) | |
$$.bound[i](value); | |
if (ready) | |
make_dirty(component, i); | |
} | |
return ret; | |
}) | |
: []; | |
$$.update(); | |
ready = true; | |
run_all($$.before_update); | |
// `false` as a special case of no DOM component | |
$$.fragment = create_fragment ? create_fragment($$.ctx) : false; | |
if (options.target) { | |
if (options.hydrate) { | |
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | |
$$.fragment && $$.fragment.l(children(options.target)); | |
} | |
else { | |
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | |
$$.fragment && $$.fragment.c(); | |
} | |
if (options.intro) | |
transition_in(component.$$.fragment); | |
mount_component(component, options.target, options.anchor); | |
flush(); | |
} | |
set_current_component(parent_component); | |
} | |
class SvelteComponent { | |
$destroy() { | |
destroy_component(this, 1); | |
this.$destroy = noop; | |
} | |
$on(type, callback) { | |
const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = [])); | |
callbacks.push(callback); | |
return () => { | |
const index = callbacks.indexOf(callback); | |
if (index !== -1) | |
callbacks.splice(index, 1); | |
}; | |
} | |
$set() { | |
// overridden by instance, if it has props | |
} | |
} | |
/* pages/Test.html generated by Svelte v3.17.0 */ | |
function create_if_block(ctx) { | |
let div; | |
let t; | |
return { | |
c() { | |
div = element("div"); | |
t = text("Test"); | |
}, | |
l(nodes) { | |
div = claim_element(nodes, "DIV", {}); | |
var div_nodes = children(div); | |
t = claim_text(div_nodes, "Test"); | |
div_nodes.forEach(detach); | |
}, | |
m(target, anchor) { | |
insert(target, div, anchor); | |
append(div, t); | |
}, | |
d(detaching) { | |
if (detaching) detach(div); | |
} | |
}; | |
} | |
function create_fragment(ctx) { | |
let t; | |
let div; | |
let if_block = /*x*/ ctx[0] && create_if_block(); | |
return { | |
c() { | |
if (if_block) if_block.c(); | |
t = space(); | |
div = element("div"); | |
this.h(); | |
}, | |
l(nodes) { | |
if (if_block) if_block.l(nodes); | |
t = claim_space(nodes); | |
div = claim_element(nodes, "DIV", { class: true }); | |
children(div).forEach(detach); | |
this.h(); | |
}, | |
h() { | |
attr(div, "class", "svelte-77u8jk"); | |
toggle_class(div, "yellow", yellow); | |
}, | |
m(target, anchor) { | |
if (if_block) if_block.m(target, anchor); | |
insert(target, t, anchor); | |
insert(target, div, anchor); | |
}, | |
p(ctx, [dirty]) { | |
if (dirty & /*yellow*/ 0) { | |
toggle_class(div, "yellow", yellow); | |
} | |
}, | |
i: noop, | |
o: noop, | |
d(detaching) { | |
if (if_block) if_block.d(detaching); | |
if (detaching) detach(t); | |
if (detaching) detach(div); | |
} | |
}; | |
} | |
let yellow = true; | |
function instance($$self) { | |
let x = typeof window !== "undefined"; | |
return [x]; | |
} | |
class Test extends SvelteComponent { | |
constructor(options) { | |
super(); | |
init(this, options, instance, create_fragment, safe_not_equal, {}); | |
} | |
} | |
return Test; | |
}()); | |
new Test({ | |
target: document.body, | |
hydrate: true, | |
}); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<style> | |
.yellow.svelte-77u8jk{background:yellow} | |
</style> | |
</head> | |
<body> | |
<div> | |
</div> | |
<div id="a" class="svelte-77u8jk yellow"></div> | |
<script> | |
var Test = (function () { | |
'use strict'; | |
function noop() { } | |
function run(fn) { | |
return fn(); | |
} | |
function blank_object() { | |
return Object.create(null); | |
} | |
function run_all(fns) { | |
fns.forEach(run); | |
} | |
function is_function(thing) { | |
return typeof thing === 'function'; | |
} | |
function safe_not_equal(a, b) { | |
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); | |
} | |
function append(target, node) { | |
target.appendChild(node); | |
} | |
function insert(target, node, anchor) { | |
target.insertBefore(node, anchor || null); | |
} | |
function detach(node) { | |
node.parentNode.removeChild(node); | |
} | |
function element(name) { | |
return document.createElement(name); | |
} | |
function svg_element(name) { | |
return document.createElementNS('http://www.w3.org/2000/svg', name); | |
} | |
function text(data) { | |
return document.createTextNode(data); | |
} | |
function space() { | |
return text(' '); | |
} | |
function attr(node, attribute, value) { | |
if (value == null) | |
node.removeAttribute(attribute); | |
else if (node.getAttribute(attribute) !== value) | |
node.setAttribute(attribute, value); | |
} | |
function children(element) { | |
return Array.from(element.childNodes); | |
} | |
function claim_element(nodes, name, attributes, svg) { | |
for (let i = 0; i < nodes.length; i += 1) { | |
const node = nodes[i]; | |
if (node.nodeName === name) { | |
for (let j = 0; j < node.attributes.length; j += 1) { | |
const attribute = node.attributes[j]; | |
if (!attributes[attribute.name]) | |
node.removeAttribute(attribute.name); | |
} | |
return nodes.splice(i, 1)[0]; // TODO strip unwanted attributes | |
} | |
} | |
return svg ? svg_element(name) : element(name); | |
} | |
function claim_text(nodes, data) { | |
for (let i = 0; i < nodes.length; i += 1) { | |
const node = nodes[i]; | |
if (node.nodeType === 3) { | |
node.data = '' + data; | |
return nodes.splice(i, 1)[0]; | |
} | |
} | |
return text(data); | |
} | |
function claim_space(nodes) { | |
return claim_text(nodes, ' '); | |
} | |
function toggle_class(element, name, toggle) { | |
element.classList[toggle ? 'add' : 'remove'](name); | |
} | |
let current_component; | |
function set_current_component(component) { | |
current_component = component; | |
} | |
const dirty_components = []; | |
const binding_callbacks = []; | |
const render_callbacks = []; | |
const flush_callbacks = []; | |
const resolved_promise = Promise.resolve(); | |
let update_scheduled = false; | |
function schedule_update() { | |
if (!update_scheduled) { | |
update_scheduled = true; | |
resolved_promise.then(flush); | |
} | |
} | |
function add_render_callback(fn) { | |
render_callbacks.push(fn); | |
} | |
function flush() { | |
const seen_callbacks = new Set(); | |
do { | |
// first, call beforeUpdate functions | |
// and update components | |
while (dirty_components.length) { | |
const component = dirty_components.shift(); | |
set_current_component(component); | |
update(component.$$); | |
} | |
while (binding_callbacks.length) | |
binding_callbacks.pop()(); | |
// then, once components are updated, call | |
// afterUpdate functions. This may cause | |
// subsequent updates... | |
for (let i = 0; i < render_callbacks.length; i += 1) { | |
const callback = render_callbacks[i]; | |
if (!seen_callbacks.has(callback)) { | |
callback(); | |
// ...so guard against infinite loops | |
seen_callbacks.add(callback); | |
} | |
} | |
render_callbacks.length = 0; | |
} while (dirty_components.length); | |
while (flush_callbacks.length) { | |
flush_callbacks.pop()(); | |
} | |
update_scheduled = false; | |
} | |
function update($$) { | |
if ($$.fragment !== null) { | |
$$.update(); | |
run_all($$.before_update); | |
const dirty = $$.dirty; | |
$$.dirty = [-1]; | |
$$.fragment && $$.fragment.p($$.ctx, dirty); | |
$$.after_update.forEach(add_render_callback); | |
} | |
} | |
const outroing = new Set(); | |
function transition_in(block, local) { | |
if (block && block.i) { | |
outroing.delete(block); | |
block.i(local); | |
} | |
} | |
function mount_component(component, target, anchor) { | |
const { fragment, on_mount, on_destroy, after_update } = component.$$; | |
fragment && fragment.m(target, anchor); | |
// onMount happens before the initial afterUpdate | |
add_render_callback(() => { | |
const new_on_destroy = on_mount.map(run).filter(is_function); | |
if (on_destroy) { | |
on_destroy.push(...new_on_destroy); | |
} | |
else { | |
// Edge case - component was destroyed immediately, | |
// most likely as a result of a binding initialising | |
run_all(new_on_destroy); | |
} | |
component.$$.on_mount = []; | |
}); | |
after_update.forEach(add_render_callback); | |
} | |
function destroy_component(component, detaching) { | |
const $$ = component.$$; | |
if ($$.fragment !== null) { | |
run_all($$.on_destroy); | |
$$.fragment && $$.fragment.d(detaching); | |
// TODO null out other refs, including component.$$ (but need to | |
// preserve final state?) | |
$$.on_destroy = $$.fragment = null; | |
$$.ctx = []; | |
} | |
} | |
function make_dirty(component, i) { | |
if (component.$$.dirty[0] === -1) { | |
dirty_components.push(component); | |
schedule_update(); | |
component.$$.dirty.fill(0); | |
} | |
component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31)); | |
} | |
function init(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) { | |
const parent_component = current_component; | |
set_current_component(component); | |
const prop_values = options.props || {}; | |
const $$ = component.$$ = { | |
fragment: null, | |
ctx: null, | |
// state | |
props, | |
update: noop, | |
not_equal, | |
bound: blank_object(), | |
// lifecycle | |
on_mount: [], | |
on_destroy: [], | |
before_update: [], | |
after_update: [], | |
context: new Map(parent_component ? parent_component.$$.context : []), | |
// everything else | |
callbacks: blank_object(), | |
dirty | |
}; | |
let ready = false; | |
$$.ctx = instance | |
? instance(component, prop_values, (i, ret, ...rest) => { | |
const value = rest.length ? rest[0] : ret; | |
if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) { | |
if ($$.bound[i]) | |
$$.bound[i](value); | |
if (ready) | |
make_dirty(component, i); | |
} | |
return ret; | |
}) | |
: []; | |
$$.update(); | |
ready = true; | |
run_all($$.before_update); | |
// `false` as a special case of no DOM component | |
$$.fragment = create_fragment ? create_fragment($$.ctx) : false; | |
if (options.target) { | |
if (options.hydrate) { | |
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | |
$$.fragment && $$.fragment.l(children(options.target)); | |
} | |
else { | |
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | |
$$.fragment && $$.fragment.c(); | |
} | |
if (options.intro) | |
transition_in(component.$$.fragment); | |
mount_component(component, options.target, options.anchor); | |
flush(); | |
} | |
set_current_component(parent_component); | |
} | |
class SvelteComponent { | |
$destroy() { | |
destroy_component(this, 1); | |
this.$destroy = noop; | |
} | |
$on(type, callback) { | |
const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = [])); | |
callbacks.push(callback); | |
return () => { | |
const index = callbacks.indexOf(callback); | |
if (index !== -1) | |
callbacks.splice(index, 1); | |
}; | |
} | |
$set() { | |
// overridden by instance, if it has props | |
} | |
} | |
/* pages/Test.html generated by Svelte v3.17.0 */ | |
function create_if_block(ctx) { | |
let div; | |
let t; | |
return { | |
c() { | |
div = element("div"); | |
t = text("Test"); | |
}, | |
l(nodes) { | |
div = claim_element(nodes, "DIV", {}); | |
var div_nodes = children(div); | |
t = claim_text(div_nodes, "Test"); | |
div_nodes.forEach(detach); | |
}, | |
m(target, anchor) { | |
insert(target, div, anchor); | |
append(div, t); | |
}, | |
d(detaching) { | |
if (detaching) detach(div); | |
} | |
}; | |
} | |
function create_fragment(ctx) { | |
let div0; | |
let t; | |
let div1; | |
let if_block = /*x*/ ctx[0] && create_if_block(); | |
return { | |
c() { | |
div0 = element("div"); | |
if (if_block) if_block.c(); | |
t = space(); | |
div1 = element("div"); | |
this.h(); | |
}, | |
l(nodes) { | |
div0 = claim_element(nodes, "DIV", {}); | |
var div0_nodes = children(div0); | |
if (if_block) if_block.l(div0_nodes); | |
div0_nodes.forEach(detach); | |
t = claim_space(nodes); | |
div1 = claim_element(nodes, "DIV", { id: true, class: true }); | |
children(div1).forEach(detach); | |
this.h(); | |
}, | |
h() { | |
attr(div1, "id", "a"); | |
attr(div1, "class", "svelte-77u8jk"); | |
toggle_class(div1, "yellow", yellow); | |
}, | |
m(target, anchor) { | |
insert(target, div0, anchor); | |
if (if_block) if_block.m(div0, null); | |
insert(target, t, anchor); | |
insert(target, div1, anchor); | |
}, | |
p(ctx, [dirty]) { | |
if (dirty & /*yellow*/ 0) { | |
toggle_class(div1, "yellow", yellow); | |
} | |
}, | |
i: noop, | |
o: noop, | |
d(detaching) { | |
if (detaching) detach(div0); | |
if (if_block) if_block.d(); | |
if (detaching) detach(t); | |
if (detaching) detach(div1); | |
} | |
}; | |
} | |
let yellow = true; | |
function instance($$self) { | |
let x = typeof window !== "undefined"; | |
return [x]; | |
} | |
class Test extends SvelteComponent { | |
constructor(options) { | |
super(); | |
init(this, options, instance, create_fragment, safe_not_equal, {}); | |
} | |
} | |
return Test; | |
}()); | |
new Test({ | |
target: document.body, | |
hydrate: true, | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment