0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2025-01-11 01:10:08 -05:00
Squire/build/squire.js

1 line
27 KiB
JavaScript
Raw Normal View History

(function(e){"use strict";function t(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function n(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function r(e,t,n){if(e.nodeName!==t)return!1;for(var r in n)if(e.getAttribute(r)!==n[r])return!1;return!0}function o(e,t){return e.nodeType===t.nodeType&&e.nodeName===t.nodeName&&e.className===t.className&&(!e.style&&!t.style||e.style.cssText===t.style.cssText)}function i(e){return e.nodeType===x&&!!et[e.nodeName]}function a(e){return J.test(e.nodeName)}function d(e){return e.nodeType===x&&!a(e)&&n(e.childNodes,a)}function l(e){return e.nodeType===x&&!a(e)&&!d(e)}function s(e){return d(e)?I:L}function f(e){var n=e.ownerDocument,r=new t(n.body,B,s,!1);return r.currentNode=e,r}function c(e){return f(e).previousNode()}function u(e){return f(e).nextNode()}function p(e,t,n){do if(r(e,t,n))return e;while(e=e.parentNode);return null}function h(e){var t,n,r,o,i=e.parentNode;return i&&e.nodeType===x?(t=h(i),t+=(t?">":"")+e.nodeName,(n=e.id)&&(t+="#"+n),(r=e.className.trim())&&(o=r.split(/\s\s*/),o.sort(),t+=".",t+=o.join("."))):t=i?h(i):"",t}function N(e){var t=e.nodeType;return t===x?e.childNodes.length:e.length||0}function C(e){var t=e.parentNode;return t&&t.removeChild(e),e}function v(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function m(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function g(e){var t,n,r=e.ownerDocument,o=e;if("BODY"===e.nodeName&&((n=e.firstChild)&&"BR"!==n.nodeName||(t=r.createElement("DIV"),n?e.replaceChild(t,n):e.appendChild(t),e=t,t=null)),a(e))e.firstChild||(j?(t=r.createTextNode(""),kt(t)):t=r.createTextNode(""));else if($){for(;e.nodeType!==D&&!i(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===D?/^ +$/.test(e.data)&&(e.data=""):i(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!a(n);)e=n;return t&&e.appendChild(t),o}function y(e,t,n){var r,o,i,a=e.nodeType;if(a===D&&e!==n)return y(e.parentNode,e.splitText(t),n);if(a===x){if("number"==typeof t&&(t=e.childNodes.length>t?e.childNodes[t]:null),e===n)return t;for(r=e.parentNode,o=e.cloneNode(!1);t;)i=t.nextSibling,o.appendChild(t),t=i;return g(e),g(o),(i=e.nextSibling)?r.insertBefore(o,i):r.appendChild(o),y(r,o,n)}return t}function T(e,t){if(e.nodeType===x)for(var n,r,i,d=e.childNodes,l=d.length,s=[];l--;)if(n=d[l],r=l&&d[l-1],l&&a(n)&&o(n,r)&&!et[n.nodeName])t.startContainer===n&&(t.startContainer=r,t.startOffset+=N(r)),t.endContainer===n&&(t.endContainer=r,t.endOffset+=N(r)),t.startContainer===e&&(t.startOffset>l?t.startOffset-=1:t.startOffset===l&&(t.startContainer=r,t.startOffset=N(r))),t.endContainer===e&&(t.endOffset>l?t.endOffset-=1:t.endOffset===l&&(t.endContainer=r,t.endOffset=N(r))),C(n),n.nodeType===D?r.appendData(n.data.replace(/\u200B/g,"")):s.push(m(n));else if(n.nodeType===x){for(i=s.length;i--;)n.appendChild(s.pop());T(n,t)}}function S(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;C(a),o=e.childNodes.length,r=e.lastChild,r&&"BR"===r.nodeName&&(e.removeChild(r),o-=1),i={startContainer:e,startOffset:o,endContainer:e,endOffset:o},e.appendChild(m(t)),T(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),G&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function O(e){var t=e.previousSibling,n=e.firstChild;t&&o(t,e)&&l(t)&&(C(e),t.appendChild(m(e)),n&&O(n))}function b(t,n,r){var o,i,a,d=e.createElement(t);if(n instanceof Array&&(r=n,n=null),n)for(o in n)d.setAttribute(o,n[o]);if(r)for(i=0,a=r.length;a>i;i+=1)d.appendChild(r[i]);return d}var E=2,x=1,D=3,B=1,A=4,I=1,L=3,R=0,w=1,P=2,U=3,k=e.defaultView,V=e.body,H=navigator.userAgent,z=/iP(?:ad|hone|od)/.test(H),M=/Mac OS X/.test(H),F=/Gecko\//.test(H),K=/Trident\//.test(H),q=8===k.ie,G=!!k.opera,Q=/WebKit\//.test(H),Y=M?"meta-":"ctrl-",$=K||G,j=K||Q,W=K,X=/\S/,Z=Array.prototype.indexOf,_={1:1,2:2,3:4,8:128,9:256,11:1024};t.prototype.nextNode=function(){for(var e,t=this.currentNode,n=t