Comparing version 1.6.6 to 1.6.7
24
extra.js
@@ -1,5 +0,11 @@ | ||
import ease from 'rx-ease'; | ||
import { BehaviorSubject, Observable, combineLatest, of } from 'rxjs'; | ||
import 'rxjs/operators'; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var ease = _interopDefault(require('rx-ease')); | ||
var rxjs = require('rxjs'); | ||
require('rxjs/operators'); | ||
var defineProperty = function (obj, key, value) { | ||
@@ -95,3 +101,3 @@ if (key in obj) { | ||
var all = function all(obs) { | ||
return obs.length ? combineLatest.apply(undefined, toConsumableArray(obs).concat([function () { | ||
return obs.length ? rxjs.combineLatest.apply(undefined, toConsumableArray(obs).concat([function () { | ||
for (var _len = arguments.length, xs = Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -102,3 +108,3 @@ xs[_key] = arguments[_key]; | ||
return xs; | ||
}])) : of([]); | ||
}])) : rxjs.of([]); | ||
}; | ||
@@ -108,3 +114,3 @@ | ||
var raf = new Observable(function (observer) { | ||
var raf = new rxjs.Observable(function (observer) { | ||
var isSubscribed = true; | ||
@@ -135,3 +141,3 @@ | ||
var createMutable = function createMutable(initialValue) { | ||
var sub = new BehaviorSubject(initialValue); | ||
var sub = new rxjs.BehaviorSubject(initialValue); | ||
sub.set = function (x) { | ||
@@ -147,2 +153,4 @@ return sub.next(typeof x === 'function' ? x(sub.value) : x); | ||
export { ease, createState, all }; | ||
exports.ease = ease; | ||
exports.createState = createState; | ||
exports.all = all; |
@@ -1,5 +0,11 @@ | ||
import createTag from 'vdom-tag'; | ||
import { BehaviorSubject, Observable, combineLatest, from, of } from 'rxjs'; | ||
import { filter, map, sample, share, startWith } from 'rxjs/operators'; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var createTag = _interopDefault(require('vdom-tag')); | ||
var rxjs = require('rxjs'); | ||
var operators = require('rxjs/operators'); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
@@ -186,3 +192,3 @@ return typeof obj; | ||
var toObservable = function toObservable(x) { | ||
return isObservable(x) ? x : of(x); | ||
return isObservable(x) ? x : rxjs.of(x); | ||
}; | ||
@@ -193,3 +199,3 @@ | ||
return new Observable(function (observer) { | ||
return new rxjs.Observable(function (observer) { | ||
var isOuterStreamComplete = false; | ||
@@ -233,3 +239,3 @@ var isInnerStreamComplete = false; | ||
var all = function all(obs) { | ||
return obs.length ? combineLatest.apply(undefined, toConsumableArray(obs).concat([function () { | ||
return obs.length ? rxjs.combineLatest.apply(undefined, toConsumableArray(obs).concat([function () { | ||
for (var _len = arguments.length, xs = Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -240,3 +246,3 @@ xs[_key] = arguments[_key]; | ||
return xs; | ||
}])) : of([]); | ||
}])) : rxjs.of([]); | ||
}; | ||
@@ -246,3 +252,3 @@ | ||
return function (stream) { | ||
return new Observable(function (observer) { | ||
return new rxjs.Observable(function (observer) { | ||
return stream.subscribe({ | ||
@@ -261,3 +267,3 @@ complete: function complete() {}, | ||
var raf = new Observable(function (observer) { | ||
var raf = new rxjs.Observable(function (observer) { | ||
var isSubscribed = true; | ||
@@ -307,6 +313,6 @@ | ||
var flatten = function flatten(variable) { | ||
return Array.isArray(variable) ? all(variable.map(compose(startWith(''), flatten))).pipe(blockComplete(), filter(hasContent)) : isObservable(variable) ? switchMap(flatten, variable) : isPromise(variable) ? switchMap(flatten, from(variable)) : toObservable(variable); | ||
return Array.isArray(variable) ? all(variable.map(compose(operators.startWith(''), flatten))).pipe(blockComplete(), operators.filter(hasContent)) : isObservable(variable) ? switchMap(flatten, variable) : isPromise(variable) ? switchMap(flatten, rxjs.from(variable)) : toObservable(variable); | ||
}; | ||
var sharedRaf = share()(raf); | ||
var sharedRaf = operators.share()(raf); | ||
@@ -324,3 +330,3 @@ // createReactiveTag | ||
return flatten(variables).pipe(startWith([]), sample(sharedRaf), map(function (variables) { | ||
return flatten(variables).pipe(operators.startWith([]), operators.sample(sharedRaf), operators.map(function (variables) { | ||
return tagFunction.apply(undefined, [strings].concat(toConsumableArray(variables))); | ||
@@ -669,3 +675,3 @@ })); | ||
function createPropsStream(props) { | ||
var sub = new BehaviorSubject(props); | ||
var sub = new rxjs.BehaviorSubject(props); | ||
return { | ||
@@ -707,3 +713,3 @@ next: function next(props) { | ||
this.state.subscription = vdomStream.pipe(flatten, sample(sharedRaf)).subscribe({ | ||
this.state.subscription = vdomStream.pipe(flatten, operators.sample(sharedRaf)).subscribe({ | ||
next: function next(newChildTree) { | ||
@@ -846,3 +852,3 @@ if (newChildTree instanceof VPatch) { | ||
var createRenderProcess = function createRenderProcess(vdom$) { | ||
return new Observable(function (observer) { | ||
return new rxjs.Observable(function (observer) { | ||
var domNode = void 0; | ||
@@ -932,3 +938,4 @@ var previousTree = void 0; | ||
export { text, render }; | ||
export default html$1; | ||
exports['default'] = html$1; | ||
exports.text = text; | ||
exports.render = render; |
@@ -1,1 +0,1 @@ | ||
import createTag from"vdom-tag";import{BehaviorSubject,Observable,combineLatest,from,of}from"rxjs";import{filter,map,sample,share,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}}(),_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))}}},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).concat([function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return t}])):of([])},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)}})})}},raf=new Observable(function(e){var t=!0;return window.requestAnimationFrame(function r(){t&&(e.next(),window.requestAnimationFrame(r))}),{unsubscribe:function(){t=!1}}}),noOp=function(){},createDefaultLifecycle=function(){return{mount:noOp,update:noOp,unmount:noOp}},isEmpty=function(e){return 0!==e&&(!e||"string"==typeof e&&!e.trim())},hasContent=function(e){return!e.length||!e.every(isEmpty)},flatten=function e(t){return Array.isArray(t)?all(t.map(compose(startWith(""),e))).pipe(blockComplete(),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(startWith([]),sample(sharedRaf),map(function(r){return e.apply(void 0,[t].concat(toConsumableArray(r)))}))}};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}function updateStyle(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)}}var 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,h=void 0===f?"":f;classCallCheck(this,e),this.name=r,this.attrs=o,this.lifecycle=a,this.events=c,this.children=l,this.key=h}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 this.updateEvents(r,{}),this.updateAttrs(r,{}),this.updateChildren(r,[],e,t),r}},{key:"updateElement",value:function(e,t,r,n){if(t.name!==this.name)return t.removeElement(e),this.createElement(r,n);this.updateEvents(e,t.events),this.updateAttrs(e,t.attrs),this.updateChildren(e,t.children,r,n),this.lifecycle.update(e)}},{key:"removeElement",value:function(e){this.children.map(function(t,r){return t.removeElement(e.childNodes[r])}),this.lifecycle.unmount(e)}},{key:"mount",value:function(e){this.children.map(function(e){return e.mount()}),this.lifecycle.mount(e)}},{key:"updateEvents",value:function(e,t){var r=this,n=!0,o=!1,i=void 0;try{for(var a,u=_objectEntries(this.events)[Symbol.iterator]();!(n=(a=u.next()).done);n=!0){var c=a.value,s=slicedToArray(c,2),l=s[0],f=s[1];t[l]?f!==t[l]&&(e.removeEventListener(l,t[l]),e.addEventListener(l,f)):e.addEventListener(l,f)}}catch(e){o=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}var h=_objectEntries(t).filter(function(e){var t=slicedToArray(e,1)[0];return!r.events[t]}),v=!0,m=!1,y=void 0;try{for(var d,p=h[Symbol.iterator]();!(v=(d=p.next()).done);v=!0){var b=d.value,E=slicedToArray(b,2),g=E[0],x=E[1];e.removeEventListener(g,x)}}catch(e){m=!0,y=e}finally{try{!v&&p.return&&p.return()}finally{if(m)throw y}}}},{key:"updateAttrs",value:function(e,t){for(var r in _extends({},t,this.attrs)){var n=this.attrs[r];n===t[r]||(isEmpty(n)?"value"===r&&"INPUT"===e.tagName?e.value="":e.removeAttribute(r):"style"===r?updateStyle(e,t.style,this.attrs.style):"value"===r&&"INPUT"===e.tagName?e.value=n:e.setAttribute(r,n))}}},{key:"updateChildren",value:function(e,t,r,n){for(var o in this.children){var i=this.children[o],a=t[o],u=e.childNodes[o];if(u)n(u,a,i,r);else{var c=i.createElement(r,n);e.appendChild(c),i.mount(c)}}for(var s in[].slice.call(e.childNodes,this.children.length)){var l=parseInt(s)+this.children.length,f=t[l],h=e.childNodes[l];h&&(f.removeElement(h),h.remove())}}}]),e}(),VText=function(){function e(t){var r=t.text;classCallCheck(this,e),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 createVTree(e){return new VNode({name:e.nodeName.toLowerCase(),lifecycle:createDefaultLifecycle(),events:{},attrs:{},untouchedAttributes:{},children:Array.prototype.map.call(e.childNodes,function(e){return 3===e.nodeType?new 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];if(r.constructor!==t.constructor||r.key!==t.key){t.removeElement(e);var o=r.createElement(n,patch);return e.parentNode.replaceChild(o,e),r.mount(o),o}var i=r.updateElement(e,t,n,patch);return i?(e.parentNode.replaceChild(i,e),r.mount(i,n),i):e}var VPatch=function(){function e(t){classCallCheck(this,e),this.vTree=t}return createClass(e,[{key:"createElement",value:function(){var e;return(e=this.vTree).createElement.apply(e,arguments)}},{key:"updateElement",value:function(){var e;return(e=this.vTree).updateElement.apply(e,arguments)}},{key:"removeElement",value:function(){var e;return(e=this.vTree).removeElement.apply(e,arguments)}},{key:"mount",value:function(){var e;return(e=this.vTree).mount.apply(e,arguments)}}]),e}();function createPropsStream(e){var t=new BehaviorSubject(e);return{next:function(e){return t.next(e)},stream:t}}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.name=r,this.untouchedAttributes=n,this.key=i}return createClass(e,[{key:"createElement",value:function(e,t){var r=this,n=e?document.createElementNS("http://www.w3.org/2000/svg","g"):document.createElement("div");this.state={},this.state.props=createPropsStream(this.untouchedAttributes),this.state.childTree=void 0;var o=this.name(this.state.props.stream);if(!o)throw new Error("Component "+this.name.name+" must return a stream!");return this.state.subscription=o.pipe(flatten,sample(sharedRaf)).subscribe({next:function(o){o instanceof VPatch?r.state.childTree=o.vTree:(n=t(n,r.state.childTree,o,e),r.state.childTree=o)},error:function(e){return console.error(e)}}),n}},{key:"updateElement",value:function(e,t,r,n){if(this.state=t.state,t.name!==this.name)return t.removeElement(e),this.createElement(r,n);this.state.props.next(this.untouchedAttributes)}},{key:"removeElement",value:function(e){this.state.subscription.unsubscribe(),this.state.childTree&&this.state.childTree.removeElement(e)}},{key:"mount",value:function(){}}]),e}(),flatMap=curry(function(e,t){return t.reduce(function(t,r){return t.concat(e(r))},[])});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 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):[VNode,VText,VPatch,Component].some(function(t){return e instanceof t})?[e]:isEmpty(e)?[]:[new VText({text:""+e})]});function h(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];if("function"==typeof e)return new Component({name:e,untouchedAttributes:_extends({},t,{children:r})});var n=_objectEntries$1(t).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:{}}),o=n.key,i=n.lifecycle,a=n.events,u=n.attrs;return new VNode({name:e,attrs:u,lifecycle:i,events:a,children:formatChildren(r),key:o})}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(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))),render=function(e,t){var r=t.firstChild,n=void 0;return e.subscribe({next:function(e){e instanceof VPatch?n=e.vTree:(r?patch(r,n,e):(r=e.createElement(!1,patch),t.appendChild(r)),n=e)}})},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};export default html$1; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var createTag=_interopDefault(require("vdom-tag")),rxjs=require("rxjs"),operators=require("rxjs/operators"),_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}}(),_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))}}},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:rxjs.of(e)},switchMap=curry(function(e,t){var r=void 0;return new rxjs.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?rxjs.combineLatest.apply(void 0,toConsumableArray(e).concat([function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return t}])):rxjs.of([])},blockComplete=function(){return function(e){return new rxjs.Observable(function(t){return e.subscribe({complete:function(){},next:function(e){return t.next(e)},error:function(e){return t.error(e)}})})}},raf=new rxjs.Observable(function(e){var t=!0;return window.requestAnimationFrame(function r(){t&&(e.next(),window.requestAnimationFrame(r))}),{unsubscribe:function(){t=!1}}}),noOp=function(){},createDefaultLifecycle=function(){return{mount:noOp,update:noOp,unmount:noOp}},isEmpty=function(e){return 0!==e&&(!e||"string"==typeof e&&!e.trim())},hasContent=function(e){return!e.length||!e.every(isEmpty)},flatten=function e(t){return Array.isArray(t)?all(t.map(compose(operators.startWith(""),e))).pipe(blockComplete(),operators.filter(hasContent)):isObservable(t)?switchMap(e,t):isPromise(t)?switchMap(e,rxjs.from(t)):toObservable(t)},sharedRaf=operators.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(operators.startWith([]),operators.sample(sharedRaf),operators.map(function(r){return e.apply(void 0,[t].concat(toConsumableArray(r)))}))}};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}function updateStyle(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)}}var 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,v=void 0===f?"":f;classCallCheck(this,e),this.name=r,this.attrs=o,this.lifecycle=a,this.events=c,this.children=l,this.key=v}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 this.updateEvents(r,{}),this.updateAttrs(r,{}),this.updateChildren(r,[],e,t),r}},{key:"updateElement",value:function(e,t,r,n){if(t.name!==this.name)return t.removeElement(e),this.createElement(r,n);this.updateEvents(e,t.events),this.updateAttrs(e,t.attrs),this.updateChildren(e,t.children,r,n),this.lifecycle.update(e)}},{key:"removeElement",value:function(e){this.children.map(function(t,r){return t.removeElement(e.childNodes[r])}),this.lifecycle.unmount(e)}},{key:"mount",value:function(e){this.children.map(function(e){return e.mount()}),this.lifecycle.mount(e)}},{key:"updateEvents",value:function(e,t){var r=this,n=!0,o=!1,i=void 0;try{for(var a,u=_objectEntries(this.events)[Symbol.iterator]();!(n=(a=u.next()).done);n=!0){var c=a.value,s=slicedToArray(c,2),l=s[0],f=s[1];t[l]?f!==t[l]&&(e.removeEventListener(l,t[l]),e.addEventListener(l,f)):e.addEventListener(l,f)}}catch(e){o=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}var v=_objectEntries(t).filter(function(e){var t=slicedToArray(e,1)[0];return!r.events[t]}),h=!0,m=!1,p=void 0;try{for(var y,d=v[Symbol.iterator]();!(h=(y=d.next()).done);h=!0){var b=y.value,x=slicedToArray(b,2),E=x[0],g=x[1];e.removeEventListener(E,g)}}catch(e){m=!0,p=e}finally{try{!h&&d.return&&d.return()}finally{if(m)throw p}}}},{key:"updateAttrs",value:function(e,t){for(var r in _extends({},t,this.attrs)){var n=this.attrs[r];n===t[r]||(isEmpty(n)?"value"===r&&"INPUT"===e.tagName?e.value="":e.removeAttribute(r):"style"===r?updateStyle(e,t.style,this.attrs.style):"value"===r&&"INPUT"===e.tagName?e.value=n:e.setAttribute(r,n))}}},{key:"updateChildren",value:function(e,t,r,n){for(var o in this.children){var i=this.children[o],a=t[o],u=e.childNodes[o];if(u)n(u,a,i,r);else{var c=i.createElement(r,n);e.appendChild(c),i.mount(c)}}for(var s in[].slice.call(e.childNodes,this.children.length)){var l=parseInt(s)+this.children.length,f=t[l],v=e.childNodes[l];v&&(f.removeElement(v),v.remove())}}}]),e}(),VText=function(){function e(t){var r=t.text;classCallCheck(this,e),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 createVTree(e){return new VNode({name:e.nodeName.toLowerCase(),lifecycle:createDefaultLifecycle(),events:{},attrs:{},untouchedAttributes:{},children:Array.prototype.map.call(e.childNodes,function(e){return 3===e.nodeType?new 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];if(r.constructor!==t.constructor||r.key!==t.key){t.removeElement(e);var o=r.createElement(n,patch);return e.parentNode.replaceChild(o,e),r.mount(o),o}var i=r.updateElement(e,t,n,patch);return i?(e.parentNode.replaceChild(i,e),r.mount(i,n),i):e}var VPatch=function(){function e(t){classCallCheck(this,e),this.vTree=t}return createClass(e,[{key:"createElement",value:function(){var e;return(e=this.vTree).createElement.apply(e,arguments)}},{key:"updateElement",value:function(){var e;return(e=this.vTree).updateElement.apply(e,arguments)}},{key:"removeElement",value:function(){var e;return(e=this.vTree).removeElement.apply(e,arguments)}},{key:"mount",value:function(){var e;return(e=this.vTree).mount.apply(e,arguments)}}]),e}();function createPropsStream(e){var t=new rxjs.BehaviorSubject(e);return{next:function(e){return t.next(e)},stream:t}}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.name=r,this.untouchedAttributes=n,this.key=i}return createClass(e,[{key:"createElement",value:function(e,t){var r=this,n=e?document.createElementNS("http://www.w3.org/2000/svg","g"):document.createElement("div");this.state={},this.state.props=createPropsStream(this.untouchedAttributes),this.state.childTree=void 0;var o=this.name(this.state.props.stream);if(!o)throw new Error("Component "+this.name.name+" must return a stream!");return this.state.subscription=o.pipe(flatten,operators.sample(sharedRaf)).subscribe({next:function(o){o instanceof VPatch?r.state.childTree=o.vTree:(n=t(n,r.state.childTree,o,e),r.state.childTree=o)},error:function(e){return console.error(e)}}),n}},{key:"updateElement",value:function(e,t,r,n){if(this.state=t.state,t.name!==this.name)return t.removeElement(e),this.createElement(r,n);this.state.props.next(this.untouchedAttributes)}},{key:"removeElement",value:function(e){this.state.subscription.unsubscribe(),this.state.childTree&&this.state.childTree.removeElement(e)}},{key:"mount",value:function(){}}]),e}(),flatMap=curry(function(e,t){return t.reduce(function(t,r){return t.concat(e(r))},[])});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 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):[VNode,VText,VPatch,Component].some(function(t){return e instanceof t})?[e]:isEmpty(e)?[]:[new VText({text:""+e})]});function h(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];if("function"==typeof e)return new Component({name:e,untouchedAttributes:_extends({},t,{children:r})});var n=_objectEntries$1(t).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:{}}),o=n.key,i=n.lifecycle,a=n.events,u=n.attrs;return new VNode({name:e,attrs:u,lifecycle:i,events:a,children:formatChildren(r),key:o})}var createRenderProcess=function(e){return new rxjs.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(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))),render=function(e,t){var r=t.firstChild,n=void 0;return e.subscribe({next:function(e){e instanceof VPatch?n=e.vTree:(r?patch(r,n,e):(r=e.createElement(!1,patch),t.appendChild(r)),n=e)}})},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);exports.default=html$1,exports.text=text,exports.render=render; |
{ | ||
"name": "evolui", | ||
"version": "1.6.6", | ||
"version": "1.6.7", | ||
"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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
51657
890
2