0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 23:40:35 -05:00
Squire/build/squire.js

1 line
50 KiB
JavaScript
Raw Normal View History

!function(e,t){"use strict";var n=1,i=3,o=9,r=11,a=1,s="",d=e.defaultView,l=navigator.userAgent,c=/Android/.test(l),h=/Mac OS X/.test(l),u=/Windows NT/.test(l),f=/iP(?:ad|hone|od)/.test(l)||h&&!!navigator.maxTouchPoints,p=/Gecko\//.test(l),g=/Edge\//.test(l),m=!g&&/WebKit\//.test(l),v=/Trident\/[4567]\./.test(l),_=h?"meta-":"ctrl-",C=m,N="undefined"!=typeof MutationObserver,S="undefined"!=typeof WeakMap,y=/[^ \t\r\n]/,T=Array.prototype.indexOf,E={1:1,2:2,3:4,8:128,9:256,11:1024},b=function(){return!0};function k(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n||b}k.prototype.nextNode=function(){for(var e,t=this.currentNode,n=this.root,i=this.nodeType,o=this.filter;;){for(e=t.firstChild;!e&&t&&t!==n;)(e=t.nextSibling)||(t=t.parentNode);if(!e)return null;if(E[e.nodeType]&i&&o(e))return this.currentNode=e,e;t=e}},k.prototype.previousNode=function(){for(var e,t=this.currentNode,n=this.root,i=this.nodeType,o=this.filter;;){if(t===n)return null;if(e=t.previousSibling)for(;t=e.lastChild;)e=t;else e=t.parentNode;if(!e)return null;if(E[e.nodeType]&i&&o(e))return this.currentNode=e,e;t=e}},k.prototype.previousPONode=function(){for(var e,t=this.currentNode,n=this.root,i=this.nodeType,o=this.filter;;){for(e=t.lastChild;!e&&t&&t!==n;)(e=t.previousSibling)||(t=t.parentNode);if(!e)return null;if(E[e.nodeType]&i&&o(e))return this.currentNode=e,e;t=e}};var L=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:FRAME|MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|TIME|U|VAR|WBR)$/,x={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1};var A=0,B=1,O=2,R=3,D=S?new WeakMap:null;function P(e){return e.nodeType===n&&!!x[e.nodeName]}function U(e){switch(e.nodeType){case i:return B;case n:case r:if(S&&D.has(e))return D.get(e);break;default:return A}var t;return t=function(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}(e.childNodes,I)?L.test(e.nodeName)?B:O:R,S&&D.set(e,t),t}function I(e){return U(e)===B}function F(e){return U(e)===O}function w(e){return U(e)===R}function M(e,t){var n=new k(t,a,F);return n.currentNode=e,n}function H(e,t){return(e=M(e,t).previousNode())!==t?e:null}function W(e,t){return(e=M(e,t).nextNode())!==t?e:null}function z(e){return!e.textContent&&!e.querySelector("IMG")}function q(e,t){return!P(e)&&e.nodeType===t.nodeType&&e.nodeName===t.nodeName&&"A"!==e.nodeName&&e.className===t.className&&(!e.style&&!t.style||e.style.cssText===t.style.cssText)}function K(e,t,n){if(e.nodeName!==t)return!1;for(var i in n)if(e.getAttribute(i)!==n[i])return!1;return!0}function G(e,t,n,i){for(;e&&e!==t;){if(K(e,n,i))return e;e=e.parentNode}return null}function Z(e,t){for(;t;){if(t===e)return!0;t=t.parentNode}return!1}function Q(e){var t=e.nodeType;return t===n||t===r?e.childNodes.length:e.length||0}function $(e){var t=e.parentNode;return t&&t.removeChild(e),e}function j(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function V(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,i=n?n.length:0;i--;)t.appendChild(e.firstChild);return t}function Y(e,n,i,o){var r,a,s,d,l=e.createElement(n);if(i instanceof Array&&(o=i,i=null),i)for(r in i)(a=i[r])!==t&&l.setAttribute(r,a);if(o)for(s=0,d=o.length;s<d;s+=1)l.appendChild(o[s]);return l}function X(e,t){var n,o,r=t.__squire__,a=e.ownerDocument,d=e;if(e===t&&((o=e.firstChild)&&"BR"!==o.nodeName||(n=r.createDefaultBlock(),o?e.replaceChild(n,o):e.appendChild(n),e=n,n=null)),e.nodeType===i)return d;if(I(e)){for(o=e.firstChild;C&&o&&o.nodeType===i&&!o.data;)e.removeChild(o),o=e.firstChild;o||(C?(n=a.createTextNode(s),r._didAddZWS()):n=a.createTextNode(""))}else if(!e.querySelector("BR"))for(n=Y(a,"BR");(o=e.lastElementChild)&&!I(o);)e=o;if(n)try{e.appendChild(n)}catch(t){r.didError({name:"Squire: fixCursor  "+t,message:"Parent: "+e.nodeName+"/"+e.innerHTML+" appendChild: "+n.nodeName})}return d}function J(e,t){var n,i,o,r,a=e.childNodes,s=e.ownerDocument,d=null;t.__squire__._config;for(n=0,i=a.length;n<i;n+=1)!(r="BR"===(o=a[n]).nodeName)&&I(o)?(d||(d=Y(s,"div")),d.appendChild(o),n-=1,i-=1):(r||d)&&(d||(d=Y(s,"div")