From e272736d064ccb46e1d13971d81c2c58f930dc39 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 13 Nov 2018 21:23:57 -0500 Subject: [PATCH] remove built internal.js from repo (replaces shared.js) --- .gitignore | 1 + internal.js | 615 ---------------------------------------------------- 2 files changed, 1 insertion(+), 615 deletions(-) delete mode 100644 internal.js diff --git a/.gitignore b/.gitignore index 472328464c..0c3b104cc2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ node_modules /compiler/ /ssr/ /shared.js +/internal.js /scratch/ /coverage/ /coverage.lcov/ diff --git a/internal.js b/internal.js deleted file mode 100644 index cdb0307058..0000000000 --- a/internal.js +++ /dev/null @@ -1,615 +0,0 @@ -function append(target, node) { - target.appendChild(node); -} - -function insert(target, node, anchor) { - target.insertBefore(node, anchor); -} - -function detachNode(node) { - node.parentNode.removeChild(node); -} - -function detachBetween(before, after) { - while (before.nextSibling && before.nextSibling !== after) { - before.parentNode.removeChild(before.nextSibling); - } -} - -function detachBefore(after) { - while (after.previousSibling) { - after.parentNode.removeChild(after.previousSibling); - } -} - -function detachAfter(before) { - while (before.nextSibling) { - before.parentNode.removeChild(before.nextSibling); - } -} - -function reinsertBetween(before, after, target) { - while (before.nextSibling && before.nextSibling !== after) { - target.appendChild(before.parentNode.removeChild(before.nextSibling)); - } -} - -function reinsertChildren(parent, target) { - while (parent.firstChild) target.appendChild(parent.firstChild); -} - -function reinsertAfter(before, target) { - while (before.nextSibling) target.appendChild(before.nextSibling); -} - -function reinsertBefore(after, target) { - var parent = after.parentNode; - while (parent.firstChild !== after) target.appendChild(parent.firstChild); -} - -function destroyEach(iterations, detach) { - for (var i = 0; i < iterations.length; i += 1) { - if (iterations[i]) iterations[i].d(detach); - } -} - -function createFragment() { - return document.createDocumentFragment(); -} - -function createElement(name) { - return document.createElement(name); -} - -function createSvgElement(name) { - return document.createElementNS('http://www.w3.org/2000/svg', name); -} - -function createText(data) { - return document.createTextNode(data); -} - -function createComment() { - return document.createComment(''); -} - -function addListener(node, event, handler, options) { - node.addEventListener(event, handler, options); -} - -function removeListener(node, event, handler, options) { - node.removeEventListener(event, handler, options); -} - -function setAttribute(node, attribute, value) { - if (value == null) node.removeAttribute(attribute); - else node.setAttribute(attribute, value); -} - -function setAttributes(node, attributes) { - for (var key in attributes) { - if (key === 'style') { - node.style.cssText = attributes[key]; - } else if (key in node) { - node[key] = attributes[key]; - } else { - setAttribute(node, key, attributes[key]); - } - } -} - -function setCustomElementData(node, prop, value) { - if (prop in node) { - node[prop] = value; - } else if (value) { - setAttribute(node, prop, value); - } else { - node.removeAttribute(prop); - } -} - -function setXlinkAttribute(node, attribute, value) { - node.setAttributeNS('http://www.w3.org/1999/xlink', attribute, value); -} - -function getBindingGroupValue(group) { - var value = []; - for (var i = 0; i < group.length; i += 1) { - if (group[i].checked) value.push(group[i].__value); - } - return value; -} - -function toNumber(value) { - return value === '' ? undefined : +value; -} - -function timeRangesToArray(ranges) { - var array = []; - for (var i = 0; i < ranges.length; i += 1) { - array.push({ start: ranges.start(i), end: ranges.end(i) }); - } - return array; -} - -function children (element) { - return Array.from(element.childNodes); -} - -function claimElement (nodes, name, attributes, svg) { - for (var i = 0; i < nodes.length; i += 1) { - var node = nodes[i]; - if (node.nodeName === name) { - for (var j = 0; j < node.attributes.length; j += 1) { - var attribute = node.attributes[j]; - if (!attributes[attribute.name]) node.removeAttribute(attribute.name); - } - return nodes.splice(i, 1)[0]; // TODO strip unwanted attributes - } - } - - return svg ? createSvgElement(name) : createElement(name); -} - -function claimText (nodes, data) { - for (var i = 0; i < nodes.length; i += 1) { - var node = nodes[i]; - if (node.nodeType === 3) { - node.data = data; - return nodes.splice(i, 1)[0]; - } - } - - return createText(data); -} - -function setData(text, data) { - text.data = '' + data; -} - -function setInputType(input, type) { - try { - input.type = type; - } catch (e) {} -} - -function setStyle(node, key, value) { - node.style.setProperty(key, value); -} - -function selectOption(select, value) { - for (var i = 0; i < select.options.length; i += 1) { - var option = select.options[i]; - - if (option.__value === value) { - option.selected = true; - return; - } - } -} - -function selectOptions(select, value) { - for (var i = 0; i < select.options.length; i += 1) { - var option = select.options[i]; - option.selected = ~value.indexOf(option.__value); - } -} - -function selectValue(select) { - var selectedOption = select.querySelector(':checked') || select.options[0]; - return selectedOption && selectedOption.__value; -} - -function selectMultipleValue(select) { - return [].map.call(select.querySelectorAll(':checked'), function(option) { - return option.__value; - }); -} - -function addResizeListener(element, fn) { - if (getComputedStyle(element).position === 'static') { - element.style.position = 'relative'; - } - - const object = document.createElement('object'); - object.setAttribute('style', 'display: block; position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1;'); - object.type = 'text/html'; - - let win; - - object.onload = () => { - win = object.contentDocument.defaultView; - win.addEventListener('resize', fn); - }; - - if (/Trident/.test(navigator.userAgent)) { - element.appendChild(object); - object.data = 'about:blank'; - } else { - object.data = 'about:blank'; - element.appendChild(object); - } - - return { - cancel: () => { - win && win.removeEventListener && win.removeEventListener('resize', fn); - element.removeChild(object); - } - }; -} - -function toggleClass(element, name, toggle) { - element.classList.toggle(name, !!toggle); -} - -let update_scheduled = false; - -const dirty_components = []; - -function schedule_update(component) { - dirty_components.push(component); - if (!update_scheduled) { - update_scheduled = true; - queueMicrotask(flush); - } -} - -function flush() { - while (dirty_components.length) { - dirty_components.pop().__update(); - } - - update_scheduled = false; -} - -function queueMicrotask(callback) { - Promise.resolve().then(callback); -} - -function noop() {} - -function assign(tar, src) { - for (var k in src) tar[k] = src[k]; - return tar; -} - -function assignTrue(tar, src) { - for (var k in src) tar[k] = 1; - return tar; -} - -function isPromise(value) { - return value && typeof value.then === 'function'; -} - -function callAfter(fn, i) { - if (i === 0) fn(); - return () => { - if (!--i) fn(); - }; -} - -function addLoc(element, file, line, column, char) { - element.__svelte_meta = { - loc: { file, line, column, char } - }; -} - -function exclude(src, prop) { - const tar = {}; - for (const k in src) k === prop || (tar[k] = src[k]); - return tar; -} - -function run(fn) { - fn(); -} - -function linear(t) { - return t; -} - -function generateRule({ a, b, delta, duration }, ease, fn) { - const step = 16.666 / duration; - let keyframes = '{\n'; - - for (let p = 0; p <= 1; p += step) { - const t = a + delta * ease(p); - keyframes += p * 100 + `%{${fn(t, 1 - t)}}\n`; - } - - return keyframes + `100% {${fn(b, 1 - b)}}\n}`; -} - -// https://github.com/darkskyapp/string-hash/blob/master/index.js -function hash(str) { - let hash = 5381; - let i = str.length; - - while (i--) hash = ((hash << 5) - hash) ^ str.charCodeAt(i); - return hash >>> 0; -} - -function wrapTransition(component, node, fn, params, intro) { - let obj = fn.call(component, node, params); - let duration; - let ease; - let cssText; - - let initialised = false; - - return { - t: intro ? 0 : 1, - running: false, - program: null, - pending: null, - - run(b, callback) { - if (typeof obj === 'function') { - transitionManager.wait().then(() => { - obj = obj(); - this._run(b, callback); - }); - } else { - this._run(b, callback); - } - }, - - _run(b, callback) { - duration = obj.duration || 300; - ease = obj.easing || linear; - - const program = { - start: window.performance.now() + (obj.delay || 0), - b, - callback: callback || noop - }; - - if (intro && !initialised) { - if (obj.css && obj.delay) { - cssText = node.style.cssText; - node.style.cssText += obj.css(0, 1); - } - - if (obj.tick) obj.tick(0, 1); - initialised = true; - } - - if (!b) { - program.group = outros.current; - outros.current.remaining += 1; - } - - if (obj.delay) { - this.pending = program; - } else { - this.start(program); - } - - if (!this.running) { - this.running = true; - transitionManager.add(this); - } - }, - - start(program) { - component.fire(`${program.b ? 'intro' : 'outro'}.start`, { node }); - - program.a = this.t; - program.delta = program.b - program.a; - program.duration = duration * Math.abs(program.b - program.a); - program.end = program.start + program.duration; - - if (obj.css) { - if (obj.delay) node.style.cssText = cssText; - - const rule = generateRule(program, ease, obj.css); - transitionManager.addRule(rule, program.name = '__svelte_' + hash(rule)); - - node.style.animation = (node.style.animation || '') - .split(', ') - .filter(anim => anim && (program.delta < 0 || !/__svelte/.test(anim))) - .concat(`${program.name} ${program.duration}ms linear 1 forwards`) - .join(', '); - } - - this.program = program; - this.pending = null; - }, - - update(now) { - const program = this.program; - if (!program) return; - - const p = now - program.start; - this.t = program.a + program.delta * ease(p / program.duration); - if (obj.tick) obj.tick(this.t, 1 - this.t); - }, - - done() { - const program = this.program; - this.t = program.b; - - if (obj.tick) obj.tick(this.t, 1 - this.t); - - component.fire(`${program.b ? 'intro' : 'outro'}.end`, { node }); - - if (!program.b && !program.invalidated) { - program.group.callbacks.push(() => { - program.callback(); - if (obj.css) transitionManager.deleteRule(node, program.name); - }); - - if (--program.group.remaining === 0) { - program.group.callbacks.forEach(run); - } - } else { - if (obj.css) transitionManager.deleteRule(node, program.name); - } - - this.running = !!this.pending; - }, - - abort(reset) { - if (this.program) { - if (reset && obj.tick) obj.tick(1, 0); - if (obj.css) transitionManager.deleteRule(node, this.program.name); - this.program = this.pending = null; - this.running = false; - } - }, - - invalidate() { - if (this.program) { - this.program.invalidated = true; - } - } - }; -} - -let outros = {}; - -function groupOutros() { - outros.current = { - remaining: 0, - callbacks: [] - }; -} - -var transitionManager = { - running: false, - transitions: [], - bound: null, - stylesheet: null, - activeRules: {}, - promise: null, - - add(transition) { - this.transitions.push(transition); - - if (!this.running) { - this.running = true; - requestAnimationFrame(this.bound || (this.bound = this.next.bind(this))); - } - }, - - addRule(rule, name) { - if (!this.stylesheet) { - const style = createElement('style'); - document.head.appendChild(style); - transitionManager.stylesheet = style.sheet; - } - - if (!this.activeRules[name]) { - this.activeRules[name] = true; - this.stylesheet.insertRule(`@keyframes ${name} ${rule}`, this.stylesheet.cssRules.length); - } - }, - - next() { - this.running = false; - - const now = window.performance.now(); - let i = this.transitions.length; - - while (i--) { - const transition = this.transitions[i]; - - if (transition.program && now >= transition.program.end) { - transition.done(); - } - - if (transition.pending && now >= transition.pending.start) { - transition.start(transition.pending); - } - - if (transition.running) { - transition.update(now); - this.running = true; - } else if (!transition.pending) { - this.transitions.splice(i, 1); - } - } - - if (this.running) { - requestAnimationFrame(this.bound); - } else if (this.stylesheet) { - let i = this.stylesheet.cssRules.length; - while (i--) this.stylesheet.deleteRule(i); - this.activeRules = {}; - } - }, - - deleteRule(node, name) { - node.style.animation = node.style.animation - .split(', ') - .filter(anim => anim && anim.indexOf(name) === -1) - .join(', '); - }, - - wait() { - if (!transitionManager.promise) { - transitionManager.promise = Promise.resolve(); - transitionManager.promise.then(() => { - transitionManager.promise = null; - }); - } - - return transitionManager.promise; - } -}; - -class SvelteComponent { - constructor(options) { - this.__get_state = this.__init( - fn => this.__inject_props = fn - ); - - this.__dirty = null; - - if (options.props) { - this.__inject_props(options.props); - } - - if (options.target) { - this.__mount(options.target); - } - } - - $on(eventName, callback) { - - } - - $destroy() { - this.__destroy(true); - } - - __make_dirty() { - if (this.__dirty) return; - this.__dirty = {}; - schedule_update(this); - } - - __mount(target, anchor) { - this.__fragment = this.__create_fragment(this.__get_state()); - this.__fragment.c(); - this.__fragment.m(target, anchor); - } - - __set(key, value) { - this.__inject_props({ [key]: value }); - this.__make_dirty(); - this.__dirty[key] = true; - } - - __update() { - this.__fragment.p(this.__dirty, this.__get_state()); - this.__dirty = null; - } - - __destroy(detach) { - this.__fragment.d(detach); - } -} - -export { append, insert, detachNode, detachBetween, detachBefore, detachAfter, reinsertBetween, reinsertChildren, reinsertAfter, reinsertBefore, destroyEach, createFragment, createElement, createSvgElement, createText, createComment, addListener, removeListener, setAttribute, setAttributes, setCustomElementData, setXlinkAttribute, getBindingGroupValue, toNumber, timeRangesToArray, children, claimElement, claimText, setData, setInputType, setStyle, selectOption, selectOptions, selectValue, selectMultipleValue, addResizeListener, toggleClass, schedule_update, flush, linear, generateRule, hash, wrapTransition, outros, groupOutros, transitionManager, noop, assign, assignTrue, isPromise, callAfter, addLoc, exclude, run, SvelteComponent };