-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrio.min.js
1 lines (1 loc) · 15.4 KB
/
rio.min.js
1
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e){var t=function e(t,n,r){if(t.getAttribute("ref")==n)return t;var i=!0,a=!1,o=void 0;try{for(var s,u=t.children[Symbol.iterator]();!(i=(s=u.next()).done);i=!0){var l=s.value;if(!r||!l.hasAttribute("data-rio-view")){var d=e(l,n,!0);if(d)return d}}}catch(e){a=!0,o=e}finally{try{!i&&u.return&&u.return()}finally{if(a)throw o}}return null},n={get:function(n,r){if(n[r])return n[r];if(e.el){var i=t(e.el,r);return n[r]=i,i}return null}};return new Proxy({},n)}Object.defineProperty(t,"__esModule",{value:!0}),t.View=t.rio=void 0;var o=function(){function e(e,t){var n=[],r=!0,i=!1,a=void 0;try{for(var o,s=e[Symbol.iterator]();!(r=(o=s.next()).done)&&(n.push(o.value),!t||n.length!==t);r=!0);}catch(e){i=!0,a=e}finally{try{!r&&s.return&&s.return()}finally{if(i)throw a}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),s=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),u=n(1),l=r(u),d=n(2),f=r(d),c={idInstances:{},fns:{},fids:new WeakMap,styles:[],updateOpts:{}},h=function(){function e(){i(this,e);var t=this.key.apply(this,arguments);if(c.idInstances[t])return c.idInstances[t];this.handlers={mount:[],update:[],updated:[],unmount:[]},this.initialize.apply(this,arguments),this.finalize.apply(this),this.refs=a(this),this._id=t,this._fids=[],this.parent=null,this._updatedQueue=[],this._mounted=!1,this._depth=0,this.views={},c.fids.set(this,new WeakMap)}return s(e,[{key:"namespace",value:function(){return this.constructor.name}},{key:"initialize",value:function(){}},{key:"finalize",value:function(){}},{key:"render",value:function(){}},{key:"style",value:function(){}},{key:"key",value:function(){throw new Error("Please define a 'key' method that returns a deterministic key for a given instance.")}},{key:"_register",value:function(){c.idInstances[this._id]=this}},{key:"_injectStyle",value:function(){var e="",t=!0,n=!1,r=void 0;try{for(var i,a=c.styles[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var s=o(i.value,2);s[0],e+=s[1]}}catch(e){n=!0,r=e}finally{try{!t&&a.return&&a.return()}finally{if(n)throw r}}var u=document.createElement("style");u.innerHTML=e,this.el.parentNode.insertBefore(u,this.el)}},{key:"_harvestViews",value:function(){var e=Array.from(this.el.querySelectorAll("[data-rio-id]")),t=[],n=!0,r=!1,i=void 0;try{for(var a,o=e[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var s=a.value,u=c.idInstances[s.getAttribute("data-rio-id")];u.el=s,t.push(u)}}catch(e){r=!0,i=e}finally{try{!n&&o.return&&o.return()}finally{if(r)throw i}}t=t.sort(function(e,t){return t._depth-e._depth});var l=!0,d=!1,f=void 0;try{for(var h,p=t[Symbol.iterator]();!(l=(h=p.next()).done);l=!0){var v=h.value;v.dispatch("mount"),v._mounted=!0}}catch(e){d=!0,f=e}finally{try{!l&&p.return&&p.return()}finally{if(d)throw f}}}},{key:"_setEl",value:function(e){this.el=e,this.refs=a(this)}},{key:"_parent",value:function(e){this.parent=e}},{key:"_renderView",value:function(e){if(e._mounted&&!1===e.shouldUpdate(c.updateOpts)){var t=e.el.outerHTML;return t=t.replace(/(<[\w\-]+)/,"$1 data-rio-should-render-false")}e._parent(this);var n=e.namespace();this.views[n]=this.views[n]||[],this.views[n].push(e),e._depth=this._depth+1,e._mounted&&e.dispatch("update");var r=e.render();return e._mounted&&this._updatedQueue.push(e),r}},{key:"tmpl",value:function(t){var n=this;this.views={},c.styles.find(function(e){return e[0]==n.namespace()})||c.styles.push([this.namespace(),this.style()]);var r="";this._updatedQueue.length=0;for(var i=0;i<t.length;i++)if(r+=t[i],i<(arguments.length<=1?0:arguments.length-1)){var a=arguments.length<=i+1?void 0:arguments[i+1];if(a instanceof e)r+=this._renderView(a);else if("function"==typeof a){var o=function(e){var t=void 0;if(c.fids.get(n).has(e))t=c.fids.get(n).get(e);else{t="ev"+String(parseInt(Math.random()*Number.MAX_SAFE_INTEGER-1));var r=function(){return e.bind(n)(window.event),window.event.defaultPrevented};c.fids.get(n).set(e,t),c.fns[t]=r,n._fids.push(t)}return t}(a);r+='"rio.fns.'+o+'()"'}else if(Array.isArray(a)){for(var s=0;s<a.length;s++)a[s]instanceof e&&(a[s]=this._renderView(a[s]));r+=a.join("")}else r+=null===a||void 0===a?"":a}return this._register(this._id,this),r=r.replace(/(<[\w\-]+)/,'$1 data-rio-id="'+this._id+'" data-rio-view="'+this.namespace()+'"')}},{key:"css",value:function(e){for(var t="",n=0;n<e.length;n++)t+=e[n],n<(arguments.length<=1?0:arguments.length-1)&&(t+=arguments.length<=n+1?void 0:arguments[n+1]);var r="[data-rio-view="+this.namespace()+"]";return t=f.default.serialize(f.default.namespace(t,r))}},{key:"mount",value:function(e){try{window.rio=p}catch(e){}this.el=e,this.html=this.render(),this._injectStyle(),this.el.innerHTML=this.html,this._harvestViews()}},{key:"unmount",value:function(){var e=this,t=!0,n=!1,r=void 0;try{for(var i,a=this._fids[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value;delete c.fns[o]}}catch(e){n=!0,r=e}finally{try{!t&&a.return&&a.return()}finally{if(n)throw r}}if(this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el),this.parent){var s=this.namespace(),u=this.parent.views[s].findIndex(function(t){return t==e});this.parent.views[s].splice(u,1)}delete c.idInstances[this._id]}},{key:"shouldUpdate",value:function(){return!0}},{key:"update",value:function(e){if((!this._mounted||!1!==this.shouldUpdate(e))&&this.el){this.dispatch("update");var t=this.render().trim();c.updateOpts=e;try{var n=function(e){return e.nodeType==Node.ELEMENT_NODE};for((0,l.default)(this.el,t,{getNodeKey:function(e){return n(e)?e.getAttribute("data-rio-id")||e.id:e.id},onNodeDiscarded:function(e){if(n(e)&&e.hasAttribute("data-rio-id")){var t=e.getAttribute("data-rio-id"),r=c.idInstances[t];r.dispatch("unmount"),r.unmount()}},onBeforeNodeDiscarded:function(e){return n(e)&&!e.hasAttribute("rio-sacrosanct")},onBeforeElUpdated:function(e,t){return!t.hasAttribute("data-rio-should-render-false")&&(!n(e)||document.activeElement!=e||!e.hasAttribute("rio-uninterruptable-input"))&&void 0},onBeforeNodeAdded:function(e){if(n(e)&&e.hasAttribute("data-rio-id")){var t=e.getAttribute("data-rio-id"),r=c.idInstances[t];r&&r.el&&r.el.parentNode&&r.el.parentNode.removeChild(r.el),r._setEl(e)}},onNodeAdded:function(e){if(n(e)&&e.hasAttribute("data-rio-view")&&e.hasAttribute("data-rio-id")){var t=e.getAttribute("data-rio-id"),r=c.idInstances[t];r.el=e,r._mounted||(r.dispatch("mount"),r._mounted=!0)}}});this._updatedQueue.length;)this._updatedQueue.shift().dispatch("updated");this.dispatch("updated")}catch(e){throw e}finally{c.updateOpts={}}}}},{key:"on",value:function(e,t){if(!this.handlers[e])throw new Error("no event "+e);this.handlers[e].push(t)}},{key:"dispatch",value:function(e){var t=!0,n=!1,r=void 0;try{for(var i,a=this.handlers[e][Symbol.iterator]();!(t=(i=a.next()).done);t=!0)i.value.call(this)}catch(e){n=!0,r=e}finally{try{!t&&a.return&&a.return()}finally{if(n)throw r}}}},{key:"root",get:function(){return this.el}}]),e}(),p={fns:c.fns,View:h};t.rio=p,t.View=h},function(e,t,n){"use strict";function r(e){!f&&p.createRange&&(f=p.createRange(),f.selectNode(p.body));var t;return f&&f.createContextualFragment?t=f.createContextualFragment(e):(t=p.createElement("body"),t.innerHTML=e),t.childNodes[0]}function i(e,t){var n=e.nodeName,r=t.nodeName;return n===r||!!(t.actualize&&n.charCodeAt(0)<91&&r.charCodeAt(0)>90)&&n===r.toUpperCase()}function a(e,t){return t&&t!==h?p.createElementNS(t,e):p.createElement(e)}function o(e,t){for(var n=e.firstChild;n;){var r=n.nextSibling;t.appendChild(n),n=r}return t}function s(e,t){var n,r,i,a,o,s=t.attributes;for(n=s.length-1;n>=0;--n)r=s[n],i=r.name,a=r.namespaceURI,o=r.value,a?(i=r.localName||i,e.getAttributeNS(a,i)!==o&&e.setAttributeNS(a,i,o)):e.getAttribute(i)!==o&&e.setAttribute(i,o);for(s=e.attributes,n=s.length-1;n>=0;--n)r=s[n],!1!==r.specified&&(i=r.name,a=r.namespaceURI,a?(i=r.localName||i,m(t,a,i)||e.removeAttributeNS(a,i)):m(t,null,i)||e.removeAttribute(i))}function u(e,t,n){e[n]!==t[n]&&(e[n]=t[n],e[n]?e.setAttribute(n,""):e.removeAttribute(n,""))}function l(){}function d(e){return e.id}var f,c,h="http://www.w3.org/1999/xhtml",p="undefined"==typeof document?void 0:document,v=p?p.body||p.createElement("div"):{};c=v.hasAttributeNS?function(e,t,n){return e.hasAttributeNS(t,n)}:v.hasAttribute?function(e,t,n){return e.hasAttribute(n)}:function(e,t,n){return null!=e.getAttributeNode(t,n)};var m=c,y={OPTION:function(e,t){u(e,t,"selected")},INPUT:function(e,t){u(e,t,"checked"),u(e,t,"disabled"),e.value!==t.value&&(e.value=t.value),m(t,null,"value")||e.removeAttribute("value")},TEXTAREA:function(e,t){var n=t.value;e.value!==n&&(e.value=n);var r=e.firstChild;if(r){var i=r.nodeValue;if(i==n||!n&&i==e.placeholder)return;r.nodeValue=n}},SELECT:function(e,t){if(!m(t,null,"multiple")){for(var n=0,r=t.firstChild;r;){var i=r.nodeName;if(i&&"OPTION"===i.toUpperCase()){if(m(r,null,"selected"))break;n++}r=r.nextSibling}e.selectedIndex=n}}},g=1,b=3,S=8,x=function(e){return function(t,n,s){function u(e){w?w.push(e):w=[e]}function f(e,t){if(e.nodeType===g)for(var n=e.firstChild;n;){var r=void 0;t&&(r=N(n))?u(r):(R(n),n.firstChild&&f(n,t)),n=n.nextSibling}}function c(e,t,n){!1!==C(e)&&(t&&t.removeChild(e),R(e),f(e,n))}function h(e){if(e.nodeType===g)for(var t=e.firstChild;t;){var n=N(t);n&&(T[n]=t),h(t),t=t.nextSibling}}function v(e){A(e);for(var t=e.firstChild;t;){var n=t.nextSibling,r=N(t);if(r){var a=T[r];a&&i(t,a)&&(t.parentNode.replaceChild(a,t),m(a,t))}v(t),t=n}}function m(r,a,o){var s,l=N(a);if(l&&delete T[l],!n.isSameNode||!n.isSameNode(t)){if(!o){if(!1===k(r,a))return;if(e(r,a),E(r),!1===I(r,a))return}if("TEXTAREA"!==r.nodeName){var d,f,h,x,w=a.firstChild,A=r.firstChild;e:for(;w;){for(h=w.nextSibling,d=N(w);A;){if(f=A.nextSibling,w.isSameNode&&w.isSameNode(A)){w=h,A=f;continue e}s=N(A);var C=A.nodeType,R=void 0;if(C===w.nodeType&&(C===g?(d?d!==s&&((x=T[d])?A.nextSibling===x?R=!1:(r.insertBefore(x,A),f=A.nextSibling,s?u(s):c(A,r,!0),A=x):R=!1):s&&(R=!1),(R=!1!==R&&i(A,w))&&m(A,w)):C!==b&&C!=S||(R=!0,A.nodeValue!==w.nodeValue&&(A.nodeValue=w.nodeValue))),R){w=h,A=f;continue e}s?u(s):c(A,r,!0),A=f}if(d&&(x=T[d])&&i(x,w))r.appendChild(x),m(x,w);else{var O=_(w);!1!==O&&(O&&(w=O),w.actualize&&(w=w.actualize(r.ownerDocument||p)),r.appendChild(w),v(w))}w=h,A=f}for(;A;)f=A.nextSibling,(s=N(A))?u(s):c(A,r,!0),A=f}var V=y[r.nodeName];V&&V(r,a)}}if(s||(s={}),"string"==typeof n)if("#document"===t.nodeName||"HTML"===t.nodeName){var x=n;n=p.createElement("html"),n.innerHTML=x}else n=r(n);var w,N=s.getNodeKey||d,_=s.onBeforeNodeAdded||l,A=s.onNodeAdded||l,k=s.onBeforeElUpdated||l,E=s.onElUpdated||l,C=s.onBeforeNodeDiscarded||l,R=s.onNodeDiscarded||l,I=s.onBeforeElChildrenUpdated||l,O=!0===s.childrenOnly,T={};h(t);var V=t,j=V.nodeType,M=n.nodeType;if(!O)if(j===g)M===g?i(t,n)||(R(t),V=o(t,a(n.nodeName,n.namespaceURI))):V=n;else if(j===b||j===S){if(M===j)return V.nodeValue!==n.nodeValue&&(V.nodeValue=n.nodeValue),V;V=n}if(V===n)R(t);else if(m(V,n,O),w)for(var U=0,z=w.length;U<z;U++){var P=T[w[U]];P&&c(P,P.parentNode,!1)}return!O&&V!==t&&t.parentNode&&(V.actualize&&(V=V.actualize(t.ownerDocument||p)),t.parentNode.replaceChild(V,t)),V}}(s);e.exports=x},function(e,t,n){"use strict";var r=function(){this.cssImportStatements=[],this.cssKeyframeStatements=[],this.cssRegex=new RegExp("([\\s\\S]*?){([\\s\\S]*?)}","gi"),this.cssMediaQueryRegex="((@media [\\s\\S]*?){([\\s\\S]*?}\\s*?)})",this.cssKeyframeRegex="((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})",this.combinedCSSRegex="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",this.cssCommentsRegex="(\\/\\*[\\s\\S]*?\\*\\/)",this.cssImportStatementRegex=new RegExp("@import .*?;","gi")};r.prototype.stripComments=function(e){var t=new RegExp(this.cssCommentsRegex,"gi");return e.replace(t,"")},r.prototype.parse=function(e){if(void 0===e)return[];for(var t=[];;){var n=this.cssImportStatementRegex.exec(e);if(null===n)break;this.cssImportStatements.push(n[0]),t.push({selector:"@imports",type:"imports",styles:n[0]})}e=e.replace(this.cssImportStatementRegex,"");for(var r,i=new RegExp(this.cssKeyframeRegex,"gi");null!==(r=i.exec(e));)t.push({selector:"@keyframes",type:"keyframes",styles:r[0]});e=e.replace(i,"");for(var a=new RegExp(this.combinedCSSRegex,"gi");null!==(r=a.exec(e));){var o="";o=void 0===r[2]?r[5].split("\r\n").join("\n").trim():r[2].split("\r\n").join("\n").trim();var s=new RegExp(this.cssCommentsRegex,"gi"),u=s.exec(o);if(null!==u&&(o=o.replace(s,"").trim()),o=o.replace(/\n+/,"\n"),-1!==o.indexOf("@media")){var l={selector:o,type:"media",subStyles:this.parse(r[3]+"\n}")};null!==u&&(l.comments=u[0]),t.push(l)}else{var d=this.parseRules(r[6]),f={selector:o,rules:d};"@font-face"===o&&(f.type="font-face"),null!==u&&(f.comments=u[0]),t.push(f)}}return t},r.prototype.parseRules=function(e){e=e.split("\r\n").join("\n");var t=[];e=e.split(";");for(var n=0;n<e.length;n++){var r=e[n];if(r=r.trim(),-1!==r.indexOf(":")){r=r.split(":");var i=r[0].trim(),a=r.slice(1).join(":").trim();if(i.length<1||a.length<1)continue;t.push({directive:i,value:a})}else"base64,"===r.trim().substr(0,7)?t[t.length-1].value+=r.trim():r.length>0&&t.push({directive:"",value:r,defective:!0})}return t},r.prototype.serialize=function(e){var t="";void 0===e&&(e=this.css);for(var n=0;n<e.length;n++)"imports"===e[n].type&&(t+=e[n].styles+"\n\n");for(n=0;n<e.length;n++){var r=e[n];if(void 0!==r.selector){var i="";void 0!==r.comments&&(i=r.comments+"\n"),"media"===r.type?(t+=i+r.selector+"{\n",t+=this.getCSSForEditor(r.subStyles,1),t+="}\n\n"):"keyframes"!==r.type&&"imports"!==r.type&&(t+=this.getSpaces(0)+i+r.selector+" {\n",t+=this.getCSSOfRules(r.rules,1),t+=this.getSpaces(0)+"}\n\n")}}for(n=0;n<e.length;n++)"keyframes"===e[n].type&&(t+=e[n].styles+"\n\n");return t},r.prototype.getCSSOfRules=function(e,t){for(var n="",r=0;r<e.length;r++)void 0!==e[r]&&(void 0===e[r].defective?n+=this.getSpaces(t)+e[r].directive+": "+e[r].value+";\n":n+=this.getSpaces(t)+e[r].value+";\n");return n||"\n"},r.prototype.getSpaces=function(e){for(var t="",n=0;n<4*e;n++)t+=" ";return t},r.prototype.namespace=function(e,t){var n=e,r=t;"string"==typeof e&&(n=this.parse(e));for(var i=0;i<n.length;i++){var a=n[i];if(!(a.selector.indexOf("@font-face")>-1||a.selector.indexOf("keyframes")>-1||a.selector.indexOf("@import")>-1||a.selector.indexOf(".form-all")>-1||a.selector.indexOf("#stage")>-1))if("media"!==a.type){for(var o=a.selector.split(","),s=[],u=0;u<o.length;u++){var l=r+" "+o[u],d=o[u].trim().replace(/\s|$/,r+" ");s.push(l+","+d)}a.selector=s.join(",")}else a.subStyles=this.namespace(a.subStyles,t)}return n},e.exports=new r}])});