/*! For license information please see attachProps.js.LICENSE.txt */
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.syncEvent=exports.isCoveredByReact=exports.transformReactEventName=exports.getClassName=exports.attachProps=void 0;var case_1=require("./case"),attachProps=function(e,t,a){if(void 0===a&&(a={}),e instanceof Element){var r=(0,exports.getClassName)(e.classList,t,a);""!==r&&(e.className=r),Object.keys(t).forEach(function(a){if("children"!==a&&"style"!==a&&"ref"!==a&&"class"!==a&&"className"!==a&&"forwardedRef"!==a)if(0===a.indexOf("on")&&a[2]===a[2].toUpperCase()){var r=a.substring(2),s=r[0].toLowerCase()+r.substring(1);(0,exports.isCoveredByReact)(s)||(0,exports.syncEvent)(e,s,t[a])}else e[a]=t[a],"string"==typeof t[a]&&e.setAttribute((0,case_1.camelToDashCase)(a),t[a])})}};exports.attachProps=attachProps;var getClassName=function(e,t,a){var r=t.className||t.class,s=a.className||a.class,n=arrayToMap(e),o=arrayToMap(r?r.split(" "):[]),c=arrayToMap(s?s.split(" "):[]),i=[];return n.forEach(function(e){o.has(e)?(i.push(e),o.delete(e)):c.has(e)||i.push(e)}),o.forEach(function(e){return i.push(e)}),i.join(" ")};exports.getClassName=getClassName;var transformReactEventName=function(e){return"doubleclick"===e?"dblclick":e};exports.transformReactEventName=transformReactEventName;var isCoveredByReact=function(e){if("undefined"==typeof document)return!0;var t="on"+(0,exports.transformReactEventName)(e),a=t in document;if(!a){var r=document.createElement("div");r.setAttribute(t,"return;"),a="function"==typeof r[t]}return a};exports.isCoveredByReact=isCoveredByReact;var syncEvent=function(e,t,a){var r=e.__events||(e.__events={}),s=r[t];s&&e.removeEventListener(t,s),e.addEventListener(t,r[t]=function(e){a&&a.call(this,e)})};exports.syncEvent=syncEvent;var arrayToMap=function(e){var t=new Map;return e.forEach(function(e){return t.set(e,e)}),t};