Comparing version 2.0.0-alpha.2 to 2.0.0-alpha.3
@@ -190,3 +190,27 @@ import createTag from 'vdom-tag'; | ||
function _objectEntries(obj) { | ||
var flatMap = curry(function (f, xs) { | ||
return xs.reduce(function (acc, x) { | ||
return acc.concat(f(x)); | ||
}, []); | ||
}); | ||
var flatten = flatMap(function (x) { | ||
return x; | ||
}); | ||
var noOp = function noOp() {}; | ||
var createDefaultLifecycle = function createDefaultLifecycle() { | ||
return { | ||
mount: noOp, | ||
update: noOp, | ||
unmount: noOp | ||
}; | ||
}; | ||
var isEmpty = function isEmpty(x) { | ||
return x !== 0 && (!x || typeof x === 'string' && !x.trim()) || Array.isArray(x) && !x.length; | ||
}; | ||
function _objectEntries$1(obj) { | ||
var entries = []; | ||
@@ -200,3 +224,3 @@ var keys = Object.keys(obj); | ||
function _objectEntries(obj) { | ||
function _objectEntries$1(obj) { | ||
var entries = []; | ||
@@ -221,3 +245,3 @@ var keys = Object.keys(obj); | ||
var pickBy = curry(function (predicate, obj) { | ||
return fromEntries(_objectEntries(obj).filter(function (_ref3) { | ||
return fromEntries(_objectEntries$1(obj).filter(function (_ref3) { | ||
var _ref4 = slicedToArray(_ref3, 2), | ||
@@ -467,61 +491,117 @@ key = _ref4[0], | ||
var noOp = function noOp() {}; | ||
function _objectEntries(obj) { | ||
var entries = []; | ||
var keys = Object.keys(obj); | ||
var createDefaultLifecycle = function createDefaultLifecycle() { | ||
return { | ||
mount: noOp, | ||
update: noOp, | ||
unmount: noOp | ||
}; | ||
}; | ||
for (var k = 0; k < keys.length; ++k) entries.push([keys[k], obj[keys[k]]]); | ||
var isEmpty = function isEmpty(x) { | ||
return x !== 0 && (!x || typeof x === 'string' && !x.trim()) || Array.isArray(x) && !x.length; | ||
}; | ||
return entries; | ||
} | ||
var hasContent = function hasContent(xs) { | ||
return !xs.length || !xs.every(isEmpty); | ||
function _objectEntries(obj) { | ||
var entries = []; | ||
var keys = Object.keys(obj); | ||
for (var k = 0; k < keys.length; ++k) entries.push([keys[k], obj[keys[k]]]); | ||
return entries; | ||
} | ||
var isLifecycle = function isLifecycle(key) { | ||
return ['mount', 'update', 'unmount'].includes(key); | ||
}; | ||
var isEvent = function isEvent(key) { | ||
return !!key.match(/^on/); | ||
}; | ||
var toEventName = function toEventName(key) { | ||
return key.replace(/^on/, '').toLowerCase(); | ||
}; | ||
// data Variable a | ||
// = a | ||
// | Promise (Variable a) | ||
// | Observable (Variable a) | ||
// | [Variable a] | ||
var styleToObject = function styleToObject(styleStr) { | ||
return styleStr.split(';').reduce(function (acc, str) { | ||
var _str$split = str.split(/:/), | ||
_str$split2 = toArray(_str$split), | ||
k = _str$split2[0], | ||
v = _str$split2.slice(1); | ||
// flatten :: Variable a -> Observable a | ||
var flatten = function flatten(variable) { | ||
return Array.isArray(variable) ? all(variable.map(compose(startWith(''), flatten))).pipe(filter(hasContent)) : isObservable(variable) ? switchMap(flatten, variable) : isPromise(variable) ? switchMap(flatten, from(variable)) : toObservable(variable); | ||
if (k.trim()) acc[k.trim()] = v.join(':'); | ||
return acc; | ||
}, {}); | ||
}; | ||
var sharedRaf = share()(raf); | ||
var formatChildren = flatMap(function (c) { | ||
return Array.isArray(c) ? formatChildren(c) : isEmpty(c) ? [] : ['VNode', 'VText', 'VPatch', 'Component'].some(function (type) { | ||
return c.type === type; | ||
}) ? [c] : isObservable(c) || isPromise(c) ? [{ | ||
type: 'Component', | ||
name: function AnonymousComponent() { | ||
return flip(c).pipe(map(function (child) { | ||
return formatChildren([child]); | ||
}), map(function (children) { | ||
return children.length === 1 ? children[0] : children; | ||
}), filter(function (x) { | ||
return !isEmpty(x); | ||
})); | ||
}, | ||
untouchedAttributes: { children: [] } | ||
}] : [{ type: 'VText', text: c }]; | ||
}); | ||
// createReactiveTag | ||
// :: ([String] -> ...[Variable a] -> b) | ||
// -> [String] | ||
// -> ...[Variable a] | ||
// -> Observable b | ||
var createReactiveTag = function createReactiveTag(tagFunction) { | ||
return function (strings) { | ||
for (var _len = arguments.length, variables = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
variables[_key - 1] = arguments[_key]; | ||
function h(name, _attributes) { | ||
var attributes = _attributes || {}; | ||
for (var _len = arguments.length, _children = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
_children[_key - 2] = arguments[_key]; | ||
} | ||
var children = _children.reduce(function (acc, x) { | ||
return acc.concat(x); | ||
}, []); | ||
if (typeof name === 'function') { | ||
return { | ||
type: 'Component', | ||
name: name, | ||
untouchedAttributes: _extends({}, attributes, { children: children }) | ||
}; | ||
} | ||
var _Object$entries$reduc = _objectEntries(attributes).reduce(function (acc, _ref) { | ||
var _ref2 = slicedToArray(_ref, 2), | ||
key = _ref2[0], | ||
value = _ref2[1]; | ||
if (key === 'key') { | ||
acc.key = value; | ||
} else if (isLifecycle(key) && typeof value === 'function') { | ||
acc.lifecycle[key] = value; | ||
} else if (isEvent(key) && typeof value === 'function') { | ||
acc.events[toEventName(key)] = value; | ||
} else if (key === 'style') { | ||
acc.attrs[key] = (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' ? value : styleToObject(value); | ||
} else { | ||
acc.attrs[key] = value; | ||
} | ||
return acc; | ||
}, { lifecycle: createDefaultLifecycle(), events: {}, attrs: {} }), | ||
key = _Object$entries$reduc.key, | ||
lifecycle = _Object$entries$reduc.lifecycle, | ||
events = _Object$entries$reduc.events, | ||
attrs = _Object$entries$reduc.attrs; | ||
return flatten(variables).pipe(blockComplete(), startWith([]), sample(sharedRaf), map(function (variables) { | ||
return tagFunction.apply(undefined, [strings].concat(toConsumableArray(variables))); | ||
})); | ||
return { | ||
type: 'VNode', | ||
name: name, | ||
attrs: attrs, | ||
lifecycle: lifecycle, | ||
events: events, | ||
children: formatChildren(children), | ||
key: key | ||
}; | ||
}; | ||
} | ||
var flatMap = curry(function (f, xs) { | ||
return xs.reduce(function (acc, x) { | ||
return acc.concat(f(x)); | ||
}, []); | ||
}); | ||
// html :: [String] -> ...[Variable a] -> VirtualDOM | ||
var html$1 = createTag(h); | ||
var flatten$1 = flatMap(function (x) { | ||
return x; | ||
}); | ||
function _objectEntries$1(obj) { | ||
function _objectEntries$2(obj) { | ||
var entries = []; | ||
@@ -535,3 +615,3 @@ var keys = Object.keys(obj); | ||
function _objectEntries$1(obj) { | ||
function _objectEntries$2(obj) { | ||
var entries = []; | ||
@@ -545,6 +625,6 @@ var keys = Object.keys(obj); | ||
var sharedRaf$1 = share()(raf); | ||
var sharedRaf = share()(raf); | ||
var toStream = function toStream(component) { | ||
return flip(component).pipe(sample(sharedRaf$1)); | ||
return flip(component).pipe(sample(sharedRaf)); | ||
}; | ||
@@ -685,3 +765,3 @@ | ||
try { | ||
for (var _iterator = _objectEntries$1(vTree.events)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
for (var _iterator = _objectEntries$2(vTree.events)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var _ref3 = _step.value; | ||
@@ -716,3 +796,3 @@ | ||
var removedEventsEntries = _objectEntries$1(previousEvents).filter(function (_ref5) { | ||
var removedEventsEntries = _objectEntries$2(previousEvents).filter(function (_ref5) { | ||
var _ref6 = slicedToArray(_ref5, 1), | ||
@@ -780,4 +860,4 @@ key = _ref6[0]; | ||
var updateChildren = function updateChildren(node, previousChildren, children, isSvg, context) { | ||
var flatChildren = flatten$1(children); | ||
var flatPreviousChildren = flatten$1(previousChildren); | ||
var flatChildren = flatten(children); | ||
var flatPreviousChildren = flatten(previousChildren); | ||
for (var index in flatChildren) { | ||
@@ -860,3 +940,3 @@ var childTree = flatChildren[index]; | ||
value: function removeElement(node) { | ||
flatten$1(this.children).map(function (child, index) { | ||
flatten(this.children).map(function (child, index) { | ||
return _removeElement(child, node.childNodes[index]); | ||
@@ -870,3 +950,3 @@ }); | ||
value: function mount(node) { | ||
flatten$1(this.children).map(function (child) { | ||
flatten(this.children).map(function (child) { | ||
return _mount(child); | ||
@@ -1087,151 +1167,25 @@ }); | ||
function _objectEntries$2(obj) { | ||
var entries = []; | ||
var keys = Object.keys(obj); | ||
for (var k = 0; k < keys.length; ++k) entries.push([keys[k], obj[keys[k]]]); | ||
return entries; | ||
} | ||
function _objectEntries$2(obj) { | ||
var entries = []; | ||
var keys = Object.keys(obj); | ||
for (var k = 0; k < keys.length; ++k) entries.push([keys[k], obj[keys[k]]]); | ||
return entries; | ||
} | ||
var isLifecycle = function isLifecycle(key) { | ||
return ['mount', 'update', 'unmount'].includes(key); | ||
var hasContent = function hasContent(xs) { | ||
return !xs.length || !xs.every(isEmpty); | ||
}; | ||
var isEvent = function isEvent(key) { | ||
return !!key.match(/^on/); | ||
}; | ||
var toEventName = function toEventName(key) { | ||
return key.replace(/^on/, '').toLowerCase(); | ||
}; | ||
var styleToObject = function styleToObject(styleStr) { | ||
return styleStr.split(';').reduce(function (acc, str) { | ||
var _str$split = str.split(/:/), | ||
_str$split2 = toArray(_str$split), | ||
k = _str$split2[0], | ||
v = _str$split2.slice(1); | ||
// data Variable a | ||
// = a | ||
// | Promise (Variable a) | ||
// | Observable (Variable a) | ||
// | [Variable a] | ||
if (k.trim()) acc[k.trim()] = v.join(':'); | ||
return acc; | ||
}, {}); | ||
// flatten :: Variable a -> Observable a | ||
var flatten$1 = function flatten(variable) { | ||
return Array.isArray(variable) ? all(variable.map(compose(startWith(''), flatten))).pipe(filter(hasContent)) : isObservable(variable) ? switchMap(flatten, variable) : isPromise(variable) ? switchMap(flatten, from(variable)) : toObservable(variable); | ||
}; | ||
var formatChildren = flatMap(function (c) { | ||
return Array.isArray(c) ? formatChildren(c) : isEmpty(c) ? [] : ['VNode', 'VText', 'VPatch', 'Component'].some(function (type) { | ||
return c.type === type; | ||
}) ? [c] : isObservable(c) || isPromise(c) ? [{ | ||
type: 'Component', | ||
name: function AnonymousComponent() { | ||
return flip(c).pipe(map(function (child) { | ||
return formatChildren([child]); | ||
}), map(function (children) { | ||
return children.length === 1 ? children[0] : children; | ||
}), filter(function (x) { | ||
return !isEmpty(x); | ||
})); | ||
}, | ||
untouchedAttributes: { children: [] } | ||
}] : [{ type: 'VText', text: c }]; | ||
}); | ||
var sharedRaf$1 = share()(raf); | ||
function h(name, _attributes) { | ||
var attributes = _attributes || {}; | ||
for (var _len = arguments.length, _children = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
_children[_key - 2] = arguments[_key]; | ||
} | ||
var children = _children.reduce(function (acc, x) { | ||
return acc.concat(x); | ||
}, []); | ||
if (typeof name === 'function') { | ||
return { | ||
type: 'Component', | ||
name: name, | ||
untouchedAttributes: _extends({}, attributes, { children: children }) | ||
}; | ||
} | ||
var _Object$entries$reduc = _objectEntries$2(attributes).reduce(function (acc, _ref) { | ||
var _ref2 = slicedToArray(_ref, 2), | ||
key = _ref2[0], | ||
value = _ref2[1]; | ||
if (key === 'key') { | ||
acc.key = value; | ||
} else if (isLifecycle(key) && typeof value === 'function') { | ||
acc.lifecycle[key] = value; | ||
} else if (isEvent(key) && typeof value === 'function') { | ||
acc.events[toEventName(key)] = value; | ||
} else if (key === 'style') { | ||
acc.attrs[key] = (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' ? value : styleToObject(value); | ||
} else { | ||
acc.attrs[key] = value; | ||
} | ||
return acc; | ||
}, { lifecycle: createDefaultLifecycle(), events: {}, attrs: {} }), | ||
key = _Object$entries$reduc.key, | ||
lifecycle = _Object$entries$reduc.lifecycle, | ||
events = _Object$entries$reduc.events, | ||
attrs = _Object$entries$reduc.attrs; | ||
return { | ||
type: 'VNode', | ||
name: name, | ||
attrs: attrs, | ||
lifecycle: lifecycle, | ||
events: events, | ||
children: formatChildren(children), | ||
key: key | ||
}; | ||
} | ||
var createRenderProcess = function createRenderProcess(vdom$) { | ||
return new Observable(function (observer) { | ||
var domNode = void 0; | ||
var previousTree = void 0; | ||
var isSvg = void 0; | ||
return vdom$.subscribe({ | ||
complete: function complete() { | ||
return observer.complete(); | ||
}, | ||
error: function error(e) { | ||
return observer.error(e); | ||
}, | ||
next: function next(vTree) { | ||
if (!(vTree instanceof VNode)) return observer.next(vTree); | ||
var onMount = vTree.lifecycle.mount; | ||
vTree.lifecycle.mount = function (node, _isSvg) { | ||
domNode = node; | ||
isSvg = _isSvg; | ||
onMount(node); | ||
}; | ||
if (!domNode) { | ||
observer.next(vTree); | ||
} else { | ||
domNode = patch(domNode, previousTree, vTree, isSvg); | ||
observer.next(new VPatch({ vTree: vTree })); | ||
} | ||
previousTree = vTree; | ||
} | ||
}); | ||
}); | ||
}; | ||
var toRenderProcess = function toRenderProcess(tag) { | ||
// createReactiveTag | ||
// :: ([String] -> ...[Variable a] -> b) | ||
// -> [String] | ||
// -> ...[Variable a] | ||
// -> Observable b | ||
var createReactiveTag = function createReactiveTag(tagFunction) { | ||
return function (strings) { | ||
@@ -1242,9 +1196,8 @@ for (var _len = arguments.length, variables = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
return createRenderProcess(tag.apply(undefined, [strings].concat(variables))); | ||
return flatten$1(variables).pipe(blockComplete(), startWith([]), sample(sharedRaf$1), map(function (variables) { | ||
return tagFunction.apply(undefined, [strings].concat(toConsumableArray(variables))); | ||
})); | ||
}; | ||
}; | ||
// html :: [String] -> ...[Variable a] -> Observable VirtualDOM | ||
var html$1 = toRenderProcess(createReactiveTag(createTag(h))); | ||
// textTag :: [String] -> ...[a] -> String | ||
@@ -1251,0 +1204,0 @@ var textTag = function textTag(strings) { |
@@ -1,1 +0,1 @@ | ||
import createTag from"vdom-tag";import{BehaviorSubject,Observable,combineLatest,from,of}from"rxjs";import{filter,map,share,shareReplay,startWith}from"rxjs/operators";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),defineProperty=function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e},_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},slicedToArray=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],n=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(n=(a=u.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){o=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),toArray=function(e){return Array.isArray(e)?e:Array.from(e)},toConsumableArray=function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)},compose=function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return function(e){return t.reduceRight(function(e,t){return t(e)},e)}},curry=function e(t){return function(){for(var r=arguments.length,n=Array(r),o=0;o<r;o++)n[o]=arguments[o];return n.length>=t.length?t.apply(void 0,n):function(){for(var r=arguments.length,o=Array(r),i=0;i<r;i++)o[i]=arguments[i];return e(t).apply(void 0,n.concat(o))}}};function _objectEntries(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}function _objectEntries(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}var fromEntries=function(e){return e.reduce(function(e,t){var r=slicedToArray(t,2),n=r[0],o=r[1];return _extends({},e,defineProperty({},n,o))},{})},pickBy=curry(function(e,t){return fromEntries(_objectEntries(t).filter(function(t){var r=slicedToArray(t,2),n=r[0],o=r[1];return e(o,n)}))}),mapValues=curry(function(e,t){return Object.keys(t).reduce(function(r,n){return _extends({},r,defineProperty({},n,e(t[n],n)))},{})}),isObject=function(e){return"object"===(void 0===e?"undefined":_typeof(e))&&null!==e};function _objectValues(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push(e[r[n]]);return t}function _objectValues(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push(e[r[n]]);return t}var isPromise=function(e){return e&&"function"==typeof e.then},isObservable=function(e){return e&&"function"==typeof e.subscribe},toObservable=function(e){return isObservable(e)?e:of(e)},switchMap=curry(function(e,t){var r=void 0;return new Observable(function(n){var o=!1,i=!1,a=t.subscribe({next:function(t){r&&r.unsubscribe(),r=e(t).subscribe({error:function(e){return n.error(e)},next:function(e){return n.next(e)},complete:function(){i=!0,o&&n.complete()}})},error:function(e){return n.error(e)},complete:function(){o=!0,i&&n.complete()}});return{unsubscribe:function(){r&&r.unsubscribe(),a.unsubscribe()}}})}),all=function(e){return e.length?combineLatest.apply(void 0,toConsumableArray(e.map(toObservable)).concat([function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return t}])):of([])},combineLatestObject=function(e){var t=Object.keys(e);return t.length?combineLatest.apply(void 0,toConsumableArray(t.map(function(t){return toObservable(e[t]).pipe(map(function(e){return[t,e]}))})).concat([function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.reduce(function(e,t){var r=slicedToArray(t,2),n=r[0],o=r[1];return _extends({},e,defineProperty({},n,o))},{})}])):of(e)},blockComplete=function(){return function(e){return new Observable(function(t){return e.subscribe({complete:function(){},next:function(e){return t.next(e)},error:function(e){return t.error(e)}})})}},sample=curry(function(e,t){var r=Symbol("None");return new Observable(function(n){var o=r,i=t.subscribe({next:function(e){o=e},complete:function(){},error:function(e){return n.error(e)}}),a=e.subscribe({next:function(){o!==r&&(n.next(o),o=r)},complete:function(){return n.complete()},error:function(e){return n.error(e)}});return{unsubscribe:function(){i.unsubscribe(),a.unsubscribe()}}})}),raf=new Observable(function(e){var t=!0;return window.requestAnimationFrame(function r(){t&&(e.next(),window.requestAnimationFrame(r))}),{unsubscribe:function(){t=!1}}}),applyIf=curry(function(e,t,r){return e(r)?t(r):r}),ifObservable=applyIf(isObservable),allIfObservable=applyIf(function(e){return e.some(isObservable)},all),combineLatestObjectIfObservable=applyIf(function(e){return _objectValues(e).some(isObservable)},combineLatestObject),defaultWith=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:32;return function(r){return new Observable(function(n){var o=setTimeout(function(){return n.next(e)},t);return r.subscribe({next:function(e){clearTimeout(o),n.next(e)},complete:function(){clearTimeout(o),n.complete()},error:function(e){clearTimeout(o),n.error(e)}})})}},_flip=function e(t){return isObservable(t)?switchMap(compose(toObservable,e))(t):isPromise(t)?switchMap(compose(toObservable,e))(from(t)):Array.isArray(t)?allIfObservable(t.map(compose(ifObservable(defaultWith(void 0)),e))):isObject(t)?"Component"===t.type?t:combineLatestObjectIfObservable(mapValues(compose(ifObservable(defaultWith(void 0)),e),t)):t},flip=function(e){return toObservable(_flip(e))},noOp=function(){},createDefaultLifecycle=function(){return{mount:noOp,update:noOp,unmount:noOp}},isEmpty=function(e){return 0!==e&&(!e||"string"==typeof e&&!e.trim())||Array.isArray(e)&&!e.length},hasContent=function(e){return!e.length||!e.every(isEmpty)},flatten=function e(t){return Array.isArray(t)?all(t.map(compose(startWith(""),e))).pipe(filter(hasContent)):isObservable(t)?switchMap(e,t):isPromise(t)?switchMap(e,from(t)):toObservable(t)},sharedRaf=share()(raf),createReactiveTag=function(e){return function(t){for(var r=arguments.length,n=Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return flatten(n).pipe(blockComplete(),startWith([]),sample(sharedRaf),map(function(r){return e.apply(void 0,[t].concat(toConsumableArray(r)))}))}},flatMap=curry(function(e,t){return t.reduce(function(t,r){return t.concat(e(r))},[])}),flatten$1=flatMap(function(e){return e});function _objectEntries$1(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}function _objectEntries$1(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}var sharedRaf$1=share()(raf),toStream=function(e){return flip(e).pipe(sample(sharedRaf$1))},render=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=n.isSvg,i=void 0!==o&&o,a=n.morphNode,u=void 0!==a&&a?t:t.firstChild,c=void 0,s="function"==typeof e?e(r):e,l=toStream(s).subscribe({next:function(e){"VPatch"===e.type?c=e.vTree:Array.isArray(e)?(updateChildren(u||(u=t),c||[],e,i,r),c=e):(u?u=patch(u,c,e,i,r):(u=_createElement(e,i,r),t.innerHTML="",t.appendChild(u)),c=e)}});return{unsubscribe:function(){c&&(Array.isArray(c)?updateChildren(u,c,[],i,r):_removeElement(c,u)),l.unsubscribe()}}},VText=function(){function e(t){var r=t.text;classCallCheck(this,e),this.type="VText",this.text=r}return createClass(e,[{key:"createElement",value:function(){return document.createTextNode(this.text)}},{key:"updateElement",value:function(e,t){t.text!==this.text&&(e.textContent=this.text)}},{key:"removeElement",value:function(){}},{key:"mount",value:function(){}}]),e}();function isShallowEqual(e,t){for(var r in e)if(!(r in t)||e[r]!==t[r])return!1;for(var n in t)if(!(n in e)||e[n]!==t[n])return!1;return!0}var updateStyle=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};for(var n in _extends({},t,r)){var o=r&&r[n]?r[n]:"";r[n]===t[n]||("-"===n[0]?e.style.setProperty(n,o):e.style[n]=o)}},updateEvents=function(e,t,r){var n=!0,o=!1,i=void 0;try{for(var a,u=_objectEntries$1(e.events)[Symbol.iterator]();!(n=(a=u.next()).done);n=!0){var c=a.value,s=slicedToArray(c,2),l=s[0],f=s[1];r[l]?f!==r[l]&&(t.removeEventListener(l,r[l]),t.addEventListener(l,f)):t.addEventListener(l,f)}}catch(e){o=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}var p=_objectEntries$1(r).filter(function(t){var r=slicedToArray(t,1)[0];return!e.events[r]}),v=!0,m=!1,y=void 0;try{for(var h,d=p[Symbol.iterator]();!(v=(h=d.next()).done);v=!0){var b=h.value,E=slicedToArray(b,2),A=E[0],g=E[1];t.removeEventListener(A,g)}}catch(e){m=!0,y=e}finally{try{!v&&d.return&&d.return()}finally{if(m)throw y}}},updateAttrs=function(e,t,r){for(var n in _extends({},r,e.attrs)){var o=e.attrs[n];o===r[n]||(isEmpty(o)?"value"===n&&"INPUT"===t.tagName?t.value="":t.removeAttribute(n):"style"===n?updateStyle(t,r.style,e.attrs.style):"value"===n&&"INPUT"===t.tagName?t.value=o:t.setAttribute(n,o))}},updateChildren=function(e,t,r,n,o){var i=flatten$1(r),a=flatten$1(t);for(var u in i){var c=i[u],s=a[u],l=e.childNodes[u];if(l)patch(l,s,c,n,o);else{var f=_createElement(c,n,o);e.appendChild(f),_mount(c,f)}}for(var p in[].slice.call(e.childNodes,i.length)){var v=parseInt(p)+i.length,m=a[v],y=e.childNodes[v];y&&(_removeElement(m,y),y.remove())}},VNode=function(){function e(t){var r=t.name,n=t.attrs,o=void 0===n?{}:n,i=t.lifecycle,a=void 0===i?{}:i,u=t.events,c=void 0===u?{}:u,s=t.children,l=void 0===s?{}:s,f=t.key,p=void 0===f?"":f;classCallCheck(this,e),this.type="VNode",this.name=r,this.attrs=o,this.lifecycle=a,this.events=c,this.children=l,this.key=p}return createClass(e,[{key:"createElement",value:function(e,t){var r=(e=e||"svg"===this.name)?document.createElementNS("http://www.w3.org/2000/svg",this.name):document.createElement(this.name);return updateEvents(this,r,{}),updateAttrs(this,r,{}),updateChildren(r,[],this.children,e,t),r}},{key:"updateElement",value:function(e,t,r,n){if(t.name!==this.name)return _removeElement(t,e),_createElement(this,r,n);updateEvents(this,e,t.events),updateAttrs(this,e,t.attrs),updateChildren(e,t.children,this.children,r,n),this.lifecycle.update(e)}},{key:"removeElement",value:function(e){flatten$1(this.children).map(function(t,r){return _removeElement(t,e.childNodes[r])}),this.lifecycle.unmount(e)}},{key:"mount",value:function(e){flatten$1(this.children).map(function(e){return _mount(e)}),this.lifecycle.mount(e)}}]),e}(),VPatch=function(){function e(t){var r=t.vTree;classCallCheck(this,e),this.type="VPatch",this.vTree=r}return createClass(e,[{key:"createElement",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return _createElement.apply(void 0,[this.vTree].concat(t))}},{key:"updateElement",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return _updateElement.apply(void 0,[this.vTree].concat(t))}},{key:"removeElement",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return _removeElement.apply(void 0,[this.vTree].concat(t))}},{key:"mount",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return _mount.apply(void 0,[this.vTree].concat(t))}}]),e}(),pickNonObservables=function(e){return pickBy(function(e,t){return!/\$$/.test(t)},e)};function createPropsStream(e){var t=new BehaviorSubject(e);return{next:function(e){return t.next(e)},stream:t.pipe(switchMap(function(e){return combineLatestObject(pickNonObservables(e)).pipe(map(function(t){return _extends({},e,t)}))}),shareReplay(1))}}var Component=function(){function e(t){var r=t.name,n=t.untouchedAttributes,o=t.key,i=void 0===o?"":o;classCallCheck(this,e),this.type="Component",this.name=r,this.untouchedAttributes=n,this.key=i}return createClass(e,[{key:"createElement",value:function(e,t){var r=e?document.createElementNS("http://www.w3.org/2000/svg","g"):document.createElement("div");this.state={},this.state.props=createPropsStream(this.untouchedAttributes);var n=this.name(this.state.props.stream);if(!n)throw new Error("Component "+this.name.name+" must return a stream!");return this.state.subscription=render(n,r,t,{isSvg:e,morphNode:!0}),r}},{key:"updateElement",value:function(e,t,r,n){if(this.state=t.state,t.name!==this.name)return _removeElement(t,e),_createElement(this,r,n);isShallowEqual(t.untouchedAttributes,this.untouchedAttributes)||this.state.props.next(this.untouchedAttributes)}},{key:"removeElement",value:function(){this.state.subscription.unsubscribe()}},{key:"mount",value:function(){}}]),e}(),classes={VNode:VNode,VText:VText,Component:Component},_createElement=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return classes[e.type].prototype.createElement.apply(e,r)},_mount=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return classes[e.type].prototype.mount.apply(e,r)},_updateElement=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return classes[e.type].prototype.updateElement.apply(e,r)},_removeElement=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return classes[e.type].prototype.removeElement.apply(e,r)};function createVTree(e){return{key:"INIT",type:"VNode",name:e.nodeName.toLowerCase(),lifecycle:createDefaultLifecycle(),events:{},attrs:{},untouchedAttributes:{},children:Array.prototype.map.call(e.childNodes,function(e){return 3===e.nodeType?{type:"VText",text:e.nodeValue}:createVTree(e)})}}function patch(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:createVTree(e),r=arguments[2],n=arguments[3],o=arguments[4];if(r.type!==t.type||r.key!==t.key){_removeElement(t,e);var i=_createElement(r,n,o);return e.parentNode.replaceChild(i,e),_mount(r,i,n),i}var a=_updateElement(r,e,t,n,o);return a?(e.parentNode.replaceChild(a,e),_mount(r,a,n),a):e}function _objectEntries$2(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}function _objectEntries$2(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}var isLifecycle=function(e){return["mount","update","unmount"].includes(e)},isEvent=function(e){return!!e.match(/^on/)},toEventName=function(e){return e.replace(/^on/,"").toLowerCase()},styleToObject=function(e){return e.split(";").reduce(function(e,t){var r=t.split(/:/),n=toArray(r),o=n[0],i=n.slice(1);return o.trim()&&(e[o.trim()]=i.join(":")),e},{})},formatChildren=flatMap(function(e){return Array.isArray(e)?formatChildren(e):isEmpty(e)?[]:["VNode","VText","VPatch","Component"].some(function(t){return e.type===t})?[e]:isObservable(e)||isPromise(e)?[{type:"Component",name:function(){return flip(e).pipe(map(function(e){return formatChildren([e])}),map(function(e){return 1===e.length?e[0]:e}),filter(function(e){return!isEmpty(e)}))},untouchedAttributes:{children:[]}}]:[{type:"VText",text:e}]});function h(e,t){for(var r=t||{},n=arguments.length,o=Array(n>2?n-2:0),i=2;i<n;i++)o[i-2]=arguments[i];var a=o.reduce(function(e,t){return e.concat(t)},[]);if("function"==typeof e)return{type:"Component",name:e,untouchedAttributes:_extends({},r,{children:a})};var u=_objectEntries$2(r).reduce(function(e,t){var r=slicedToArray(t,2),n=r[0],o=r[1];return"key"===n?e.key=o:isLifecycle(n)&&"function"==typeof o?e.lifecycle[n]=o:isEvent(n)&&"function"==typeof o?e.events[toEventName(n)]=o:e.attrs[n]="style"===n?"object"===(void 0===o?"undefined":_typeof(o))?o:styleToObject(o):o,e},{lifecycle:createDefaultLifecycle(),events:{},attrs:{}}),c=u.key,s=u.lifecycle,l=u.events;return{type:"VNode",name:e,attrs:u.attrs,lifecycle:s,events:l,children:formatChildren(a),key:c}}var createRenderProcess=function(e){return new Observable(function(t){var r=void 0,n=void 0,o=void 0;return e.subscribe({complete:function(){return t.complete()},error:function(e){return t.error(e)},next:function(e){if(!(e instanceof VNode))return t.next(e);var i=e.lifecycle.mount;e.lifecycle.mount=function(e,t){r=e,o=t,i(e)},r?(r=patch(r,n,e,o),t.next(new VPatch({vTree:e}))):t.next(e),n=e}})})},toRenderProcess=function(e){return function(t){for(var r=arguments.length,n=Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return createRenderProcess(e.apply(void 0,[t].concat(n)))}},html$1=toRenderProcess(createReactiveTag(createTag(h))),textTag=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return e.reduce(function(e,t,n){return e+t+(void 0!==r[n]?r[n]:"")},"")},text=createReactiveTag(textTag);export{text,render,h};export default html$1; | ||
import createTag from"vdom-tag";import{BehaviorSubject,Observable,combineLatest,from,of}from"rxjs";import{filter,map,share,shareReplay,startWith}from"rxjs/operators";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),defineProperty=function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e},_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},slicedToArray=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],n=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(n=(a=u.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){o=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),toArray=function(e){return Array.isArray(e)?e:Array.from(e)},toConsumableArray=function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)},compose=function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return function(e){return t.reduceRight(function(e,t){return t(e)},e)}},curry=function e(t){return function(){for(var r=arguments.length,n=Array(r),o=0;o<r;o++)n[o]=arguments[o];return n.length>=t.length?t.apply(void 0,n):function(){for(var r=arguments.length,o=Array(r),i=0;i<r;i++)o[i]=arguments[i];return e(t).apply(void 0,n.concat(o))}}},flatMap=curry(function(e,t){return t.reduce(function(t,r){return t.concat(e(r))},[])}),flatten=flatMap(function(e){return e}),noOp=function(){},createDefaultLifecycle=function(){return{mount:noOp,update:noOp,unmount:noOp}},isEmpty=function(e){return 0!==e&&(!e||"string"==typeof e&&!e.trim())||Array.isArray(e)&&!e.length};function _objectEntries$1(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}function _objectEntries$1(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}var fromEntries=function(e){return e.reduce(function(e,t){var r=slicedToArray(t,2),n=r[0],o=r[1];return _extends({},e,defineProperty({},n,o))},{})},pickBy=curry(function(e,t){return fromEntries(_objectEntries$1(t).filter(function(t){var r=slicedToArray(t,2),n=r[0],o=r[1];return e(o,n)}))}),mapValues=curry(function(e,t){return Object.keys(t).reduce(function(r,n){return _extends({},r,defineProperty({},n,e(t[n],n)))},{})}),isObject=function(e){return"object"===(void 0===e?"undefined":_typeof(e))&&null!==e};function _objectValues(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push(e[r[n]]);return t}function _objectValues(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push(e[r[n]]);return t}var isPromise=function(e){return e&&"function"==typeof e.then},isObservable=function(e){return e&&"function"==typeof e.subscribe},toObservable=function(e){return isObservable(e)?e:of(e)},switchMap=curry(function(e,t){var r=void 0;return new Observable(function(n){var o=!1,i=!1,a=t.subscribe({next:function(t){r&&r.unsubscribe(),r=e(t).subscribe({error:function(e){return n.error(e)},next:function(e){return n.next(e)},complete:function(){i=!0,o&&n.complete()}})},error:function(e){return n.error(e)},complete:function(){o=!0,i&&n.complete()}});return{unsubscribe:function(){r&&r.unsubscribe(),a.unsubscribe()}}})}),all=function(e){return e.length?combineLatest.apply(void 0,toConsumableArray(e.map(toObservable)).concat([function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return t}])):of([])},combineLatestObject=function(e){var t=Object.keys(e);return t.length?combineLatest.apply(void 0,toConsumableArray(t.map(function(t){return toObservable(e[t]).pipe(map(function(e){return[t,e]}))})).concat([function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.reduce(function(e,t){var r=slicedToArray(t,2),n=r[0],o=r[1];return _extends({},e,defineProperty({},n,o))},{})}])):of(e)},blockComplete=function(){return function(e){return new Observable(function(t){return e.subscribe({complete:function(){},next:function(e){return t.next(e)},error:function(e){return t.error(e)}})})}},sample=curry(function(e,t){var r=Symbol("None");return new Observable(function(n){var o=r,i=t.subscribe({next:function(e){o=e},complete:function(){},error:function(e){return n.error(e)}}),a=e.subscribe({next:function(){o!==r&&(n.next(o),o=r)},complete:function(){return n.complete()},error:function(e){return n.error(e)}});return{unsubscribe:function(){i.unsubscribe(),a.unsubscribe()}}})}),raf=new Observable(function(e){var t=!0;return window.requestAnimationFrame(function r(){t&&(e.next(),window.requestAnimationFrame(r))}),{unsubscribe:function(){t=!1}}}),applyIf=curry(function(e,t,r){return e(r)?t(r):r}),ifObservable=applyIf(isObservable),allIfObservable=applyIf(function(e){return e.some(isObservable)},all),combineLatestObjectIfObservable=applyIf(function(e){return _objectValues(e).some(isObservable)},combineLatestObject),defaultWith=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:32;return function(r){return new Observable(function(n){var o=setTimeout(function(){return n.next(e)},t);return r.subscribe({next:function(e){clearTimeout(o),n.next(e)},complete:function(){clearTimeout(o),n.complete()},error:function(e){clearTimeout(o),n.error(e)}})})}},_flip=function e(t){return isObservable(t)?switchMap(compose(toObservable,e))(t):isPromise(t)?switchMap(compose(toObservable,e))(from(t)):Array.isArray(t)?allIfObservable(t.map(compose(ifObservable(defaultWith(void 0)),e))):isObject(t)?"Component"===t.type?t:combineLatestObjectIfObservable(mapValues(compose(ifObservable(defaultWith(void 0)),e),t)):t},flip=function(e){return toObservable(_flip(e))};function _objectEntries(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}function _objectEntries(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}var isLifecycle=function(e){return["mount","update","unmount"].includes(e)},isEvent=function(e){return!!e.match(/^on/)},toEventName=function(e){return e.replace(/^on/,"").toLowerCase()},styleToObject=function(e){return e.split(";").reduce(function(e,t){var r=t.split(/:/),n=toArray(r),o=n[0],i=n.slice(1);return o.trim()&&(e[o.trim()]=i.join(":")),e},{})},formatChildren=flatMap(function(e){return Array.isArray(e)?formatChildren(e):isEmpty(e)?[]:["VNode","VText","VPatch","Component"].some(function(t){return e.type===t})?[e]:isObservable(e)||isPromise(e)?[{type:"Component",name:function(){return flip(e).pipe(map(function(e){return formatChildren([e])}),map(function(e){return 1===e.length?e[0]:e}),filter(function(e){return!isEmpty(e)}))},untouchedAttributes:{children:[]}}]:[{type:"VText",text:e}]});function h(e,t){for(var r=t||{},n=arguments.length,o=Array(n>2?n-2:0),i=2;i<n;i++)o[i-2]=arguments[i];var a=o.reduce(function(e,t){return e.concat(t)},[]);if("function"==typeof e)return{type:"Component",name:e,untouchedAttributes:_extends({},r,{children:a})};var u=_objectEntries(r).reduce(function(e,t){var r=slicedToArray(t,2),n=r[0],o=r[1];return"key"===n?e.key=o:isLifecycle(n)&&"function"==typeof o?e.lifecycle[n]=o:isEvent(n)&&"function"==typeof o?e.events[toEventName(n)]=o:e.attrs[n]="style"===n?"object"===(void 0===o?"undefined":_typeof(o))?o:styleToObject(o):o,e},{lifecycle:createDefaultLifecycle(),events:{},attrs:{}}),c=u.key,s=u.lifecycle,l=u.events;return{type:"VNode",name:e,attrs:u.attrs,lifecycle:s,events:l,children:formatChildren(a),key:c}}var html$1=createTag(h);function _objectEntries$2(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}function _objectEntries$2(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}var sharedRaf=share()(raf),toStream=function(e){return flip(e).pipe(sample(sharedRaf))},render=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=n.isSvg,i=void 0!==o&&o,a=n.morphNode,u=void 0!==a&&a?t:t.firstChild,c=void 0,s="function"==typeof e?e(r):e,l=toStream(s).subscribe({next:function(e){"VPatch"===e.type?c=e.vTree:Array.isArray(e)?(updateChildren(u||(u=t),c||[],e,i,r),c=e):(u?u=patch(u,c,e,i,r):(u=_createElement(e,i,r),t.innerHTML="",t.appendChild(u)),c=e)}});return{unsubscribe:function(){c&&(Array.isArray(c)?updateChildren(u,c,[],i,r):_removeElement(c,u)),l.unsubscribe()}}},VText=function(){function e(t){var r=t.text;classCallCheck(this,e),this.type="VText",this.text=r}return createClass(e,[{key:"createElement",value:function(){return document.createTextNode(this.text)}},{key:"updateElement",value:function(e,t){t.text!==this.text&&(e.textContent=this.text)}},{key:"removeElement",value:function(){}},{key:"mount",value:function(){}}]),e}();function isShallowEqual(e,t){for(var r in e)if(!(r in t)||e[r]!==t[r])return!1;for(var n in t)if(!(n in e)||e[n]!==t[n])return!1;return!0}var updateStyle=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};for(var n in _extends({},t,r)){var o=r&&r[n]?r[n]:"";r[n]===t[n]||("-"===n[0]?e.style.setProperty(n,o):e.style[n]=o)}},updateEvents=function(e,t,r){var n=!0,o=!1,i=void 0;try{for(var a,u=_objectEntries$2(e.events)[Symbol.iterator]();!(n=(a=u.next()).done);n=!0){var c=a.value,s=slicedToArray(c,2),l=s[0],f=s[1];r[l]?f!==r[l]&&(t.removeEventListener(l,r[l]),t.addEventListener(l,f)):t.addEventListener(l,f)}}catch(e){o=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}var p=_objectEntries$2(r).filter(function(t){var r=slicedToArray(t,1)[0];return!e.events[r]}),v=!0,m=!1,y=void 0;try{for(var h,b=p[Symbol.iterator]();!(v=(h=b.next()).done);v=!0){var d=h.value,E=slicedToArray(d,2),A=E[0],g=E[1];t.removeEventListener(A,g)}}catch(e){m=!0,y=e}finally{try{!v&&b.return&&b.return()}finally{if(m)throw y}}},updateAttrs=function(e,t,r){for(var n in _extends({},r,e.attrs)){var o=e.attrs[n];o===r[n]||(isEmpty(o)?"value"===n&&"INPUT"===t.tagName?t.value="":t.removeAttribute(n):"style"===n?updateStyle(t,r.style,e.attrs.style):"value"===n&&"INPUT"===t.tagName?t.value=o:t.setAttribute(n,o))}},updateChildren=function(e,t,r,n,o){var i=flatten(r),a=flatten(t);for(var u in i){var c=i[u],s=a[u],l=e.childNodes[u];if(l)patch(l,s,c,n,o);else{var f=_createElement(c,n,o);e.appendChild(f),_mount(c,f)}}for(var p in[].slice.call(e.childNodes,i.length)){var v=parseInt(p)+i.length,m=a[v],y=e.childNodes[v];y&&(_removeElement(m,y),y.remove())}},VNode=function(){function e(t){var r=t.name,n=t.attrs,o=void 0===n?{}:n,i=t.lifecycle,a=void 0===i?{}:i,u=t.events,c=void 0===u?{}:u,s=t.children,l=void 0===s?{}:s,f=t.key,p=void 0===f?"":f;classCallCheck(this,e),this.type="VNode",this.name=r,this.attrs=o,this.lifecycle=a,this.events=c,this.children=l,this.key=p}return createClass(e,[{key:"createElement",value:function(e,t){var r=(e=e||"svg"===this.name)?document.createElementNS("http://www.w3.org/2000/svg",this.name):document.createElement(this.name);return updateEvents(this,r,{}),updateAttrs(this,r,{}),updateChildren(r,[],this.children,e,t),r}},{key:"updateElement",value:function(e,t,r,n){if(t.name!==this.name)return _removeElement(t,e),_createElement(this,r,n);updateEvents(this,e,t.events),updateAttrs(this,e,t.attrs),updateChildren(e,t.children,this.children,r,n),this.lifecycle.update(e)}},{key:"removeElement",value:function(e){flatten(this.children).map(function(t,r){return _removeElement(t,e.childNodes[r])}),this.lifecycle.unmount(e)}},{key:"mount",value:function(e){flatten(this.children).map(function(e){return _mount(e)}),this.lifecycle.mount(e)}}]),e}(),VPatch=function(){function e(t){var r=t.vTree;classCallCheck(this,e),this.type="VPatch",this.vTree=r}return createClass(e,[{key:"createElement",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return _createElement.apply(void 0,[this.vTree].concat(t))}},{key:"updateElement",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return _updateElement.apply(void 0,[this.vTree].concat(t))}},{key:"removeElement",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return _removeElement.apply(void 0,[this.vTree].concat(t))}},{key:"mount",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return _mount.apply(void 0,[this.vTree].concat(t))}}]),e}(),pickNonObservables=function(e){return pickBy(function(e,t){return!/\$$/.test(t)},e)};function createPropsStream(e){var t=new BehaviorSubject(e);return{next:function(e){return t.next(e)},stream:t.pipe(switchMap(function(e){return combineLatestObject(pickNonObservables(e)).pipe(map(function(t){return _extends({},e,t)}))}),shareReplay(1))}}var Component=function(){function e(t){var r=t.name,n=t.untouchedAttributes,o=t.key,i=void 0===o?"":o;classCallCheck(this,e),this.type="Component",this.name=r,this.untouchedAttributes=n,this.key=i}return createClass(e,[{key:"createElement",value:function(e,t){var r=e?document.createElementNS("http://www.w3.org/2000/svg","g"):document.createElement("div");this.state={},this.state.props=createPropsStream(this.untouchedAttributes);var n=this.name(this.state.props.stream);if(!n)throw new Error("Component "+this.name.name+" must return a stream!");return this.state.subscription=render(n,r,t,{isSvg:e,morphNode:!0}),r}},{key:"updateElement",value:function(e,t,r,n){if(this.state=t.state,t.name!==this.name)return _removeElement(t,e),_createElement(this,r,n);isShallowEqual(t.untouchedAttributes,this.untouchedAttributes)||this.state.props.next(this.untouchedAttributes)}},{key:"removeElement",value:function(){this.state.subscription.unsubscribe()}},{key:"mount",value:function(){}}]),e}(),classes={VNode:VNode,VText:VText,Component:Component},_createElement=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return classes[e.type].prototype.createElement.apply(e,r)},_mount=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return classes[e.type].prototype.mount.apply(e,r)},_updateElement=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return classes[e.type].prototype.updateElement.apply(e,r)},_removeElement=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return classes[e.type].prototype.removeElement.apply(e,r)};function createVTree(e){return{key:"INIT",type:"VNode",name:e.nodeName.toLowerCase(),lifecycle:createDefaultLifecycle(),events:{},attrs:{},untouchedAttributes:{},children:Array.prototype.map.call(e.childNodes,function(e){return 3===e.nodeType?{type:"VText",text:e.nodeValue}:createVTree(e)})}}function patch(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:createVTree(e),r=arguments[2],n=arguments[3],o=arguments[4];if(r.type!==t.type||r.key!==t.key){_removeElement(t,e);var i=_createElement(r,n,o);return e.parentNode.replaceChild(i,e),_mount(r,i,n),i}var a=_updateElement(r,e,t,n,o);return a?(e.parentNode.replaceChild(a,e),_mount(r,a,n),a):e}var hasContent=function(e){return!e.length||!e.every(isEmpty)},flatten$1=function e(t){return Array.isArray(t)?all(t.map(compose(startWith(""),e))).pipe(filter(hasContent)):isObservable(t)?switchMap(e,t):isPromise(t)?switchMap(e,from(t)):toObservable(t)},sharedRaf$1=share()(raf),createReactiveTag=function(e){return function(t){for(var r=arguments.length,n=Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return flatten$1(n).pipe(blockComplete(),startWith([]),sample(sharedRaf$1),map(function(r){return e.apply(void 0,[t].concat(toConsumableArray(r)))}))}},textTag=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return e.reduce(function(e,t,n){return e+t+(void 0!==r[n]?r[n]:"")},"")},text=createReactiveTag(textTag);export{text,render,h};export default html$1; |
{ | ||
"name": "evolui", | ||
"version": "2.0.0-alpha.02", | ||
"version": "2.0.0-alpha.03", | ||
"description": "Observable powered templates for asynchronous UIs", | ||
@@ -5,0 +5,0 @@ "main": "lib/evolui.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
68933
1301