File: //usr/syno/synoman/scripts/ext-2/ux/ux-syno-polyfill.js
/* Copyright (c) 2025 Synology Inc. All rights reserved. */
!function(t){"use strict";if(!t.setImmediate){var e,n,o,r,i,s=1,c={},a=!1,u=t.document,l=Object.getPrototypeOf&&Object.getPrototypeOf(t);l=l&&l.setTimeout?l:t,"[object process]"==={}.toString.call(t.process)?e=function(){var t=f(arguments);return process.nextTick(h(p,t)),t}:!function(){if(t.postMessage&&!t.importScripts){var e=!0,n=t.onmessage;return t.onmessage=function(){e=!1},t.postMessage("","*"),t.onmessage=n,e}}()?t.MessageChannel?((o=new MessageChannel).port1.onmessage=function(t){p(t.data)},e=function(){var t=f(arguments);return o.port2.postMessage(t),t}):u&&"onreadystatechange"in u.createElement("script")?(n=u.documentElement,e=function(){var t=f(arguments),e=u.createElement("script");return e.onreadystatechange=function(){p(t),e.onreadystatechange=null,n.removeChild(e),e=null},n.appendChild(e),t}):e=function(){var t=f(arguments);return setTimeout(h(p,t),0),t}:(r="setImmediate$"+Math.random()+"$",i=function(e){e.source===t&&"string"==typeof e.data&&0===e.data.indexOf(r)&&p(+e.data.slice(r.length))},t.addEventListener?t.addEventListener("message",i,!1):t.attachEvent("onmessage",i),e=function(){var e=f(arguments);return t.postMessage(r+e,"*"),e}),l.setImmediate=e,l.clearImmediate=d}function f(t){return c[s]=h.apply(void 0,t),s++}function h(t){var e=[].slice.call(arguments,1);return function(){"function"==typeof t?t.apply(void 0,e):new Function(""+t)()}}function p(t){if(a)setTimeout(h(p,t),0);else{var e=c[t];if(e){a=!0;try{e()}finally{d(t),a=!1}}}}function d(t){delete c[t]}}(new Function("return this")()),function(t){var e="function"==typeof setImmediate&&setImmediate||function(t){setTimeout(t,1)};function n(t,e){return function(){t.apply(e,arguments)}}var o=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function r(t){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],l(t,n(s,this),n(c,this))}function i(t){var n=this;null!==this._state?e((function(){var e=n._state?t.onFulfilled:t.onRejected;if(null!==e){var o;try{o=e(n._value)}catch(e){return void t.reject(e)}t.resolve(o)}else(n._state?t.resolve:t.reject)(n._value)})):this._deferreds.push(t)}function s(t){try{if(t===this)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var e=t.then;if("function"==typeof e)return void l(n(e,t),n(s,this),n(c,this))}this._state=!0,this._value=t,a.call(this)}catch(t){c.call(this,t)}}function c(t){this._state=!1,this._value=t,a.call(this)}function a(){for(var t=0,e=this._deferreds.length;t<e;t++)i.call(this,this._deferreds[t]);this._deferreds=null}function u(t,e,n,o){this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof e?e:null,this.resolve=n,this.reject=o}function l(t,e,n){var o=!1;try{t((function(t){o||(o=!0,e(t))}),(function(t){o||(o=!0,n(t))}))}catch(t){if(o)return;o=!0,n(t)}}r.prototype.catch=function(t){return this.then(null,t)},r.prototype.then=function(t,e){var n=this;return new r((function(o,r){i.call(n,new u(t,e,o,r))}))},r.all=function(){var t=Array.prototype.slice.call(1===arguments.length&&o(arguments[0])?arguments[0]:arguments);return new r((function(e,n){if(0===t.length)return e([]);var o=t.length;function r(i,s){try{if(s&&("object"==typeof s||"function"==typeof s)){var c=s.then;if("function"==typeof c)return void c.call(s,(function(t){r(i,t)}),n)}t[i]=s,0==--o&&e(t)}catch(t){n(t)}}for(var i=0;i<t.length;i++)r(i,t[i])}))},r.resolve=function(t){return t&&"object"==typeof t&&t.constructor===r?t:new r((function(e){e(t)}))},r.reject=function(t){return new r((function(e,n){n(t)}))},r.race=function(t){return new r((function(e,n){for(var o=0,r=t.length;o<r;o++)t[o].then(e,n)}))},r._setImmediateFn=function(t){e=t},"undefined"!=typeof module&&module.exports?module.exports=r:t.Promise||(t.Promise=r)}(this),Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector),Element.prototype.closest||(Element.prototype.closest=function(t){var e=this;do{if(e.matches(t))return e;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType);return null});