!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).DomMark=t()}(this,(function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:"body",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e(this,o),this.container=null,this.box=null,this.observer=null,this.options={},t instanceof window.HTMLElement?this.container=t:this.container=document.querySelector(t),!this.container)throw new Error("invalid selector: ".concat(t));var i=this.container.querySelector('div[powered-by="https://github.com/rotick/dom-mark"]');i&&(this.box=i),this._setOptions(n)}var r,a,s;return r=o,(a=[{key:"render",value:function(){var e=this,t=n.indexOf(this.container);t>-1&&(this.observer=i[t],n.splice(t,1),i.splice(t,1)),this.observer&&this.observer.disconnect();var o=this.options,r=o.content,a=o.fontSize,s=o.fontFamily,c=o.opacity,d=o.color,h=o.padding,u=o.zIndex,l=o.minMargin,p=o.rotate,b=o.observe;"static"===window.getComputedStyle(this.container).position&&(this.container.style.position="relative");var f=this.box||document.createElement("div");this.box=f;var v=document.createElement("div");f.style.cssText="position:absolute;top:0;left:0;right:0;bottom:0;font-size:".concat(a,";\n font-family:").concat(s,";opacity:").concat(c,";color:").concat(d,";pointer-events:none;\n user-select: none;-ms-user-select: none;z-index:").concat(u,";z-index:-1\\9;"),f.setAttribute("powered-by","https://github.com/rotick/dom-mark"),f.setAttribute("onselectstart","return false;"),f.setAttribute("ondragstart","return false;"),v.style.cssText="position:absolute;top:0;left:0;opacity:0;",v.innerHTML=r,f.appendChild(v),this.container.appendChild(f);var m=function(){var t=window.getComputedStyle(f),n=Number(t.width.replace("px","")),i=Number(t.height.replace("px","")),o=window.getComputedStyle(v),a=Number(o.width.replace("px","")),s=Number(o.height.replace("px",""));v=null;var c=e._arrange({boxWidth:n,boxHeight:i,itemWidth:a,itemHeight:s,boxPadding:h,minMarginH:l[1],minMarginV:l[0]}).map((function(e){return'
').concat(r,"
")}));f.innerHTML=c.join(""),b&&e._observe()},g=f.querySelectorAll("img");g.length?function(){for(var e=[],t=function(t){var n=g[t];n.onload=function(){e.push(1),e.length===g.length&&m()},n.onerror=function(){throw new Error("image load error: ".concat(n.src))}},n=0;n-1){e.render();break}}})),this.observer.observe(this.container,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),n.push(this.container),i.push(this.observer))}},{key:"_getParents",value:function(e){var t=[e];return function e(n){return n.parentNode?(t.push(n.parentNode),e(n.parentNode)):t}(e)}}])&&t(r.prototype,a),s&&t(r,s),Object.defineProperty(r,"prototype",{writable:!1}),o}();return o}));