diff --git a/src/AngleSharp.Js.Tests/AngleSharp.Js.Tests.csproj b/src/AngleSharp.Js.Tests/AngleSharp.Js.Tests.csproj index 035fc32..01bfbe1 100644 --- a/src/AngleSharp.Js.Tests/AngleSharp.Js.Tests.csproj +++ b/src/AngleSharp.Js.Tests/AngleSharp.Js.Tests.csproj @@ -18,6 +18,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/AngleSharp.Js.Tests/Constants.cs b/src/AngleSharp.Js.Tests/Constants.cs index d9be29d..81fa93d 100644 --- a/src/AngleSharp.Js.Tests/Constants.cs +++ b/src/AngleSharp.Js.Tests/Constants.cs @@ -421,5 +421,164 @@ get Default(){return Tn}static get DefaultType(){return Cn}static get NAME(){ret ,Js).defaultPrevented||(this._element.classList.add(so),this._queueCallback((()=>{this._element.classList.add(io),this._element.classList.remove(so,no),N.trigger(this._element,Zs)}),this._element,this._config.animation)))}dispose(){this._clearTimeout(),this.isShown()&&this._element.classList.remove(no),super.dispose()}isShown(){return this._element.classList.contains(no)}_maybeScheduleHide(){this._config.autohide&&(this._hasMouseInteraction||this._hasKeyboardInteraction||(this._timeout=setTimeout((()=>{this.hide()}) ,this._config.delay)))}_onInteraction(t,e){switch(t.type){case""mouseover"":case""mouseout"":this._hasMouseInteraction=e;break;case""focusin"":case""focusout"":this._hasKeyboardInteraction=e}if(e)return void this._clearTimeout();const i=t.relatedTarget;this._element===i||this._element.contains(i)||this._maybeScheduleHide()}_setListeners(){N.on(this._element,Xs,(t=>this._onInteraction(t,!0))),N.on(this._element,Ys,(t=>this._onInteraction(t,!1))),N.on(this._element,Us,(t=>this._onInteraction(t,!0))),N.on(this._element ,Gs,(t=>this._onInteraction(t,!1)))}_clearTimeout(){clearTimeout(this._timeout),this._timeout=null}static jQueryInterface(t){return this.each((function(){const e=ao.getOrCreateInstance(this,t);if(""string""==typeof t){if(void 0===e[t])throw new TypeError(`No method named ""${t}""`);e[t](this)}}))}}return R(ao),m(ao),{Alert:Q,Button:Y,Carousel:xt,Collapse:Bt,Dropdown:qi,Modal:On,Offcanvas:qn,Popover:us,ScrollSpy:Es,Tab:Ks,Toast:ao,Tooltip:cs}})); //# sourceMappingURL=bootstrap.bundle.min.js.map"; + + public static readonly string Jquery4_0_0_ESM = @"/*! jQuery v4.0.0-beta | (c) OpenJS Foundation and other contributors | jquery.org/license */function e(e,t){if(void 0===e||!e.document)throw Error(""jQuery requires a window with a document"");var n=[],r=Object.getPrototypeOf,i=n.slice,o=n.flat?function(e){return n.flat.call(e)}:function(e){return n.concat.apply([],e)},a=n.push,s=n.indexOf,u={},l=u.toString,c=u.hasOwnProperty,f=c.toString,p=f.call(Object),d={};function h(e){return null==e?e+"""":""object""==typeof e?u[l.call(e)]||""object"":typeof e} +function g(e){return null!=e&&e===e.window}function v(e){var t=!!e&&e.length,n=h(e);return!(""function""==typeof e||g(e))&&(""array""===n||0===t||""number""==typeof t&&t>0&&t-1 in e)}var y=e.document,m={type:!0,src:!0,nonce:!0,noModule:!0};function x(e,t,n){var r,i=(n=n||y).createElement(""script"");for(r in i.text=e,m)t&&t[r]&&(i[r]=t[r]);n.head.appendChild(i).parentNode&&i.parentNode.removeChild(i)}var b=""4.0.0-beta"",w=/HTML$/i,T=function(e,t){return new T.fn.init(e,t)};function C(e,t){return + e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()}T.fn=T.prototype={jquery:b,constructor:T,length:0,toArray:function(){return i.call(this)},get:function(e){return null==e?i.call(this):e<0?this[e+this.length]:this[e]},pushStack:function(e){var t=T.merge(this.constructor(),e);return t.prevObject=this,t},each:function(e){return T.each(this,e)},map:function(e){return this.pushStack(T.map(this,(function(t,n){return e.call(t,n,t)})))},slice:function(){return this.pushStack(i.apply(this, + arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},even:function(){return this.pushStack(T.grep(this,(function(e,t){return(t+1)%2})))},odd:function(){return this.pushStack(T.grep(this,(function(e,t){return t%2})))},eq:function(e){var t=this.length,n=+e+(e<0?t:0);return this.pushStack(n>=0&&n+~]|""+E+"")""+E+""*""),N=RegExp(E+""|>""),O=/[+~]/,H=y.documentElement,L=H.matches||H.msMatchesSelector;function P(){var e=[];function t(n,r){return e.push(n+"" "")>T.expr.cacheLength&&delete t[e.shift()],t[n+"" ""]=r}return t}function R(e){return e&&void 0!==e.getElementsByTagName&&e}var M=""\\[""+E+""*(""+A+"")(?:""+E+""*([*^$|!~]?=)""+E+""*(?:'((?:\\\\.|[^\\\\'])*)'|\""((?:\\\\.|[^\\\\\""])*)\""|(""+A+""))|)""+E+ + ""*\\]"",W="":(""+A+"")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\""((?:\\\\.|[^\\\\\""])*)\"")|((?:\\\\.|[^\\\\()[\\]]|""+M+"")*)|.*)\\)|)"",I={ID:RegExp(""^#(""+A+"")""),CLASS:RegExp(""^\\.(""+A+"")""),TAG:RegExp(""^(""+A+""|[*])""),ATTR:RegExp(""^""+M),PSEUDO:RegExp(""^""+W),CHILD:RegExp(""^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(""+E+""*(even|odd|(([+-]|)(\\d*)n|)""+E+""*(?:([+-]|)""+E+""*(\\d+)|))""+E+""*\\)|)"",""i"")},$=new RegExp(W),F=RegExp(""\\\\[\\da-fA-F]{1,6}""+E+""?|\\\\([^\\r\\n\\f])"",""g""),B=function(e,t){var n=""0x""+ + e.slice(1)-65536;return t||(n<0?String.fromCharCode(n+65536):String.fromCharCode(n>>10|55296,1023&n|56320))};function _(e){return e.replace(F,B)}function U(e){T.error(""Syntax error, unrecognized expression: ""+e)}var X=RegExp(""^""+E+""*,""+E+""*""),z=P();function V(e,t){var n,r,i,o,a,s,u,l=z[e+"" ""];if(l)return t?0:l.slice(0);a=e,s=[],u=T.expr.preFilter;while(a){for(o in(!n||(r=X.exec(a)))&&(r&&(a=a.slice(r[0].length)||a),s.push(i=[])),n=!1,(r=q.exec(a))&&(n=r.shift(),i.push({value:n,type:r[0].replace( + D,"" "")}),a=a.slice(n.length)),I)(r=T.expr.match[o].exec(a))&&(!u[o]||(r=u[o](r)))&&(n=r.shift(),i.push({value:n,type:o,matches:r}),a=a.slice(n.length));if(!n)break}return t?a.length:a?U(e):z(e,s).slice(0)}function Y(e){for(var t=0,n=e.length,r="""";t1)},removeAttr:function(e){return this.each((function(){T.removeAttr(this,e)}))}}),T.extend({attr:function(e,t,n){var r,i,o=e.nodeType;if(3!==o&&8!==o&&2!==o){if(void 0===e.getAttribute)return T.prop(e,t,n);if(1===o&&T.isXMLDoc(e)||(i=T.attrHooks[t.toLowerCase()]),void 0!==n){if( + null===n){T.removeAttr(e,t);return}return i&&""set""in i&&void 0!==(r=i.set(e,n,t))?r:(e.setAttribute(t,n),n)}return i&&""get""in i&&null!==(r=i.get(e,t))?r:null==(r=e.getAttribute(t))?void 0:r}},attrHooks:{},removeAttr:function(e,t){var n,r=0,i=t&&t.match(Q);if(i&&1===e.nodeType)while(n=i[r++])e.removeAttribute(n)}}),k&&(T.attrHooks.type={set:function(e,t){if(""radio""===t&&C(e,""input"")){var n=e.value;return e.setAttribute(""type"",t),n&&(e.value=n),t}}}),T.each(""checked selected async autofocus autoplay controls defer disabled hidden ismap loop multiple open readonly required scoped"".split("" ""),(function(e,t){T.attrHooks[t]={get:function(e){return null!=e.getAttribute(t)?t.toLowerCase():null},set:function(e,t,n){return!1===t?T.removeAttr(e,n):e.setAttribute(n,n),n}}}));var J=/([\0-\x1f\x7f]|^-?\d)|^-$|[^\x80-\uFFFF\w-]/g;function K(e,t){return t?""\0""===e?"" "":e.slice(0,-1)+""\\""+e.charCodeAt(e.length-1).toString(16)+"" "":""\\""+e}T.escapeSelector=function(e){return(e+"""").replace(J,K)};var + Z=n.sort,ee=n.splice;function te(e,t){if(e===t)return ne=!0,0;var n=!e.compareDocumentPosition-!t.compareDocumentPosition;return n||(1&(n=(e.ownerDocument||e)==(t.ownerDocument||t)?e.compareDocumentPosition(t):1)?e==y||e.ownerDocument==y&&T.contains(y,e)?-1:t==y||t.ownerDocument==y&&T.contains(y,t)?1:0:4&n?-1:1)}T.uniqueSort=function(e){var t,n=[],r=0,i=0;if(ne=!1,Z.call(e,te),ne){while(t=e[i++])t===e[i]&&(r=n.push(i));while(r--)ee.call(e,n[r],1)}return e},T.fn.uniqueSort=function(){return + this.pushStack(T.uniqueSort(i.apply(this)))};var ne,re,ie,oe,ae,se,ue=0,le=0,ce=P(),fe=P(),pe=P(),de=RegExp(E+""+"",""g""),he=RegExp(""^""+A+""$""),ge=T.extend({needsContext:RegExp(""^""+E+""*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(""+E+""*((?:-\\d)?\\d*)""+E+""*\\)|)(?=[^-]|$)"",""i"")},I),ve=/^(?:input|select|textarea|button)$/i,ye=/^h\d$/i,me=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,xe=function(){Ee()},be=Se((function(e){return!0===e.disabled&&C(e,""fieldset"")}),{dir:""parentNode"",next:""legend""});function we(e, + t,n,r){var i,o,s,u,l,c,f,p=t&&t.ownerDocument,d=t?t.nodeType:9;if(n=n||[],""string""!=typeof e||!e||1!==d&&9!==d&&11!==d)return n;if(!r&&(Ee(t),t=t||oe,se)){if(11!==d&&(l=me.exec(e))){if(i=l[1]){if(9===d)return(s=t.getElementById(i))&&a.call(n,s),n;if(p&&(s=p.getElementById(i))&&T.contains(t,s))return a.call(n,s),n}else if(l[2])return a.apply(n,t.getElementsByTagName(e)),n;else if((i=l[3])&&t.getElementsByClassName)return a.apply(n,t.getElementsByClassName(i)),n}if(!pe[e+"" ""]&&(!S||!S.test(e))){ + if(f=e,p=t,1===d&&(N.test(e)||q.test(e))){((p=O.test(e)&&R(t.parentNode)||t)!=t||k)&&((u=t.getAttribute(""id""))?u=T.escapeSelector(u):t.setAttribute(""id"",u=T.expando)),o=(c=V(e)).length;while(o--)c[o]=(u?""#""+u:"":scope"")+"" ""+Y(c[o]);f=c.join("","")}try{return a.apply(n,p.querySelectorAll(f)),n}catch(t){pe(e,!0)}finally{u===T.expando&&t.removeAttribute(""id"")}}}return Ne(e.replace(D,""$1""),t,n,r)}function Te(e){return e[T.expando]=!0,e}function Ce(e){return function(t){if(""form""in t)return + t.parentNode&&!1===t.disabled?""label""in t?""label""in t.parentNode?t.parentNode.disabled===e:t.disabled===e:t.isDisabled===e||!e!==t.isDisabled&&be(t)===e:t.disabled===e;return""label""in t&&t.disabled===e}}function je(e){return Te((function(t){return t=+t,Te((function(n,r){var i,o=e([],n.length,t),a=o.length;while(a--)n[i=o[a]]&&(n[i]=!(r[i]=n[i]))}))}))}function Ee(e){var t,n=e?e.ownerDocument||e:y;n!=oe&&9===n.nodeType&&(ae=(oe=n).documentElement,se=!T.isXMLDoc(oe),k&&y!=oe&&(t=oe.defaultView) + &&t.top!==t&&t.addEventListener(""unload"",xe))}for(re in we.matches=function(e,t){return we(e,null,null,t)},we.matchesSelector=function(e,t){if(Ee(e),se&&!pe[t+"" ""]&&(!S||!S.test(t)))try{return L.call(e,t)}catch(e){pe(t,!0)}return we(t,oe,null,[e]).length>0},T.expr={cacheLength:50,createPseudo:Te,match:ge,find:{ID:function(e,t){if(void 0!==t.getElementById&&se){var n=t.getElementById(e);return n?[n]:[]}},TAG:function(e,t){return void 0!==t.getElementsByTagName?t.getElementsByTagName(e): + t.querySelectorAll(e)},CLASS:function(e,t){if(void 0!==t.getElementsByClassName&&se)return t.getElementsByClassName(e)}},relative:{"">"":{dir:""parentNode"",first:!0},"" "":{dir:""parentNode""},""+"":{dir:""previousSibling"",first:!0},""~"":{dir:""previousSibling""}},preFilter:{ATTR:function(e){return e[1]=_(e[1]),e[3]=_(e[3]||e[4]||e[5]||""""),""~=""===e[2]&&(e[3]="" ""+e[3]+"" ""),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),""nth""===e[1].slice(0,3)?(e[3]||U(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*( + ""even""===e[3]||""odd""===e[3])),e[5]=+(e[7]+e[8]||""odd""===e[3])):e[3]&&U(e[0]),e},PSEUDO:function(e){var t,n=!e[6]&&e[2];return I.CHILD.test(e[0])?null:(e[3]?e[2]=e[4]||e[5]||"""":n&&$.test(n)&&(t=V(n,!0))&&(t=n.indexOf("")"",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{ID:function(e){var t=_(e);return function(e){return e.getAttribute(""id"")===t}},TAG:function(e){var t=_(e).toLowerCase();return""*""===e?function(){return!0}:function(e){return C(e,t)}},CLASS: + function(e){var t=ce[e+"" ""];return t||(t=RegExp(""(^|""+E+"")""+e+""(""+E+""|$)""),ce(e,(function(e){return t.test(""string""==typeof e.className&&e.className||void 0!==e.getAttribute&&e.getAttribute(""class"")||"""")})))},ATTR:function(e,t,n){return function(r){var i=T.attr(r,e);return null==i?""!=""===t:!t||((i+="""",""=""===t)?i===n:""!=""===t?i!==n:""^=""===t?n&&0===i.indexOf(n):""*=""===t?n&&i.indexOf(n)>-1:""$=""===t?n&&i.slice(-n.length)===n:""~=""===t?("" ""+i.replace(de,"" "")+"" "").indexOf(n)>-1:""|=""===t&&(i===n|| + i.slice(0,n.length+1)===n+""-""))}},CHILD:function(e,t,n,r,i){var o=""nth""!==e.slice(0,3),a=""last""!==e.slice(-4),s=""of-type""===t;return 1===r&&0===i?function(e){return!!e.parentNode}:function(t,n,u){var l,c,f,p,d,h=o!==a?""nextSibling"":""previousSibling"",g=t.parentNode,v=s&&t.nodeName.toLowerCase(),y=!u&&!s,m=!1;if(g){if(o){while(h){f=t;while(f=f[h])if(s?C(f,v):1===f.nodeType)return!1;d=h=""only""===e&&!d&&""nextSibling""}return!0}if(d=[a?g.firstChild:g.lastChild],a&&y){m=(p=(l=(c=g[T.expando]||(g[ + T.expando]={}))[e]||[])[0]===ue&&l[1])&&l[2],f=p&&g.childNodes[p];while(f=++p&&f&&f[h]||(m=p=0)||d.pop())if(1===f.nodeType&&++m&&f===t){c[e]=[ue,p,m];break}}else if(y&&(m=p=(l=(c=t[T.expando]||(t[T.expando]={}))[e]||[])[0]===ue&&l[1]),!1===m){while(f=++p&&f&&f[h]||(m=p=0)||d.pop())if((s?C(f,v):1===f.nodeType)&&++m&&(y&&((c=f[T.expando]||(f[T.expando]={}))[e]=[ue,m]),f===t))break}return(m-=i)===r||m%r==0&&m/r>=0}}},PSEUDO:function(e,t){var n=T.expr.pseudos[e]||T.expr.setFilters[e.toLowerCase()]|| + U(""unsupported pseudo: ""+e);return n[T.expando]?n(t):n}},pseudos:{not:Te((function(e){var t=[],n=[],r=qe(e.replace(D,""$1""));return r[T.expando]?Te((function(e,t,n,i){var o,a=r(e,null,i,[]),s=e.length;while(s--)(o=a[s])&&(e[s]=!(t[s]=o))})):function(e,i,o){return t[0]=e,r(t,null,o,n),t[0]=null,!n.pop()}})),has:Te((function(e){return function(t){return we(e,t).length>0}})),contains:Te((function(e){return e=_(e),function(t){return(t.textContent||T.text(t)).indexOf(e)>-1}})),lang:Te((function(e){ + return he.test(e||"""")||U(""unsupported lang: ""+e),e=_(e).toLowerCase(),function(t){var n;do{if(n=se?t.lang:t.getAttribute(""xml:lang"")||t.getAttribute(""lang""))return(n=n.toLowerCase())===e||0===n.indexOf(e+""-"")}while((t=t.parentNode)&&1===t.nodeType);return!1}})),target:function(t){var n=e.location&&e.location.hash;return n&&n.slice(1)===t.id},root:function(e){return e===ae},focus:function(e){return e===oe.activeElement&&oe.hasFocus()&&!!(e.type||e.href||~e.tabIndex)},enabled:Ce(!1),disabled:Ce( + !0),checked:function(e){return C(e,""input"")&&!!e.checked||C(e,""option"")&&!!e.selected},selected:function(e){return k&&e.parentNode&&e.parentNode.selectedIndex,!0===e.selected},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeType<6)return!1;return!0},parent:function(e){return!T.expr.pseudos.empty(e)},header:function(e){return ye.test(e.nodeName)},input:function(e){return ve.test(e.nodeName)},button:function(e){return C(e,""input"")&&""button""===e.type||C(e,""button"")},text:function( + e){return C(e,""input"")&&""text""===e.type},first:je((function(){return[0]})),last:je((function(e,t){return[t-1]})),eq:je((function(e,t,n){return[n<0?n+t:n]})),even:je((function(e,t){for(var n=0;nt?t:n;--r>=0;)e.push(r);return e})),gt:je((function(e,t,n){for(var r=n<0?n+t:n;++r1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function Ae(e,t,n,r,i){for(var o,a=[],s=0,u=e.length,l=null!=t;s-1}),l,!0),d=[function(e,t,r){var i=!u&&(r||t!=ie)||((n=t).nodeType?f(e,t,r):p(e,t,r));return n=null,i}];c-1&&(e[f]=!(u[f]=d))}}else h=Ae(h===u?h.splice(y,h.length):h),o?o(null,u,h,c):a.apply(u,h)}))}(c>1&&De(d),c>1&&Y(t.slice(0,c-1).concat({value:"" ""===t[c-2].type?""*"":""""})).replace(D,""$1""),r,c0,r=l.length>0,i=function(e,t,i,o,s){var c,f,p,d=0,h=""0"",g=e&&[],v=[],y=ie,m=e|| + r&&T.expr.find.TAG(""*"",s),x=ue+=null==y?1:Math.random()||.1;for(s&&(ie=t==oe||t||s);null!=(c=m[h]);h++){if(r&&c){f=0,t||c.ownerDocument==oe||(Ee(c),i=!se);while(p=l[f++])if(p(c,t||oe,i)){a.call(o,c);break}s&&(ue=x)}n&&((c=!p&&c)&&d--,e&&g.push(c))}if(d+=h,n&&h!==d){f=0;while(p=u[f++])p(g,v,t,i);if(e){if(d>0)while(h--)g[h]||v[h]||(v[h]=j.call(o));v=Ae(v)}a.apply(o,v),s&&!e&&v.length>0&&d+u.length>1&&T.uniqueSort(o)}return s&&(ue=x,ie=y),g},n?Te(i):i))).selector=e}return c}function Ne(e,t,n,r){ + var i,o,s,u,l,c=""function""==typeof e&&e,f=!r&&V(e=c.selector||e);if(n=n||[],1===f.length){if((o=f[0]=f[0].slice(0)).length>2&&""ID""===(s=o[0]).type&&9===t.nodeType&&se&&T.expr.relative[o[1].type]){if(!(t=(T.expr.find.ID(_(s.matches[0]),t)||[])[0]))return n;c&&(t=t.parentNode),e=e.slice(o.shift().value.length)}i=ge.needsContext.test(e)?0:o.length;while(i--){if(s=o[i],T.expr.relative[u=s.type])break;if((l=T.expr.find[u])&&(r=l(_(s.matches[0]),O.test(o[0].type)&&R(t.parentNode)||t))){if(o.splice(i, + 1),!(e=r.length&&Y(o)))return a.apply(n,r),n;break}}}return(c||qe(e,f))(r,t,!se,n,!t||O.test(e)&&R(t.parentNode)||t),n}function Oe(e,t,n){var r=[],i=void 0!==n;while((e=e[t])&&9!==e.nodeType)if(1===e.nodeType){if(i&&T(e).is(n))break;r.push(e)}return r}function He(e,t){for(var n=[];e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n}ke.prototype=T.expr.filters=T.expr.pseudos,T.expr.setFilters=new ke,Ee(),T.find=we,we.compile=qe,we.select=Ne,we.setDocument=Ee,we.tokenize=V;var + Le=T.expr.match.needsContext,Pe=/^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i;function Re(e){return""<""===e[0]&&"">""===e[e.length-1]&&e.length>=3}function Me(e,t,n){return""function""==typeof t?T.grep(e,(function(e,r){return!!t.call(e,r,e)!==n})):t.nodeType?T.grep(e,(function(e){return e===t!==n})):""string""!=typeof t?T.grep(e,(function(e){return s.call(t,e)>-1!==n})):T.filter(t,e,n)}T.filter=function(e,t,n){var r=t[0];return(n&&(e="":not(""+e+"")""),1===t.length&&1===r.nodeType) + ?T.find.matchesSelector(r,e)?[r]:[]:T.find.matches(e,T.grep(t,(function(e){return 1===e.nodeType})))},T.fn.extend({find:function(e){var t,n,r=this.length,i=this;if(""string""!=typeof e)return this.pushStack(T(e).filter((function(){for(t=0;t1?T.uniqueSort(n):n},filter:function(e){return this.pushStack(Me(this,e||[],!1))},not:function(e){return this.pushStack(Me(this,e||[],!0))},is:function( + e){return!!Me(this,""string""==typeof e&&Le.test(e)?T(e):e||[],!1).length}});var We,Ie=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/;(T.fn.init=function(e,t){var n,r;if(!e)return this;if(e.nodeType)return this[0]=e,this.length=1,this;if(""function""==typeof e)return void 0!==We.ready?We.ready(e):e(T);if(Re(n=e+""""))n=[null,e,null];else{if(""string""!=typeof e)return T.makeArray(e,this);n=Ie.exec(e)}if(n&&(n[1]||!t)){if(!n[1])return(r=y.getElementById(n[2]))&&(this[0]=r,this.length=1),this;if(t=t instanceof + T?t[0]:t,T.merge(this,T.parseHTML(n[1],t&&t.nodeType?t.ownerDocument||t:y,!0)),Pe.test(n[1])&&T.isPlainObject(t))for(n in t)""function""==typeof this[n]?this[n](t[n]):this.attr(n,t[n]);return this}return!t||t.jquery?(t||We).find(e):this.constructor(t).find(e)}).prototype=T.fn,We=T(y);var $e=/^(?:parents|prev(?:Until|All))/,Fe={children:!0,contents:!0,next:!0,prev:!0};function Be(e,t){while((e=e[t])&&1!==e.nodeType);return e}function _e(e){return e}function Ue(e){throw e}function Xe(e,t,n,r){var i; + try{e&&""function""==typeof(i=e.promise)?i.call(e).done(t).fail(n):e&&""function""==typeof(i=e.then)?i.call(e,t,n):t.apply(void 0,[e].slice(r))}catch(e){n(e)}}T.fn.extend({has:function(e){var t=T(e,this),n=t.length;return this.filter((function(){for(var e=0;e-1: + 1===n.nodeType&&T.find.matchesSelector(n,e))){o.push(n);break}}return this.pushStack(o.length>1?T.uniqueSort(o):o)},index:function(e){return e?""string""==typeof e?s.call(T(e),this[0]):s.call(this,e.jquery?e[0]:e):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){return this.pushStack(T.uniqueSort(T.merge(this.get(),T(e,t))))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}}),T.each({parent:function(e){var t=e.parentNode;return + t&&11!==t.nodeType?t:null},parents:function(e){return Oe(e,""parentNode"")},parentsUntil:function(e,t,n){return Oe(e,""parentNode"",n)},next:function(e){return Be(e,""nextSibling"")},prev:function(e){return Be(e,""previousSibling"")},nextAll:function(e){return Oe(e,""nextSibling"")},prevAll:function(e){return Oe(e,""previousSibling"")},nextUntil:function(e,t,n){return Oe(e,""nextSibling"",n)},prevUntil:function(e,t,n){return Oe(e,""previousSibling"",n)},siblings:function(e){return He((e.parentNode||{}) + .firstChild,e)},children:function(e){return He(e.firstChild)},contents:function(e){return null!=e.contentDocument&&r(e.contentDocument)?e.contentDocument:(C(e,""template"")&&(e=e.content||e),T.merge([],e.childNodes))}},(function(e,t){T.fn[e]=function(n,r){var i=T.map(this,t,n);return""Until""!==e.slice(-5)&&(r=n),r&&""string""==typeof r&&(i=T.filter(r,i)),this.length>1&&(Fe[e]||T.uniqueSort(i),$e.test(e)&&i.reverse()),this.pushStack(i)}})),T.Callbacks=function(e){e=""string""==typeof e?(t=e,n={},T.each( + t.match(Q)||[],(function(e,t){n[t]=!0})),n):T.extend({},e);var t,n,r,i,o,a,s=[],u=[],l=-1,c=function(){for(a=a||e.once,o=r=!0;u.length;l=-1){i=u.shift();while(++l-1)s.splice(n,1),n<=l&&l--})),this},has:function(e){return e?T.inArray(e,s)>-1:s.length>0},empty:function(){return s&&(s=[]),this},disable:function(){return a=u=[],s=i="""",this},disabled:function(){return!s},lock:function(){return a=u=[],i||r||(s=i=""""),this},locked:function(){return!!a},fireWith:function(e,t){return a||(t=[e,(t=t||[]).slice?t.slice():t],u.push(t),r||c()),this},fire:function(){return f.fireWith( + this,arguments),this},fired:function(){return!!o}};return f},T.extend({Deferred:function(t){var n=[[""notify"",""progress"",T.Callbacks(""memory""),T.Callbacks(""memory""),2],[""resolve"",""done"",T.Callbacks(""once memory""),T.Callbacks(""once memory""),0,""resolved""],[""reject"",""fail"",T.Callbacks(""once memory""),T.Callbacks(""once memory""),1,""rejected""]],r=""pending"",i={state:function(){return r},always:function(){return o.done(arguments).fail(arguments),this},catch:function(e){return i.then(null,e)},pipe: + function(){var e=arguments;return T.Deferred((function(t){T.each(n,(function(n,r){var i=""function""==typeof e[r[4]]&&e[r[4]];o[r[1]]((function(){var e=i&&i.apply(this,arguments);e&&""function""==typeof e.promise?e.promise().progress(t.notify).done(t.resolve).fail(t.reject):t[r[0]+""With""](this,i?[e]:arguments)}))})),e=null})).promise()},then:function(t,r,i){var o=0;function a(t,n,r,i){return function(){var s=this,u=arguments,l=function(){var e,l;if(!(t=o&&(r!==Ue&&(s=void 0,u=[e]),n.rejectWith(s,u))}};t?c():(T.Deferred.getErrorHook&&(c.error=T.Deferred.getErrorHook()),e.setTimeout( + c))}}return T.Deferred((function(e){n[0][3].add(a(0,e,""function""==typeof i?i:_e,e.notifyWith)),n[1][3].add(a(0,e,""function""==typeof t?t:_e)),n[2][3].add(a(0,e,""function""==typeof r?r:Ue))})).promise()},promise:function(e){return null!=e?T.extend(e,i):i}},o={};return T.each(n,(function(e,t){var a=t[2],s=t[5];i[t[1]]=a.add,s&&a.add((function(){r=s}),n[3-e][2].disable,n[3-e][3].disable,n[0][2].lock,n[0][3].lock),a.add(t[3].fire),o[t[0]]=function(){return o[t[0]+""With""](this===o?void 0:this, + arguments),this},o[t[0]+""With""]=a.fireWith})),i.promise(o),t&&t.call(o,o),o},when:function(e){var t=arguments.length,n=t,r=Array(n),o=i.call(arguments),a=T.Deferred(),s=function(e){return function(n){r[e]=this,o[e]=arguments.length>1?i.call(arguments):n,--t||a.resolveWith(r,o)}};if(t<=1&&(Xe(e,a.done(s(n)).resolve,a.reject,!t),""pending""===a.state()||""function""==typeof(o[n]&&o[n].then)))return a.then();while(n--)Xe(o[n],s(n),a.reject);return a.promise()}});var ze= + /^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;T.Deferred.exceptionHook=function(t,n){t&&ze.test(t.name)&&e.console.warn(""jQuery.Deferred exception"",t,n)},T.readyException=function(t){e.setTimeout((function(){throw t}))};var Ve=T.Deferred();function Ye(){y.removeEventListener(""DOMContentLoaded"",Ye),e.removeEventListener(""load"",Ye),T.ready()}T.fn.ready=function(e){return Ve.then(e).catch((function(e){T.readyException(e)})),this},T.extend({isReady:!1,readyWait:1,ready:function(e){!(!0===e?--T.readyWait:T.isReady)&&( + T.isReady=!0,!0!==e&&--T.readyWait>0||Ve.resolveWith(y,[T]))}}),T.ready.then=Ve.then,""loading""!==y.readyState?e.setTimeout(T.ready):(y.addEventListener(""DOMContentLoaded"",Ye),e.addEventListener(""load"",Ye));var Ge=/-([a-z])/g;function Qe(e,t){return t.toUpperCase()}function Je(e){return e.replace(Ge,Qe)}function Ke(e){return 1===e.nodeType||9===e.nodeType||!+e.nodeType}function Ze(){this.expando=T.expando+Ze.uid++}Ze.uid=1,Ze.prototype={cache:function(e){var t=e[this.expando];return!t&&( + t=Object.create(null),Ke(e)&&(e.nodeType?e[this.expando]=t:Object.defineProperty(e,this.expando,{value:t,configurable:!0}))),t},set:function(e,t,n){var r,i=this.cache(e);if(""string""==typeof t)i[Je(t)]=n;else for(r in t)i[Je(r)]=t[r];return n},get:function(e,t){return void 0===t?this.cache(e):e[this.expando]&&e[this.expando][Je(t)]},access:function(e,t,n){return void 0===t||t&&""string""==typeof t&&void 0===n?this.get(e,t):(this.set(e,t,n),void 0!==n?n:t)},remove:function(e,t){var n,r=e[ + this.expando];if(void 0!==r){if(void 0!==t){n=(t=Array.isArray(t)?t.map(Je):(t=Je(t))in r?[t]:t.match(Q)||[]).length;while(n--)delete r[t[n]]}(void 0===t||T.isEmptyObject(r))&&(e.nodeType?e[this.expando]=void 0:delete e[this.expando])}},hasData:function(e){var t=e[this.expando];return void 0!==t&&!T.isEmptyObject(t)}};var et=new Ze,tt=new Ze,nt=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,rt=/[A-Z]/g;function it(e,t,n){var r,i;if(void 0===n&&1===e.nodeType){if(r=""data-""+t.replace(rt,""-$&"").toLowerCase(), + ""string""==typeof(n=e.getAttribute(r))){try{i=n,n=""true""===i||""false""!==i&&(""null""===i?null:i===+i+""""?+i:nt.test(i)?JSON.parse(i):i)}catch(e){}tt.set(e,t,n)}else n=void 0}return n}T.extend({hasData:function(e){return tt.hasData(e)||et.hasData(e)},data:function(e,t,n){return tt.access(e,t,n)},removeData:function(e,t){tt.remove(e,t)},_data:function(e,t,n){return et.access(e,t,n)},_removeData:function(e,t){et.remove(e,t)}}),T.fn.extend({data:function(e,t){var n,r,i,o=this[0],a=o&&o.attributes;if( + void 0===e){if(this.length&&(i=tt.get(o),1===o.nodeType&&!et.get(o,""hasDataAttrs""))){n=a.length;while(n--)a[n]&&0===(r=a[n].name).indexOf(""data-"")&&it(o,r=Je(r.slice(5)),i[r]);et.set(o,""hasDataAttrs"",!0)}return i}return""object""==typeof e?this.each((function(){tt.set(this,e)})):G(this,(function(t){var n;if(o&&void 0===t)return void 0!==(n=tt.get(o,e))||void 0!==(n=it(o,e))?n:void 0;this.each((function(){tt.set(this,e,t)}))}),null,t,arguments.length>1,null,!0)},removeData:function(e){return + this.each((function(){tt.remove(this,e)}))}}),T.extend({queue:function(e,t,n){var r;if(e)return t=(t||""fx"")+""queue"",r=et.get(e,t),n&&(!r||Array.isArray(n)?r=et.set(e,t,T.makeArray(n)):r.push(n)),r||[]},dequeue:function(e,t){t=t||""fx"";var n=T.queue(e,t),r=n.length,i=n.shift(),o=T._queueHooks(e,t);""inprogress""===i&&(i=n.shift(),r--),i&&(""fx""===t&&n.unshift(""inprogress""),delete o.stop,i.call(e,(function(){T.dequeue(e,t)}),o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+""queueHooks""; + return et.get(e,n)||et.set(e,n,{empty:T.Callbacks(""once memory"").add((function(){et.remove(e,[t+""queue"",n])}))})}}),T.fn.extend({queue:function(e,t){var n=2;return(""string""!=typeof e&&(t=e,e=""fx"",n--),arguments.length\x20\t\r\n\f]*)/i,bt={thead:[""table""],col:[""colgroup"",""table""],tr:[""tbody"",""table""],td:[""tr"",""tbody"",""table""]};function wt(e,t){var n;return(n=void 0!==e.getElementsByTagName?e.getElementsByTagName(t||""*""):void 0!==e.querySelectorAll?e.querySelectorAll(t||""*""):[],void 0===t||t&&C(e,t))?T.merge([e],n):n} + bt.tbody=bt.tfoot=bt.colgroup=bt.caption=bt.thead,bt.th=bt.td;var Tt=/^$|^module$|\/(?:java|ecma)script/i;function Ct(e,t){for(var n=0,r=e.length;n-1)s=s.appendChild(t.createElement(u[c]));s.innerHTML=T.htmlPrefilter(a),T.merge(p,s.childNodes),(s=f.firstChild).textContent=""""}else p.push(t.createTextNode(a))}f.textContent="""",d=0;while(a=p[d++]){if(i&&T.inArray(a,i)>-1){o&&o.push(a);continue}if(l=yt(a),s=wt(f.appendChild(a),""script""),l&&Ct(s),r){c=0;while(a=s[c++])Tt.test(a.type||"""")&&r.push(a)}}return f}function kt(e){return e.type=(null!==e.getAttribute(""type""))+""/""+e.type,e}function St(e){ + return""true/""===(e.type||"""").slice(0,5)?e.type=e.type.slice(5):e.removeAttribute(""type""),e}function Dt(e,t,n,r){t=o(t);var i,a,s,u,l,c,f=0,p=e.length,d=p-1,h=t[0];if(""function""==typeof h)return e.each((function(i){var o=e.eq(i);t[0]=h.call(this,i,o.html()),Dt(o,t,n,r)}));if(p&&(a=(i=Et(t,e[0].ownerDocument,!1,e,r)).firstChild,1===i.childNodes.length&&(i=a),a||r)){for(u=(s=T.map(wt(i,""script""),kt)).length;f=1)){for(;l!==this; + l=l.parentNode||this)if(1===l.nodeType&&!(""click""===e.type&&!0===l.disabled)){for(n=0,o=[],a={};n-1:T.find(i,this,null,[l]).length),a[i]&&o.push(r);o.length&&s.push({elem:l,handlers:o})}}return l=this,u0&&Ct(a,!u&&wt(e,""script"")),s},cleanData:function(e){for(var t,n,r,i=T.event.special,o=0;void 0!==(n=e[o]);o++)if(Ke(n)){if(t=n[et.expando]){ + if(t.events)for(r in t.events)i[r]?T.event.remove(n,r):T.removeEvent(n,r,t.handle);n[et.expando]=void 0}n[tt.expando]&&(n[tt.expando]=void 0)}}}),T.fn.extend({detach:function(e){return Wt(this,e,!0)},remove:function(e){return Wt(this,e)},text:function(e){return G(this,(function(e){return void 0===e?T.text(this):this.empty().each((function(){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&(this.textContent=e)}))}),null,e,arguments.length)},append:function(){return Dt(this,arguments,( + function(e){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&Rt(this,e).appendChild(e)}))},prepend:function(){return Dt(this,arguments,(function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=Rt(this,e);t.insertBefore(e,t.firstChild)}}))},before:function(){return Dt(this,arguments,(function(e){this.parentNode&&this.parentNode.insertBefore(e,this)}))},after:function(){return Dt(this,arguments,(function(e){this.parentNode&&this.parentNode.insertBefore(e, + this.nextSibling)}))},empty:function(){for(var e,t=0;null!=(e=this[t]);t++)1===e.nodeType&&(T.cleanData(wt(e,!1)),e.textContent="""");return this},clone:function(e,t){return e=null!=e&&e,t=null==t?e:t,this.map((function(){return T.clone(this,e,t)}))},html:function(e){return G(this,(function(e){var t=this[0]||{},n=0,r=this.length;if(void 0===e&&1===t.nodeType)return t.innerHTML;if(""string""==typeof e&&!Pt.test(e)&&!bt[(xt.exec(e)||["""",""""])[1].toLowerCase()]){e=T.htmlPrefilter(e);try{for(;nT.inArray(this,e)&&(T.cleanData(wt(this)),n&&n.replaceChild(t,this))}),e)}}),T.each({appendTo:""append"",prependTo:""prepend"",insertBefore:""before"",insertAfter:""after"",replaceAll:""replaceWith""},(function(e,t){T.fn[e]=function(e){for(var n,r=[],i=T(e),o=i.length-1,s=0;s<=o; + s++)n=s===o?this:this.clone(!0),T(i[s])[t](n),a.apply(r,n);return this.pushStack(r)}}));var It=RegExp(""^(""+ot+"")(?!px)[a-z%]+$"",""i""),$t=/^--/;function Ft(t){var n=t.ownerDocument.defaultView;return n||(n=e),n.getComputedStyle(t)}function Bt(e,t,n){var r,i=$t.test(t);return(n=n||Ft(e))&&(r=n.getPropertyValue(t)||n[t],i&&r&&(r=r.replace(D,""$1"")||void 0),""""!==r||yt(e)||(r=T.style(e,t))),void 0!==r?r+"""":r}var _t=[""Webkit"",""Moz"",""ms""],Ut=y.createElement(""div"").style,Xt={};function zt(e){return Xt[ + e]||(e in Ut?e:Xt[e]=function(e){var t=e[0].toUpperCase()+e.slice(1),n=_t.length;while(n--)if((e=_t[n]+t)in Ut)return e}(e)||e)}(tn=y.createElement(""div"")).style&&(d.reliableTrDimensions=function(){var t,n,r;if(null==en){if(t=y.createElement(""table""),n=y.createElement(""tr""),t.style.cssText=""position:absolute;left:-11111px;border-collapse:separate"",n.style.cssText=""box-sizing:content-box;border:1px solid"",n.style.height=""1px"",tn.style.height=""9px"",tn.style.display=""block"",H.appendChild(t) + .appendChild(n).appendChild(tn),0===t.offsetWidth){H.removeChild(t);return}en=parseInt((r=e.getComputedStyle(n)).height,10)+parseInt(r.borderTopWidth,10)+parseInt(r.borderBottomWidth,10)===n.offsetHeight,H.removeChild(t)}return en});var Vt=/^(none|table(?!-c[ea]).+)/,Yt={position:""absolute"",visibility:""hidden"",display:""block""},Gt={letterSpacing:""0"",fontWeight:""400""};function Qt(e,t,n){var r=at.exec(t);return r?Math.max(0,r[2]-(n||0))+(r[3]||""px""):t}function Jt(e,t,n,r,i,o){var a=""width""===t?1:0, + s=0,u=0,l=0;if(n===(r?""border"":""content""))return 0;for(;a<4;a+=2)""margin""===n&&(l+=T.css(e,n+st[a],!0,i)),r?(""content""===n&&(u-=T.css(e,""padding""+st[a],!0,i)),""margin""!==n&&(u-=T.css(e,""border""+st[a]+""Width"",!0,i))):(u+=T.css(e,""padding""+st[a],!0,i),""padding""!==n?u+=T.css(e,""border""+st[a]+""Width"",!0,i):s+=T.css(e,""border""+st[a]+""Width"",!0,i));return!r&&o>=0&&(u+=Math.max(0,Math.ceil(e[""offset""+t[0].toUpperCase()+t.slice(1)]-o-u-s-.5))||0),u+l}function Kt(e,t,n){var r=Ft(e),i=(k||n)&&""border-box""=== + T.css(e,""boxSizing"",!1,r),o=i,a=Bt(e,t,r),s=""offset""+t[0].toUpperCase()+t.slice(1);if(It.test(a)){if(!n)return a;a=""auto""}return(""auto""===a||k&&i||!d.reliableTrDimensions()&&C(e,""tr""))&&e.getClientRects().length&&(i=""border-box""===T.css(e,""boxSizing"",!1,r),(o=s in e)&&(a=e[s])),(a=parseFloat(a)||0)+Jt(e,t,n||(i?""border"":""content""),o,r,a)+""px""}function Zt(e,t,n,r,i){return new Zt.prototype.init(e,t,n,r,i)}T.extend({cssHooks:{},style:function(e,t,n,r){if( + e&&3!==e.nodeType&&8!==e.nodeType&&e.style){var i,o,a,s=ht(t),u=$t.test(t),l=e.style;if(u||(t=zt(s)),a=T.cssHooks[t]||T.cssHooks[s],void 0===n)return a&&""get""in a&&void 0!==(i=a.get(e,!1,r))?i:l[t];""string""==(o=typeof n)&&(i=at.exec(n))&&i[1]&&(n=pt(e,t,i),o=""number""),null!=n&&n==n&&(""number""===o&&(n+=i&&i[3]||(ft(s)?""px"":"""")),k&&""""===n&&0===t.indexOf(""background"")&&(l[t]=""inherit""),a&&""set""in a&&void 0===(n=a.set(e,n,r))||(u?l.setProperty(t,n):l[t]=n))}},css:function(e,t,n,r){var i,o,a,s=ht(t); + return($t.test(t)||(t=zt(s)),(a=T.cssHooks[t]||T.cssHooks[s])&&""get""in a&&(i=a.get(e,!0,n)),void 0===i&&(i=Bt(e,t,r)),""normal""===i&&t in Gt&&(i=Gt[t]),""""===n||n)?(o=parseFloat(i),!0===n||isFinite(o)?o||0:i):i}}),T.each([""height"",""width""],(function(e,t){T.cssHooks[t]={get:function(e,n,r){if(n)return!Vt.test(T.css(e,""display""))||e.getClientRects().length&&e.getBoundingClientRect().width?Kt(e,t,r):function(e,t,n){var r,i,o={};for(i in t)o[i]=e.style[i],e.style[i]=t[i];for(i in r=n.call(e),t) + e.style[i]=o[i];return r}(e,Yt,(function(){return Kt(e,t,r)}))},set:function(e,n,r){var i,o=Ft(e),a=r&&""border-box""===T.css(e,""boxSizing"",!1,o),s=r?Jt(e,t,r,a,o):0;return s&&(i=at.exec(n))&&""px""!==(i[3]||""px"")&&(e.style[t]=n,n=T.css(e,t)),Qt(e,n,s)}}})),T.each({margin:"""",padding:"""",border:""Width""},(function(e,t){T.cssHooks[e+t]={expand:function(n){for(var r=0,i={},o=""string""==typeof n?n.split("" ""):[n];r<4;r++)i[e+st[r]+t]=o[r]||o[r-2]||o[0];return i}},""margin""!==e&&(T.cssHooks[e+t].set=Qt)})), + T.fn.extend({css:function(e,t){return G(this,(function(e,t,n){var r,i,o={},a=0;if(Array.isArray(t)){for(r=Ft(e),i=t.length;a1)}}),T.Tween=Zt,Zt.prototype={constructor:Zt,init:function(e,t,n,r,i,o){this.elem=e,this.prop=n,this.easing=i||T.easing._default,this.options=t,this.start=this.now=this.cur(),this.end=r,this.unit=o||(ft(n)?""px"":"""")},cur:function(){var e=Zt.propHooks[this.prop]; + return e&&e.get?e.get(this):Zt.propHooks._default.get(this)},run:function(e){var t,n=Zt.propHooks[this.prop];return this.options.duration?this.pos=t=T.easing[this.easing](e,this.options.duration*e,0,1,this.options.duration):this.pos=t=e,this.now=(this.end-this.start)*t+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),n&&n.set?n.set(this):Zt.propHooks._default.set(this),this}},Zt.prototype.init.prototype=Zt.prototype,Zt.propHooks={_default:{get:function(e){var t; + return 1!==e.elem.nodeType||null!=e.elem[e.prop]&&null==e.elem.style[e.prop]?e.elem[e.prop]:(t=T.css(e.elem,e.prop,""""))&&""auto""!==t?t:0},set:function(e){T.fx.step[e.prop]?T.fx.step[e.prop](e):1===e.elem.nodeType&&(T.cssHooks[e.prop]||null!=e.elem.style[zt(e.prop)])?T.style(e.elem,e.prop,e.now+e.unit):e.elem[e.prop]=e.now}}},T.easing={linear:function(e){return e},swing:function(e){return.5-Math.cos(e*Math.PI)/2},_default:""swing""},T.fx=Zt.prototype.init,T.fx.step={};var en,tn,nn,rn,on= + /^(?:toggle|show|hide)$/,an=/queueHooks$/;function sn(){return e.setTimeout((function(){nn=void 0})),nn=Date.now()}function un(e,t){var n,r=0,i={height:e};for(t=t?1:0;r<4;r+=2-t)i[""margin""+(n=st[r])]=i[""padding""+n]=e;return t&&(i.opacity=i.width=e),i}function ln(e,t,n){for(var r,i=(cn.tweeners[t]||[]).concat(cn.tweeners[""*""]),o=0,a=i.length;o1)},removeProp:function(e){return this.each((function(){delete this[T.propFix[e]||e]}))}}),T.extend({prop:function(e,t,n){var r,i,o=e.nodeType;if(3!==o&&8!==o&&2!==o)return(1===o&&T.isXMLDoc(e)||(t=T.propFix[t]||t,i=T.propHooks[t]),void 0!==n)?i&&""set""in i&&void 0!==(r=i.set(e,n,t))?r:e[t]=n:i&&""get""in + i&&null!==(r=i.get(e,t))?r:e[t]},propHooks:{tabIndex:{get:function(e){var t=e.getAttribute(""tabindex"");return t?parseInt(t,10):fn.test(e.nodeName)||pn.test(e.nodeName)&&e.href?0:-1}}},propFix:{for:""htmlFor"",class:""className""}}),k&&(T.propHooks.selected={get:function(e){var t=e.parentNode;return t&&t.parentNode&&t.parentNode.selectedIndex,null},set:function(e){var t=e.parentNode;t&&(t.selectedIndex,t.parentNode&&t.parentNode.selectedIndex)}}),T.each([""tabIndex"",""readOnly"",""maxLength"", + ""cellSpacing"",""cellPadding"",""rowSpan"",""colSpan"",""useMap"",""frameBorder"",""contentEditable""],(function(){T.propFix[this.toLowerCase()]=this})),T.fn.extend({addClass:function(e){var t,n,r,i,o,a;return""function""==typeof e?this.each((function(t){T(this).addClass(e.call(this,t,hn(this)))})):(t=gn(e)).length?this.each((function(){if(r=hn(this),n=1===this.nodeType&&"" ""+dn(r)+"" ""){for(o=0;on.indexOf("" ""+i+"" "")&&(n+=i+"" "");r!==(a=dn(n))&&this.setAttribute(""class"",a)}})):this}, + removeClass:function(e){var t,n,r,i,o,a;return""function""==typeof e?this.each((function(t){T(this).removeClass(e.call(this,t,hn(this)))})):arguments.length?(t=gn(e)).length?this.each((function(){if(r=hn(this),n=1===this.nodeType&&"" ""+dn(r)+"" ""){for(o=0;o-1)n=n.replace("" ""+i+"" "","" "")}r!==(a=dn(n))&&this.setAttribute(""class"",a)}})):this:this.attr(""class"","""")},toggleClass:function(e,t){var n,r,i,o;return""function""==typeof e?this.each((function(n){T( + this).toggleClass(e.call(this,n,hn(this),t),t)})):""boolean""==typeof t?t?this.addClass(e):this.removeClass(e):(n=gn(e)).length?this.each((function(){for(i=0,o=T(this);i-1)return!0;return!1}}),T.fn.extend({val:function(e){var t,n,r,i=this[0];return arguments.length?(r=""function""==typeof e,this.each((function(n){ + var i;1===this.nodeType&&(null==(i=r?e.call(this,n,T(this).val()):e)?i="""":""number""==typeof i?i+="""":Array.isArray(i)&&(i=T.map(i,(function(e){return null==e?"""":e+""""}))),(t=T.valHooks[this.type]||T.valHooks[this.nodeName.toLowerCase()])&&""set""in t&&void 0!==t.set(this,i,""value"")||(this.value=i))}))):i?(t=T.valHooks[i.type]||T.valHooks[i.nodeName.toLowerCase()])&&""get""in t&&void 0!==(n=t.get(i,""value""))?n:null==(n=i.value)?"""":n:void 0}}),T.extend({valHooks:{select:{get:function(e){var t,n,r, + i=e.options,o=e.selectedIndex,a=""select-one""===e.type,s=a?null:[],u=a?o+1:i.length;for(r=o<0?u:a?o:0;r-1)&&(n=!0);return n||(e.selectedIndex=-1),o}}}}),k&&(T.valHooks.option={get:function(e){var t=e.getAttribute(""value"");return + null!=t?t:dn(T.text(e))}}),T.each([""radio"",""checkbox""],(function(){T.valHooks[this]={set:function(e,t){if(Array.isArray(t))return e.checked=T.inArray(T(e).val(),t)>-1}}}));var vn=/^(?:focusinfocus|focusoutblur)$/,yn=function(e){e.stopPropagation()};T.extend(T.event,{trigger:function(t,n,r,i){var o,a,s,u,l,f,p,d,h=[r||y],v=c.call(t,""type"")?t.type:t,m=c.call(t,""namespace"")?t.namespace.split("".""):[];if(a=d=s=r=r||y,!(3===r.nodeType||8===r.nodeType||vn.test(v+T.event.triggered))&&(v.indexOf(""."")>- + 1&&(v=(m=v.split(""."")).shift(),m.sort()),l=0>v.indexOf("":"")&&""on""+v,(t=t[T.expando]?t:new T.Event(v,""object""==typeof t&&t)).isTrigger=i?2:3,t.namespace=m.join("".""),t.rnamespace=t.namespace?RegExp(""(^|\\.)""+m.join(""\\.(?:.*\\.|)"")+""(\\.|$)""):null,t.result=void 0,t.target||(t.target=r),n=null==n?[t]:T.makeArray(n,[t]),p=T.event.special[v]||{},i||!p.trigger||!1!==p.trigger.apply(r,n))){if(!i&&!p.noBubble&&!g(r)){for(u=p.delegateType||v,vn.test(u+v)||(a=a.parentNode);a;a=a.parentNode)h.push(a),s=a; + s===(r.ownerDocument||y)&&h.push(s.defaultView||s.parentWindow||e)}o=0;while((a=h[o++])&&!t.isPropagationStopped())d=a,t.type=o>1?u:p.bindType||v,(f=(et.get(a,""events"")||Object.create(null))[t.type]&&et.get(a,""handle""))&&f.apply(a,n),(f=l&&a[l])&&f.apply&&Ke(a)&&(t.result=f.apply(a,n),!1===t.result&&t.preventDefault());return t.type=v,!i&&!t.isDefaultPrevented()&&(!p._default||!1===p._default.apply(h.pop(),n))&&Ke(r)&&l&&""function""==typeof r[v]&&!g(r)&&((s=r[l])&&(r[l]=null),T.event.triggered=v, + t.isPropagationStopped()&&d.addEventListener(v,yn),r[v](),t.isPropagationStopped()&&d.removeEventListener(v,yn),T.event.triggered=void 0,s&&(r[l]=s)),t.result}},simulate:function(e,t,n){var r=T.extend(new T.Event,n,{type:e,isSimulated:!0});T.event.trigger(r,null,t)}}),T.fn.extend({trigger:function(e,t){return this.each((function(){T.event.trigger(e,t,this)}))},triggerHandler:function(e,t){var n=this[0];if(n)return T.event.trigger(e,t,n,!0)}});var mn=e.location,xn={guid:Date.now()},bn=/\?/; + T.parseXML=function(t){var n,r;if(!t||""string""!=typeof t)return null;try{n=(new e.DOMParser).parseFromString(t,""text/xml"")}catch(e){}return r=n&&n.getElementsByTagName(""parsererror"")[0],(!n||r)&&T.error(""Invalid XML: ""+(r?T.map(r.childNodes,(function(e){return e.textContent})).join(""\n""):t)),n};var wn=/\[\]$/,Tn=/\r?\n/g,Cn=/^(?:submit|button|image|reset|file)$/i,jn=/^(?:input|select|textarea|keygen)/i;T.param=function(e,t){var n,r=[],i=function(e,t){var n=""function""==typeof t?t():t;r[r.length] + =encodeURIComponent(e)+""=""+encodeURIComponent(null==n?"""":n)};if(null==e)return"""";if(Array.isArray(e)||e.jquery&&!T.isPlainObject(e))T.each(e,(function(){i(this.name,this.value)}));else for(n in e)!function e(t,n,r,i){var o;if(Array.isArray(n))T.each(n,(function(n,o){r||wn.test(t)?i(t,o):e(t+""[""+(""object""==typeof o&&null!=o?n:"""")+""]"",o,r,i)}));else if(r||""object""!==h(n))i(t,n);else for(o in n)e(t+""[""+o+""]"",n[o],r,i)}(n,e[n],t,i);return r.join(""&"")},T.fn.extend({serialize:function(){return + T.param(this.serializeArray())},serializeArray:function(){return this.map((function(){var e=T.prop(this,""elements"");return e?T.makeArray(e):this})).filter((function(){var e=this.type;return this.name&&!T(this).is("":disabled"")&&jn.test(this.nodeName)&&!Cn.test(e)&&(this.checked||!At.test(e))})).map((function(e,t){var n=T(this).val();return null==n?null:Array.isArray(n)?T.map(n,(function(e){return{name:t.name,value:e.replace(Tn,""\r\n"")}})):{name:t.name,value:n.replace(Tn,""\r\n"")}})).get()}});var + En=/%20/g,kn=/#.*$/,Sn=/([?&])_=[^&]*/,Dn=/^(.*?):[ \t]*([^\r\n]*)$/gm,An=/^(?:GET|HEAD)$/,qn=/^\/\//,Nn={},On={},Hn=""*/"".concat(""*""),Ln=y.createElement(""a"");function Pn(e){return function(t,n){""string""!=typeof t&&(n=t,t=""*"");var r,i=0,o=t.toLowerCase().match(Q)||[];if(""function""==typeof n)while(r=o[i++])""+""===r[0]?(e[r=r.slice(1)||""*""]=e[r]||[]).unshift(n):(e[r]=e[r]||[]).push(n)}}function Rn(e,t,n,r){var i={},o=e===On;function a(s){var u;return i[s]=!0,T.each(e[s]||[],(function(e,s){var l=s(t, + n,r);return""string""!=typeof l||o||i[l]?o?!(u=l):void 0:(t.dataTypes.unshift(l),a(l),!1)})),u}return a(t.dataTypes[0])||!i[""*""]&&a(""*"")}function Mn(e,t){var n,r,i=T.ajaxSettings.flatOptions||{};for(n in t)void 0!==t[n]&&((i[n]?e:r||(r={}))[n]=t[n]);return r&&T.extend(!0,e,r),e}Ln.href=mn.href,T.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:mn.href,type:""GET"",isLocal:/^(?:about|app|app-storage|.+-extension|file|res|widget):$/.test(mn.protocol),global:!0,processData:!0,async:!0, + contentType:""application/x-www-form-urlencoded; charset=UTF-8"",accepts:{""*"":Hn,text:""text/plain"",html:""text/html"",xml:""application/xml, text/xml"",json:""application/json, text/javascript""},contents:{xml:/\bxml\b/,html:/\bhtml/,json:/\bjson\b/},responseFields:{xml:""responseXML"",text:""responseText"",json:""responseJSON""},converters:{""* text"":String,""text html"":!0,""text json"":JSON.parse,""text xml"":T.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(e,t){return t?Mn(Mn(e,T.ajaxSettings),t): + Mn(T.ajaxSettings,e)},ajaxPrefilter:Pn(Nn),ajaxTransport:Pn(On),ajax:function(t,n){""object""==typeof t&&(n=t,t=void 0),n=n||{};var r,i,o,a,s,u,l,c,f,p,d=T.ajaxSetup({},n),h=d.context||d,g=d.context&&(h.nodeType||h.jquery)?T(h):T.event,v=T.Deferred(),m=T.Callbacks(""once memory""),x=d.statusCode||{},b={},w={},C=""canceled"",j={readyState:0,getResponseHeader:function(e){var t;if(l){if(!a){a={};while(t=Dn.exec(o))a[t[1].toLowerCase()+"" ""]=(a[t[1].toLowerCase()+"" ""]||[]).concat(t[2])}t=a[e.toLowerCase()+ + "" ""]}return null==t?null:t.join("", "")},getAllResponseHeaders:function(){return l?o:null},setRequestHeader:function(e,t){return null==l&&(b[e=w[e.toLowerCase()]=w[e.toLowerCase()]||e]=t),this},overrideMimeType:function(e){return null==l&&(d.mimeType=e),this},statusCode:function(e){var t;if(e){if(l)j.always(e[j.status]);else for(t in e)x[t]=[x[t],e[t]]}return this},abort:function(e){var t=e||C;return r&&r.abort(t),E(0,t),this}};if(v.promise(j),d.url=((t||d.url||mn.href)+"""").replace(qn,mn.protocol+ + ""//""),d.type=n.method||n.type||d.method||d.type,d.dataTypes=(d.dataType||""*"").toLowerCase().match(Q)||[""""],null==d.crossDomain){u=y.createElement(""a"");try{u.href=d.url,u.href=u.href,d.crossDomain=Ln.protocol+""//""+Ln.host!=u.protocol+""//""+u.host}catch(e){d.crossDomain=!0}}if(Rn(Nn,d,n,j),d.data&&d.processData&&""string""!=typeof d.data&&(d.data=T.param(d.data,d.traditional)),l)return j;for(f in(c=T.event&&d.global)&&0==T.active++&&T.event.trigger(""ajaxStart""),d.type=d.type.toUpperCase(), + d.hasContent=!An.test(d.type),i=d.url.replace(kn,""""),d.hasContent?d.data&&d.processData&&0===(d.contentType||"""").indexOf(""application/x-www-form-urlencoded"")&&(d.data=d.data.replace(En,""+"")):(p=d.url.slice(i.length),d.data&&(d.processData||""string""==typeof d.data)&&(i+=(bn.test(i)?""&"":""?"")+d.data,delete d.data),!1===d.cache&&(i=i.replace(Sn,""$1""),p=(bn.test(i)?""&"":""?"")+""_=""+xn.guid+++p),d.url=i+p),d.ifModified&&(T.lastModified[i]&&j.setRequestHeader(""If-Modified-Since"",T.lastModified[i]),T.etag[ + i]&&j.setRequestHeader(""If-None-Match"",T.etag[i])),(d.data&&d.hasContent&&!1!==d.contentType||n.contentType)&&j.setRequestHeader(""Content-Type"",d.contentType),j.setRequestHeader(""Accept"",d.dataTypes[0]&&d.accepts[d.dataTypes[0]]?d.accepts[d.dataTypes[0]]+(""*""!==d.dataTypes[0]?"", ""+Hn+""; q=0.01"":""""):d.accepts[""*""]),d.headers)j.setRequestHeader(f,d.headers[f]);if(d.beforeSend&&(!1===d.beforeSend.call(h,j,d)||l))return j.abort();if(C=""abort"",m.add(d.complete),j.done(d.success),j.fail(d.error),r=Rn( + On,d,n,j)){if(j.readyState=1,c&&g.trigger(""ajaxSend"",[j,d]),l)return j;d.async&&d.timeout>0&&(s=e.setTimeout((function(){j.abort(""timeout"")}),d.timeout));try{l=!1,r.send(b,E)}catch(e){if(l)throw e;E(-1,e)}}else E(-1,""No Transport"");function E(t,n,a,u){var f,p,y,b,w,C=n;!l&&(l=!0,s&&e.clearTimeout(s),r=void 0,o=u||"""",j.readyState=t>0?4:0,f=t>=200&&t<300||304===t,a&&(b=function(e,t,n){var r,i,o,a,s=e.contents,u=e.dataTypes;while(""*""===u[0])u.shift(),void 0===r&&(r=e.mimeType||t.getResponseHeader( + ""Content-Type""));if(r){for(i in s)if(s[i]&&s[i].test(r)){u.unshift(i);break}}if(u[0]in n)o=u[0];else{for(i in n){if(!u[0]||e.converters[i+"" ""+u[0]]){o=i;break}a||(a=i)}o=o||a}if(o)return o!==u[0]&&u.unshift(o),n[o]}(d,j,a)),!f&&T.inArray(""script"",d.dataTypes)>-1&&0>T.inArray(""json"",d.dataTypes)&&(d.converters[""text script""]=function(){}),b=function(e,t,n,r){var i,o,a,s,u,l={},c=e.dataTypes.slice();if(c[1])for(a in e.converters)l[a.toLowerCase()]=e.converters[a];o=c.shift();while(o)if( + e.responseFields[o]&&(n[e.responseFields[o]]=t),!u&&r&&e.dataFilter&&(t=e.dataFilter(t,e.dataType)),u=o,o=c.shift()){if(""*""===o)o=u;else if(""*""!==u&&u!==o){if(!(a=l[u+"" ""+o]||l[""* ""+o])){for(i in l)if((s=i.split("" ""))[1]===o&&(a=l[u+"" ""+s[0]]||l[""* ""+s[0]])){!0===a?a=l[i]:!0!==l[i]&&(o=s[0],c.unshift(s[1]));break}}if(!0!==a){if(a&&e.throws)t=a(t);else try{t=a(t)}catch(e){return{state:""parsererror"",error:a?e:""No conversion from ""+u+"" to ""+o}}}}}return{state:""success"",data:t}}(d,b,j,f),f?( + d.ifModified&&((w=j.getResponseHeader(""Last-Modified""))&&(T.lastModified[i]=w),(w=j.getResponseHeader(""etag""))&&(T.etag[i]=w)),204===t||""HEAD""===d.type?C=""nocontent"":304===t?C=""notmodified"":(C=b.state,p=b.data,f=!(y=b.error))):(y=C,(t||!C)&&(C=""error"",t<0&&(t=0))),j.status=t,j.statusText=(n||C)+"""",f?v.resolveWith(h,[p,C,j]):v.rejectWith(h,[j,C,y]),j.statusCode(x),x=void 0,c&&g.trigger(f?""ajaxSuccess"":""ajaxError"",[j,d,f?p:y]),m.fireWith(h,[j,C]),!c||(g.trigger(""ajaxComplete"",[j,d]),--T.active|| + T.event.trigger(""ajaxStop"")))}return j},getJSON:function(e,t,n){return T.get(e,t,n,""json"")},getScript:function(e,t){return T.get(e,void 0,t,""script"")}}),T.each([""get"",""post""],(function(e,t){T[t]=function(e,n,r,i){return(""function""==typeof n||null===n)&&(i=i||r,r=n,n=void 0),T.ajax(T.extend({url:e,type:t,dataType:i,data:n,success:r},T.isPlainObject(e)&&e))}})),T.ajaxPrefilter((function(e){var t;for(t in e.headers)""content-type""===t.toLowerCase()&&(e.contentType=e.headers[t]||"""")})), + T._evalUrl=function(e,t,n){return T.ajax({url:e,type:""GET"",dataType:""script"",cache:!0,async:!1,global:!1,scriptAttrs:t.crossOrigin?{crossOrigin:t.crossOrigin}:void 0,converters:{""text script"":function(){}},dataFilter:function(e){T.globalEval(e,t,n)}})},T.fn.extend({wrapAll:function(e){var t;return this[0]&&(""function""==typeof e&&(e=e.call(this[0])),t=T(e,this[0].ownerDocument).eq(0).clone(!0),this[0].parentNode&&t.insertBefore(this[0]),t.map((function(){var e=this;while(e.firstElementChild) + e=e.firstElementChild;return e})).append(this)),this},wrapInner:function(e){return""function""==typeof e?this.each((function(t){T(this).wrapInner(e.call(this,t))})):this.each((function(){var t=T(this),n=t.contents();n.length?n.wrapAll(e):t.append(e)}))},wrap:function(e){var t=""function""==typeof e;return this.each((function(n){T(this).wrapAll(t?e.call(this,n):e)}))},unwrap:function(e){return this.parent(e).not(""body"").each((function(){T(this).replaceWith(this.childNodes)})),this}}), + T.expr.pseudos.hidden=function(e){return!T.expr.pseudos.visible(e)},T.expr.pseudos.visible=function(e){return!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)},T.ajaxSettings.xhr=function(){return new e.XMLHttpRequest};var Wn={0:200};function In(e){return e.scriptAttrs||!e.headers&&(e.crossDomain||e.async&&0>T.inArray(""json"",e.dataTypes))}T.ajaxTransport((function(e){var t;return{send:function(n,r){var i,o=e.xhr();if(o.open(e.type,e.url,e.async,e.username,e.password),e.xhrFields)for( + i in e.xhrFields)o[i]=e.xhrFields[i];for(i in e.mimeType&&o.overrideMimeType&&o.overrideMimeType(e.mimeType),e.crossDomain||n[""X-Requested-With""]||(n[""X-Requested-With""]=""XMLHttpRequest""),n)o.setRequestHeader(i,n[i]);t=function(e){return function(){t&&(t=o.onload=o.onerror=o.onabort=o.ontimeout=null,""abort""===e?o.abort():""error""===e?r(o.status,o.statusText):r(Wn[o.status]||o.status,o.statusText,""text""===(o.responseType||""text"")?{text:o.responseText}:{binary:o.response}, + o.getAllResponseHeaders()))}},o.onload=t(),o.onabort=o.onerror=o.ontimeout=t(""error""),t=t(""abort"");try{o.send(e.hasContent&&e.data||null)}catch(e){if(t)throw e}},abort:function(){t&&t()}}})),T.ajaxSetup({accepts:{script:""text/javascript, application/javascript, application/ecmascript, application/x-ecmascript""},converters:{""text script"":function(e){return T.globalEval(e),e}}}),T.ajaxPrefilter(""script"",(function(e){void 0===e.cache&&(e.cache=!1),In(e)&&(e.type=""GET"")})),T.ajaxTransport(""script"",( + function(e){if(In(e)){var t,n;return{send:function(r,i){t=T("""; + var document = await context.OpenAsync(r => r.Content(html)); + Assert.IsNull(document.GetElementById("test")); + } + + [Test] + public async Task InlineModuleScriptShouldRun() + { + var config = + Configuration.Default + .WithJs() + .With(new MockHttpClientRequester(new Dictionary() + { + { "/jquery_4_0_0_esm.js", Constants.Jquery4_0_0_ESM } + })) + .WithDefaultLoader(new LoaderOptions() { IsResourceLoadingEnabled = true }); + var context = BrowsingContext.New(config); + var html = "
Test
"; + var document = await context.OpenAsync(r => r.Content(html)); + Assert.IsNull(document.GetElementById("test")); + } + + [Test] + public async Task ModuleScriptWithImportMapShouldRun() + { + var config = + Configuration.Default + .WithJs() + .With(new MockHttpClientRequester(new Dictionary() + { + { "/jquery_4_0_0_esm.js", Constants.Jquery4_0_0_ESM } + })) + .WithDefaultLoader(new LoaderOptions() { IsResourceLoadingEnabled = true }); + + var context = BrowsingContext.New(config); + var html = "
Test
"; + var document = await context.OpenAsync(r => r.Content(html)); + Assert.IsNull(document.GetElementById("test")); + } + + [Test] + public async Task ModuleScriptWithScopedImportMapShouldRunCorrectScript() + { + var config = + Configuration.Default + .WithJs() + .With(new MockHttpClientRequester(new Dictionary() + { + { "/example-module-1.js", "export function test() { document.getElementById('test1').remove(); }" }, + { "/example-module-2.js", "export function test() { document.getElementById('test2').remove(); }" }, + { "/test.js", "import { test } from 'example-module'; test();" }, + { "/test/test.js", "import { test } from 'example-module'; test();" } + })) + .WithDefaultLoader(new LoaderOptions() { IsResourceLoadingEnabled = true }); + + var context = BrowsingContext.New(config); + + var html1 = "
Test
Test
"; + var document1 = await context.OpenAsync(r => r.Content(html1)); + Assert.IsNull(document1.GetElementById("test1")); + Assert.IsNotNull(document1.GetElementById("test2")); + + var html2 = "
Test
Test
"; + var document2 = await context.OpenAsync(r => r.Content(html2)); + Assert.IsNull(document2.GetElementById("test2")); + Assert.IsNotNull(document2.GetElementById("test1")); + } + + [Test] + public async Task ModuleScriptWithAbsoluteUrlImportMapShouldRun() + { + var config = + Configuration.Default + .WithJs() + .With(new MockHttpClientRequester(new Dictionary() + { + { "/jquery_4_0_0_esm.js", Constants.Jquery4_0_0_ESM } + })) + .WithDefaultLoader(new LoaderOptions() { IsResourceLoadingEnabled = true }); + + var context = BrowsingContext.New(config); + var html = "
Test
"; + var document = await context.OpenAsync(r => r.Content(html)); + Assert.IsNull(document.GetElementById("test")); + } } } diff --git a/src/AngleSharp.Js.Tests/Mocks/MockHttpClientRequester.cs b/src/AngleSharp.Js.Tests/Mocks/MockHttpClientRequester.cs new file mode 100644 index 0000000..65277d5 --- /dev/null +++ b/src/AngleSharp.Js.Tests/Mocks/MockHttpClientRequester.cs @@ -0,0 +1,42 @@ +namespace AngleSharp.Js.Tests.Mocks +{ + using AngleSharp.Io; + using AngleSharp.Io.Network; + using System.Collections.Generic; + using System.IO; + using System.Net; + using System.Text; + using System.Threading; + using System.Threading.Tasks; + + /// + /// Mock HttpClientRequester which returns content for a specific request from a local dictionary. + /// + internal class MockHttpClientRequester : HttpClientRequester + { + private readonly Dictionary _mockResponses; + + public MockHttpClientRequester(Dictionary mockResponses) : base() + { + _mockResponses = mockResponses; + } + + protected override async Task PerformRequestAsync(Request request, CancellationToken cancel) + { + var response = new DefaultResponse(); + + if (_mockResponses.TryGetValue(request.Address.PathName, out var responseContent)) + { + response.StatusCode = HttpStatusCode.OK; + response.Content = new MemoryStream(Encoding.UTF8.GetBytes(responseContent)); + } + else + { + response.StatusCode = HttpStatusCode.NotFound; + response.Content = new MemoryStream(Encoding.UTF8.GetBytes(string.Empty)); + } + + return response; + } + } +} diff --git a/src/AngleSharp.Js/EngineInstance.cs b/src/AngleSharp.Js/EngineInstance.cs index 2767e3d..3848ebb 100644 --- a/src/AngleSharp.Js/EngineInstance.cs +++ b/src/AngleSharp.Js/EngineInstance.cs @@ -1,6 +1,8 @@ namespace AngleSharp.Js { using AngleSharp.Dom; + using AngleSharp.Io; + using AngleSharp.Text; using Jint; using Jint.Native; using Jint.Native.Object; @@ -17,6 +19,7 @@ sealed class EngineInstance private readonly ReferenceCache _references; private readonly IEnumerable _libs; private readonly DomNodeInstance _window; + private readonly JsImportMap _importMap; #endregion @@ -24,7 +27,12 @@ sealed class EngineInstance public EngineInstance(IWindow window, IDictionary assignments, IEnumerable libs) { - _engine = new Engine(); + _importMap = new JsImportMap(); + + _engine = new Engine((options) => + { + options.EnableModules(new JsModuleLoader(this, window.Document, false)); + }); _prototypes = new PrototypeCache(_engine); _references = new ReferenceCache(); _libs = libs; @@ -65,6 +73,8 @@ public EngineInstance(IWindow window, IDictionary assignments, I public Engine Jint => _engine; + public JsImportMap ImportMap => _importMap; + #endregion #region Methods @@ -73,14 +83,98 @@ public EngineInstance(IWindow window, IDictionary assignments, I public ObjectInstance GetDomPrototype(Type type) => _prototypes.GetOrCreate(type, CreatePrototype); - public JsValue RunScript(String source, JsValue context) + public JsValue RunScript(String source, String type, String sourceUrl, JsValue context) { + if (string.IsNullOrEmpty(type)) + { + type = MimeTypeNames.DefaultJavaScript; + } + lock (_engine) { - return _engine.Evaluate(source); + if (MimeTypeNames.IsJavaScript(type)) + { + return _engine.Evaluate(source); + } + else if (type.Isi("importmap")) + { + return LoadImportMap(source); + } + else if (type.Isi("module")) + { + // use a unique specifier to import the module into Jint + var specifier = sourceUrl ?? Guid.NewGuid().ToString(); + + return ImportModule(specifier, source); + } + else + { + return JsValue.Undefined; + } } } + private JsValue LoadImportMap(String source) + { + var importMap = _engine.Evaluate($"JSON.parse('{source}')").AsObject(); + + if (importMap.TryGetValue("scopes", out var scopes)) + { + var scopesObj = scopes.AsObject(); + + foreach (var scopeProperty in scopesObj.GetOwnProperties()) + { + var scopePath = scopeProperty.Key.AsString(); + + if (_importMap.Scopes.ContainsKey(scopePath)) + { + continue; + } + + var scopeValue = new Dictionary(); + + var scopeImports = scopesObj[scopePath].AsObject(); + + foreach (var scopeImportProperty in scopeImports.GetOwnProperties()) + { + var scopeImportSpecifier = scopeImportProperty.Key.AsString(); + + if (!scopeValue.ContainsKey(scopeImportSpecifier)) + { + scopeValue.Add(scopeImportSpecifier, new Uri(scopeImports[scopeImportSpecifier].AsString(), UriKind.RelativeOrAbsolute)); + } + } + + _importMap.Scopes.Add(scopePath, scopeValue); + } + } + + if (importMap.TryGetValue("imports", out var imports)) + { + var importsObj = imports.AsObject(); + + foreach (var importProperty in importsObj.GetOwnProperties()) + { + var importSpecifier = importProperty.Key.AsString(); + + if (!_importMap.Imports.ContainsKey(importSpecifier)) + { + _importMap.Imports.Add(importSpecifier, new Uri(importsObj[importSpecifier].AsString(), UriKind.RelativeOrAbsolute)); + } + } + } + + return JsValue.Undefined; + } + + private JsValue ImportModule(String specifier, String source) + { + _engine.Modules.Add(specifier, source); + _engine.Modules.Import(specifier); + + return JsValue.Undefined; + } + #endregion #region Helpers diff --git a/src/AngleSharp.Js/Extensions/EngineExtensions.cs b/src/AngleSharp.Js/Extensions/EngineExtensions.cs index 599d4f8..12cf37e 100644 --- a/src/AngleSharp.Js/Extensions/EngineExtensions.cs +++ b/src/AngleSharp.Js/Extensions/EngineExtensions.cs @@ -198,11 +198,11 @@ public static void AddInstance(this EngineInstance engine, ObjectInstance obj, T apply.Invoke(engine, obj); } - public static JsValue RunScript(this EngineInstance engine, String source) => - engine.RunScript(source, engine.Window); + public static JsValue RunScript(this EngineInstance engine, String source, String type, String sourceUrl) => + engine.RunScript(source, type, sourceUrl, engine.Window); - public static JsValue RunScript(this EngineInstance engine, String source, INode context) => - engine.RunScript(source, context.ToJsValue(engine)); + public static JsValue RunScript(this EngineInstance engine, String source, String type, String sourceUrl, INode context) => + engine.RunScript(source, type, sourceUrl, context.ToJsValue(engine)); public static JsValue Call(this EngineInstance instance, MethodInfo method, JsValue thisObject, JsValue[] arguments) { diff --git a/src/AngleSharp.Js/JsApiExtensions.cs b/src/AngleSharp.Js/JsApiExtensions.cs index d5e8cbf..b055e11 100644 --- a/src/AngleSharp.Js/JsApiExtensions.cs +++ b/src/AngleSharp.Js/JsApiExtensions.cs @@ -1,6 +1,7 @@ namespace AngleSharp.Js { using AngleSharp.Dom; + using AngleSharp.Io; using AngleSharp.Scripting; using System; @@ -14,14 +15,16 @@ public static class JsApiExtensions /// /// The document as context. /// The script to run. + /// The type of the script to run (defaults to "text/javascript"). + /// The URL of the script. /// The result of running the script, if any. - public static Object ExecuteScript(this IDocument document, String scriptCode) + public static Object ExecuteScript(this IDocument document, String scriptCode, String scriptType = null, String sourceUrl = null) { if (document == null) throw new ArgumentNullException(nameof(document)); var service = document?.Context.GetService(); - return service?.EvaluateScript(document, scriptCode); + return service?.EvaluateScript(document, scriptCode, scriptType ?? MimeTypeNames.DefaultJavaScript, sourceUrl); } } } diff --git a/src/AngleSharp.Js/JsImportMap.cs b/src/AngleSharp.Js/JsImportMap.cs new file mode 100644 index 0000000..247c99b --- /dev/null +++ b/src/AngleSharp.Js/JsImportMap.cs @@ -0,0 +1,29 @@ +namespace AngleSharp.Js +{ + using System; + using System.Collections.Generic; + + /// + /// https://html.spec.whatwg.org/multipage/webappapis.html#import-map + /// + sealed class JsImportMap + { + public JsImportMap() + { + Imports = new Dictionary(); + Scopes = new Dictionary>(); + } + + /// + /// Provides the mappings between module specifier text that might appear in an import statement or import() operator, + /// and the text that will replace it when the specifier is resolved. + /// + public Dictionary Imports { get; set; } + + /// + /// Mappings that are only used if the script importing the module contains a particular URL path. + /// If the URL of the loading script matches the supplied path, the mapping associated with the scope will be used. + /// + public Dictionary> Scopes { get; set; } + } +} diff --git a/src/AngleSharp.Js/JsModuleLoader.cs b/src/AngleSharp.Js/JsModuleLoader.cs new file mode 100644 index 0000000..ec547c4 --- /dev/null +++ b/src/AngleSharp.Js/JsModuleLoader.cs @@ -0,0 +1,118 @@ +namespace AngleSharp.Js +{ + using AngleSharp.Dom; + using AngleSharp.Io; + using AngleSharp.Text; + using Jint; + using Jint.Runtime.Modules; + using System.IO; + using System; + using System.Linq; + + internal class JsModuleLoader : DefaultModuleLoader + { + private readonly EngineInstance _instance; + private readonly IResourceLoader _resourceLoader; + private readonly IElement _scriptElement; + private readonly string _documentUrl; + + public JsModuleLoader(EngineInstance instance, IDocument document, bool restrictToBasePath = true) : base (document.Url, restrictToBasePath) + { + _instance = instance; + _resourceLoader = document.Context.GetService(); + _scriptElement = document.CreateElement(TagNames.Script); + _documentUrl = document.Url; + } + + public override ResolvedSpecifier Resolve(string referencingModuleLocation, ModuleRequest moduleRequest) + { + if (referencingModuleLocation != null && _instance.ImportMap.Scopes.Count > 0) + { + foreach (var scopePath in _instance.ImportMap.Scopes.Keys.OrderByDescending(k => k.Length)) + { + if (referencingModuleLocation.Contains(scopePath)) + { + var scopeImports = _instance.ImportMap.Scopes[scopePath]; + + if (scopeImports.TryGetValue(moduleRequest.Specifier, out var scopeModuleUrl)) + { + if (!scopeModuleUrl.IsAbsoluteUri) + { + scopeModuleUrl = new Uri(new Uri(_documentUrl), scopeModuleUrl); + } + + return new ResolvedSpecifier( + moduleRequest, + moduleRequest.Specifier, + scopeModuleUrl, + SpecifierType.RelativeOrAbsolute); + } + } + } + } + + if (_instance.ImportMap.Imports.TryGetValue(moduleRequest.Specifier, out var moduleUrl)) + { + if (!moduleUrl.IsAbsoluteUri) + { + moduleUrl = new Uri(new Uri(_documentUrl), moduleUrl); + } + + return new ResolvedSpecifier( + moduleRequest, + moduleRequest.Specifier, + moduleUrl, + SpecifierType.RelativeOrAbsolute); + } + + // Before passing to the base default module loader, make sure any relative paths are prepended with a dot + // as Jint will otherwise resolve them as absolute file paths when running on Linux + if (moduleRequest.Specifier.StartsWith("/")) + { + moduleRequest = new ModuleRequest($".{moduleRequest.Specifier}", moduleRequest.Attributes); + } + + if (referencingModuleLocation?.StartsWith("/") == true) + { + referencingModuleLocation = $".{referencingModuleLocation}"; + } + + return base.Resolve(referencingModuleLocation, moduleRequest); + } + + protected override string LoadModuleContents(Engine engine, ResolvedSpecifier resolved) + { + if (resolved.Uri?.Scheme.IsOneOf(ProtocolNames.Http, ProtocolNames.Https) == true) + { + return FetchModule(resolved.Uri); + } + else + { + return base.LoadModuleContents(engine, resolved); + } + } + + private string FetchModule(Uri moduleUrl) + { + if (_resourceLoader == null) + { + return string.Empty; + } + + var importUrl = Url.Convert(moduleUrl); + + var request = new ResourceRequest(_scriptElement, importUrl); + + var response = _resourceLoader.FetchAsync(request).Task.Result; + + string content; + + using (var streamReader = new StreamReader(response.Content)) + { + content = streamReader.ReadToEnd(); + } + + return content; + } + } +} diff --git a/src/AngleSharp.Js/JsScriptingService.cs b/src/AngleSharp.Js/JsScriptingService.cs index 3f50b6e..add873e 100644 --- a/src/AngleSharp.Js/JsScriptingService.cs +++ b/src/AngleSharp.Js/JsScriptingService.cs @@ -4,6 +4,7 @@ namespace AngleSharp.Scripting using AngleSharp.Dom; using AngleSharp.Io; using AngleSharp.Js; + using AngleSharp.Text; using Jint; using System; using System.Collections.Generic; @@ -57,7 +58,9 @@ public JsScriptingService() #region Methods Boolean IScriptingService.SupportsType(String mimeType) => - MimeTypeNames.IsJavaScript(mimeType); + MimeTypeNames.IsJavaScript(mimeType) || + mimeType.Isi("module") || + mimeType.Isi("importmap"); /// /// Gets the associated Jint engine or creates it. @@ -81,7 +84,7 @@ public async Task EvaluateScriptAsync(IResponse response, ScriptOptions options, { var content = await reader.ReadToEndAsync().ConfigureAwait(false); await options.EventLoop.EnqueueAsync(_ => - EvaluateScript(options.Document, content), TaskPriority.Critical).ConfigureAwait(false); + EvaluateScript(options.Document, content, options.Element?.Type, options.Element?.Source), TaskPriority.Critical).ConfigureAwait(false); } } @@ -90,11 +93,13 @@ await options.EventLoop.EnqueueAsync(_ => /// /// The context of the evaluation. /// The source of the script. + /// The type of the script. + /// The URL of the script. /// The result of the evaluation. - public Object EvaluateScript(IDocument document, String source) + public Object EvaluateScript(IDocument document, String source, String type, String sourceUrl) { document = document ?? throw new ArgumentNullException(nameof(document)); - return GetOrCreateInstance(document).RunScript(source).FromJsValue(); + return GetOrCreateInstance(document).RunScript(source, type, sourceUrl).FromJsValue(); } #endregion