module.exports = "(function(e,t,i){var n=i(5894),r=i(7358),a=i(343),s=i(1540),o=i(280).v,h=i(3684),c=i(5077),l=i(4527).get(\"stores/directive\"),p=i(8737),d=i(5035),E=i(1571),T=i(4810),I=i(5906),_=i(4721),A=i(2557).create(),N={MOVING_WINDOW_MILLISECONDS:__CHANGE_APPLICATION_RATE__.MOVING_WINDOW_MILLISECONDS,MAX_MACROTASKS_IN_MOVING_WINDOW:__CHANGE_APPLICATION_RATE__.MAX_MACROTASKS_IN_MOVING_WINDOW},u=o(\"ChangeOverheatError\");function O(e,t){if(this.change=e,this.identifier=t.identifier,this.startTime=t.startTime,l.shouldObserveChangesIndefinitely()){E.dispatch(r.INITIALIZE_CHANGE_METRICS),this.rateMeter=new I(N.MOVING_WINDOW_MILLISECONDS);var i=n.isNull(N.MAX_MACROTASKS_IN_MOVING_WINDOW)?Number.POSITIVE_INFINITY:N.MAX_MACROTASKS_IN_MOVING_WINDOW;this.rateMeter.addListener(i,n.bind((function(){T.warn(\"AppendChange\",this,\"has overheated and will no longer apply or reapply\"),this.cancel(),E.dispatch(r.RECORD_CHANGE_OVERHEATED),a.emitError(new u(\"Change \"+this.identifier+\" has overheated\"),{layerId:t.action&&t.action.layerId,experimentId:t.action&&t.action.experimentId,variationId:t.action&&t.action.variationId,changeId:e.id,changeType:e.type,movingWindowMilliseconds:N.MOVING_WINDOW_MILLISECONDS,maxMacroTasksInMovingWindow:i})}),this));for(var s=Math.min(i,50),o=0;o<=s;o++)this.rateMeter.addListener(o,n.partial((function(e){E.dispatch(r.RECORD_CHANGE_MACROTASK_RATE,{changeMacrotaskRate:e})}),o))}}O.prototype.numberOfRootNodes=function(e){var t=document.createElement(\"div\");return t.innerHTML=e,t.childNodes.length},O.prototype.getSiblingElements=function(e,t,i){for(var n=e,r=[],a=0;a<t;a++)i?(r.push(n.nextSibling),n=n.nextSibling):(r.push(n.previousSibling),n=n.previousSibling);return r},O.prototype.apply=function(){this.applyDeferred=c();try{if(!this.numberOfRootNodes(this.change.value))throw new Error(\"No DOM elements to be created for this change: \"+this.change.value);var e=n.partial(this.applyDeferred.reject,new Error(\"Unable to find selector.\")),t={};l.shouldObserveChangesUntilTimeout()?t={timeout:n.partial(_.isTimedOut,this.startTime),onTimeout:e}:l.isEditor()&&A.waitUntil(n.partial(_.isTimedOut,this.startTime)).then(e,e),this.unobserveSelector=A.observeSelector(this.change.selector,n.bind(this.maybeApplyToElement,this),t);var i=p.querySelectorAll(this.change.selector);n.each(i,n.bind(this.maybeApplyToElement,this))}catch(e){this.applyDeferred.reject(e)}return this.applyDeferred},O.prototype.maybeApplyToElement=function(e){var t=s.CHANGE_ID_ATTRIBUTE_PREFIX+this.change.id;if(e.hasAttribute(t))return T.debug(\"Not applying AppendChange to element\",e,\"because it was inserted by this change\"),this.applyDeferred.resolve(),void 0;this.rateMeter&&this.rateMeter.countCurrentTick(),n.bind(this.applyOrReapplyToElement,this,e,t)(),this.applyDeferred.resolve()},O.prototype.applyOrReapplyToElement=function(e,t){var i;switch(this.change.operator){case d.DOMInsertionType.AFTER:i=d.insertAdjacentHTMLType.AFTER_END;break;case d.DOMInsertionType.APPEND:i=d.insertAdjacentHTMLType.BEFORE_END;break;case d.DOMInsertionType.BEFORE:i=d.insertAdjacentHTMLType.BEFORE_BEGIN;break;case d.DOMInsertionType.PREPEND:i=d.insertAdjacentHTMLType.AFTER_BEGIN;break;default:i=d.insertAdjacentHTMLType.BEFORE_END}e.insertAdjacentHTML(i,this.change.value),e.setAttribute(t,\"\"),h.setData(e,this.change.id,this.identifier,[]);var r,a,s=this.numberOfRootNodes(this.change.value)-1;i===d.insertAdjacentHTMLType.BEFORE_END?(r=e.lastChild,a=this.getSiblingElements(r,s,!1)):i===d.insertAdjacentHTMLType.AFTER_BEGIN?(r=e.firstChild,a=this.getSiblingElements(r,s,!0)):i===d.insertAdjacentHTMLType.BEFORE_BEGIN?(r=e.previousSibling,a=this.getSiblingElements(r,s,!1)):i===d.insertAdjacentHTMLType.AFTER_END&&(r=e.nextSibling,a=this.getSiblingElements(r,s,!0)),a.unshift(r),n.each(a,n.bind((function(e){var i=e.nodeType===Node.ELEMENT_NODE?e:p.parentElement(e);i.setAttribute(t,\"\");var r=h.getData(i,this.change.id,this.identifier)||[];r.push(e),h.setData(i,this.change.id,this.identifier,r),n.each(p.childrenOf(i),(function(e){e.setAttribute(t,\"\")}))}),this))},O.prototype.cancel=function(){this.unobserveSelector&&this.unobserveSelector()},__UNDO_CHANGES_UPON_VIEW_DEACTIVATION__&&(O.prototype.undo=function(){var e=s.CHANGE_ID_ATTRIBUTE_PREFIX+this.change.id,t=p.querySelectorAll(\"[\"+e+\"]\");return n.each(t,n.bind((function(t){var i=h.getData(t,this.change.id,this.identifier)||[];n.each(i,(function(e){e.parentNode.removeChild(e)})),t.removeAttribute(e),h.removeData(t,this.change.id,this.identifier),n.each(p.childrenOf(t),(function(t){t.removeAttribute(e)}))}),this)),c().resolve(d.changeState.UNAPPLIED)}),e.exports=function(e){e.registerChangeApplier(d.changeType.APPEND,O)}})";