dom-mutator
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -48,4 +48,13 @@ 'use strict'; | ||
el: el, | ||
_positionTimeout: null, | ||
observer: new MutationObserver(function () { | ||
// enact a 1 second timeout that blocks subsequent firing of the | ||
// observer until the timeout is complete. This will prevent multiple | ||
// mutations from firing in quick succession, which can cause the | ||
// mutation to be reverted before the DOM has a chance to update. | ||
if (attr === 'position' && record._positionTimeout) return;else if (attr === 'position') record._positionTimeout = setTimeout(function () { | ||
record._positionTimeout = null; | ||
}, 1000); | ||
var currentValue = getCurrentValue(el); | ||
if (attr === 'position' && currentValue.parentNode === record.virtualValue.parentNode && currentValue.insertBeforeNode === record.virtualValue.insertBeforeNode) return; | ||
if (currentValue === record.virtualValue) return; | ||
@@ -59,3 +68,14 @@ record.originalValue = currentValue; | ||
}; | ||
record.observer.observe(el, getObserverInit(attr)); | ||
if (attr === 'position' && el.parentNode) { | ||
record.observer.observe(el.parentNode, { | ||
childList: true, | ||
subtree: true, | ||
attributes: false, | ||
characterData: false | ||
}); | ||
} else { | ||
record.observer.observe(el, getObserverInit(attr)); | ||
} | ||
return record; | ||
@@ -71,7 +91,7 @@ } | ||
record.isDirty = true; | ||
queueDOMUpdates(); | ||
runDOMUpdates(); | ||
} | ||
} else if (val !== currentVal) { | ||
record.isDirty = true; | ||
queueDOMUpdates(); | ||
runDOMUpdates(); | ||
} | ||
@@ -155,2 +175,8 @@ } | ||
var setElementPosition = function setElementPosition(el, value) { | ||
if (value.insertBeforeNode && !value.parentNode.contains(value.insertBeforeNode)) { | ||
// skip position mutation - insertBeforeNode not a child of parent. happens | ||
// when mutation observer for indvidual element fires out of order | ||
return; | ||
} | ||
value.parentNode.insertBefore(el, value.insertBeforeNode); | ||
@@ -261,4 +287,2 @@ }; | ||
var raf = false; | ||
function setValue(m, el) { | ||
@@ -273,12 +297,4 @@ m.html && setPropertyValue(el, 'html', m.html); | ||
function setValues() { | ||
raf = false; | ||
function runDOMUpdates() { | ||
elements.forEach(setValue); | ||
} | ||
function queueDOMUpdates() { | ||
if (!raf) { | ||
raf = true; | ||
requestAnimationFrame(setValues); | ||
} | ||
} // find or create ElementPropertyRecord, add mutation to it, then run | ||
@@ -327,8 +343,8 @@ | ||
function refreshElementsSet(mutation) { | ||
// if a position mutation has already found an element to move, don't move | ||
// any more elements | ||
if (mutation.kind === 'position' && mutation.elements.size === 1) return; | ||
var existingElements = new Set(mutation.elements); | ||
var newElements = new Set(); | ||
var matchingElements = document.querySelectorAll(mutation.selector); | ||
matchingElements.forEach(function (el) { | ||
newElements.add(el); | ||
if (!existingElements.has(el)) { | ||
@@ -339,8 +355,2 @@ mutation.elements.add(el); | ||
}); | ||
existingElements.forEach(function (el) { | ||
if (!newElements.has(el)) { | ||
mutation.elements["delete"](el); | ||
stopMutating(mutation, el); | ||
} | ||
}); | ||
} | ||
@@ -347,0 +357,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=/^[a-zA-Z:_][a-zA-Z0-9:_.-]*$/,t={revert:function(){}},n=new Map,r=new Set;function i(e){var t=n.get(e);return t||n.set(e,t={element:e,attributes:{}}),t}function u(e,t,n,r,i){var u=n(e),o={isDirty:!1,originalValue:u,virtualValue:u,mutations:[],el:e,observer:new MutationObserver((function(){var t=n(e);t!==o.virtualValue&&(o.originalValue=t,i(o))})),mutationRunner:i,setValue:r,getCurrentValue:n};return o.observer.observe(e,function(e){return"html"===e?{childList:!0,subtree:!0,attributes:!0,characterData:!0}:{childList:!1,subtree:!1,attributes:!0,attributeFilter:[e]}}(t)),o}function o(e,t){var n=t.getCurrentValue(t.el);t.virtualValue=e,e&&"string"!=typeof e?n&&e.parentNode===n.parentNode&&e.insertBeforeNode===n.insertBeforeNode||(t.isDirty=!0,A()):e!==n&&(t.isDirty=!0,A())}function a(e){var t=e.originalValue;e.mutations.forEach((function(e){return t=e.mutate(t)})),o(function(e){return h||(h=document.createElement("div")),h.innerHTML=e,h.innerHTML}(t),e)}function l(e){var t=new Set(e.originalValue.split(/\s+/).filter(Boolean));e.mutations.forEach((function(e){return e.mutate(t)})),o(Array.from(t).filter(Boolean).join(" "),e)}function s(e){var t=e.originalValue;e.mutations.forEach((function(e){return t=e.mutate(t)})),o(t,e)}function c(e){var t=e.originalValue;e.mutations.forEach((function(e){var n=function(e){var t=e.insertBeforeSelector,n=document.querySelector(e.parentSelector);if(!n)return null;var r=t?document.querySelector(t):null;return t&&!r?null:{parentNode:n,insertBeforeNode:r}}(e.mutate());t=n||t})),o(t,e)}var f=function(e){return e.innerHTML},d=function(e,t){return e.innerHTML=t};function m(e){var t=i(e);return t.html||(t.html=u(e,"html",f,d,a)),t.html}var v=function(e){return{parentNode:e.parentElement,insertBeforeNode:e.nextElementSibling}},b=function(e,t){t.parentNode.insertBefore(e,t.insertBeforeNode)};function p(e){var t=i(e);return t.position||(t.position=u(e,"position",v,b,c)),t.position}var h,S=function(e,t){return t?e.className=t:e.removeAttribute("class")},g=function(e){return e.className};function y(e){var t=i(e);return t.classes||(t.classes=u(e,"class",g,S,l)),t.classes}function E(e,t){var n,r=i(e);return r.attributes[t]||(r.attributes[t]=u(e,t,(n=t,function(e){var t;return null!=(t=e.getAttribute(n))?t:null}),function(e){return function(t,n){return null!==n?t.setAttribute(e,n):t.removeAttribute(e)}}(t),s)),r.attributes[t]}function N(e,t,r){if(r.isDirty){r.isDirty=!1;var i=r.virtualValue;r.mutations.length||function(e,t){var r,i,u=n.get(e);if(u)if("html"===t)null==(r=u.html)||null==(i=r.observer)||i.disconnect(),delete u.html;else if("class"===t){var o,a;null==(o=u.classes)||null==(a=o.observer)||a.disconnect(),delete u.classes}else if("position"===t){var l,s;null==(l=u.position)||null==(s=l.observer)||s.disconnect(),delete u.position}else{var c,f,d;null==(c=u.attributes)||null==(f=c[t])||null==(d=f.observer)||d.disconnect(),delete u.attributes[t]}}(e,t),r.setValue(e,i)}}var V,k=!1;function B(e,t){e.html&&N(t,"html",e.html),e.classes&&N(t,"class",e.classes),e.position&&N(t,"position",e.position),Object.keys(e.attributes).forEach((function(n){N(t,n,e.attributes[n])}))}function w(){k=!1,n.forEach(B)}function A(){k||(k=!0,requestAnimationFrame(w))}function M(e,t){var n=null;if("html"===e.kind?n=m(t):"class"===e.kind?n=y(t):"attribute"===e.kind?n=E(t,e.attribute):"position"===e.kind&&(n=p(t)),n){var r=n.mutations.indexOf(e);-1!==r&&n.mutations.splice(r,1),n.mutationRunner(n)}}function x(e){var t=new Set(e.elements),n=new Set;document.querySelectorAll(e.selector).forEach((function(r){n.add(r),t.has(r)||(e.elements.add(r),function(e,t){var n=null;"html"===e.kind?n=m(t):"class"===e.kind?n=y(t):"attribute"===e.kind?n=E(t,e.attribute):"position"===e.kind&&(n=p(t)),n&&(n.mutations.push(e),n.mutationRunner(n))}(e,r))})),t.forEach((function(t){n.has(t)||(e.elements.delete(t),M(e,t))}))}function D(){r.forEach(x)}function L(){"undefined"!=typeof document&&(V||(V=new MutationObserver((function(){D()}))),D(),V.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!1,characterData:!1}))}function O(e){return"undefined"==typeof document?t:(r.add(e),x(e),{revert:function(){var t;(t=e).elements.forEach((function(e){return M(t,e)})),t.elements.clear(),r.delete(t)}})}function j(e,t){return O({kind:"html",elements:new Set,mutate:t,selector:e})}function q(e,t){return O({kind:"position",elements:new Set,mutate:t,selector:e})}function H(e,t){return O({kind:"class",elements:new Set,mutate:t,selector:e})}function T(n,r,i){return e.test(r)?"class"===r||"className"===r?H(n,(function(e){var t=i(Array.from(e).join(" "));e.clear(),t&&t.split(/\s+/g).filter(Boolean).forEach((function(t){return e.add(t)}))})):O({kind:"attribute",attribute:r,elements:new Set,mutate:i,selector:n}):t}L();var _={html:j,classes:H,attribute:T,position:q,declarative:function(e){var n=e.selector,r=e.action,i=e.value,u=e.attribute,o=e.parentSelector,a=e.insertBeforeSelector;if("html"===u){if("append"===r)return j(n,(function(e){return e+(null!=i?i:"")}));if("set"===r)return j(n,(function(){return null!=i?i:""}))}else if("class"===u){if("append"===r)return H(n,(function(e){i&&e.add(i)}));if("remove"===r)return H(n,(function(e){i&&e.delete(i)}));if("set"===r)return H(n,(function(e){e.clear(),i&&e.add(i)}))}else if("position"===u){if("set"===r&&o)return q(n,(function(){return{insertBeforeSelector:a,parentSelector:o}}))}else{if("append"===r)return T(n,u,(function(e){return null!==e?e+(null!=i?i:""):null!=i?i:""}));if("set"===r)return T(n,u,(function(){return null!=i?i:""}));if("remove"===r)return T(n,u,(function(){return null}))}return t}};exports.connectGlobalObserver=L,exports.default=_,exports.disconnectGlobalObserver=function(){V&&V.disconnect()},exports.validAttributeName=e; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=/^[a-zA-Z:_][a-zA-Z0-9:_.-]*$/,t={revert:function(){}},n=new Map,r=new Set;function i(e){var t=n.get(e);return t||n.set(e,t={element:e,attributes:{}}),t}function o(e,t,n,r,i){var o=n(e),u={isDirty:!1,originalValue:o,virtualValue:o,mutations:[],el:e,_positionTimeout:null,observer:new MutationObserver((function(){if("position"!==t||!u._positionTimeout){"position"===t&&(u._positionTimeout=setTimeout((function(){u._positionTimeout=null}),1e3));var r=n(e);"position"===t&&r.parentNode===u.virtualValue.parentNode&&r.insertBeforeNode===u.virtualValue.insertBeforeNode||r!==u.virtualValue&&(u.originalValue=r,i(u))}})),mutationRunner:i,setValue:r,getCurrentValue:n};return"position"===t&&e.parentNode?u.observer.observe(e.parentNode,{childList:!0,subtree:!0,attributes:!1,characterData:!1}):u.observer.observe(e,function(e){return"html"===e?{childList:!0,subtree:!0,attributes:!0,characterData:!0}:{childList:!1,subtree:!1,attributes:!0,attributeFilter:[e]}}(t)),u}function u(e,t){var n=t.getCurrentValue(t.el);t.virtualValue=e,e&&"string"!=typeof e?n&&e.parentNode===n.parentNode&&e.insertBeforeNode===n.insertBeforeNode||(t.isDirty=!0,E()):e!==n&&(t.isDirty=!0,E())}function a(e){var t=e.originalValue;e.mutations.forEach((function(e){return t=e.mutate(t)})),u(function(e){return h||(h=document.createElement("div")),h.innerHTML=e,h.innerHTML}(t),e)}function l(e){var t=new Set(e.originalValue.split(/\s+/).filter(Boolean));e.mutations.forEach((function(e){return e.mutate(t)})),u(Array.from(t).filter(Boolean).join(" "),e)}function s(e){var t=e.originalValue;e.mutations.forEach((function(e){return t=e.mutate(t)})),u(t,e)}function c(e){var t=e.originalValue;e.mutations.forEach((function(e){var n=function(e){var t=e.insertBeforeSelector,n=document.querySelector(e.parentSelector);if(!n)return null;var r=t?document.querySelector(t):null;return t&&!r?null:{parentNode:n,insertBeforeNode:r}}(e.mutate());t=n||t})),u(t,e)}var f=function(e){return e.innerHTML},d=function(e,t){return e.innerHTML=t};function m(e){var t=i(e);return t.html||(t.html=o(e,"html",f,d,a)),t.html}var v=function(e){return{parentNode:e.parentElement,insertBeforeNode:e.nextElementSibling}},p=function(e,t){t.insertBeforeNode&&!t.parentNode.contains(t.insertBeforeNode)||t.parentNode.insertBefore(e,t.insertBeforeNode)};function b(e){var t=i(e);return t.position||(t.position=o(e,"position",v,p,c)),t.position}var h,N,S=function(e,t){return t?e.className=t:e.removeAttribute("class")},B=function(e){return e.className};function V(e){var t=i(e);return t.classes||(t.classes=o(e,"class",B,S,l)),t.classes}function g(e,t){var n,r=i(e);return r.attributes[t]||(r.attributes[t]=o(e,t,(n=t,function(e){var t;return null!=(t=e.getAttribute(n))?t:null}),function(e){return function(t,n){return null!==n?t.setAttribute(e,n):t.removeAttribute(e)}}(t),s)),r.attributes[t]}function y(e,t,r){if(r.isDirty){r.isDirty=!1;var i=r.virtualValue;r.mutations.length||function(e,t){var r,i,o=n.get(e);if(o)if("html"===t)null==(r=o.html)||null==(i=r.observer)||i.disconnect(),delete o.html;else if("class"===t){var u,a;null==(u=o.classes)||null==(a=u.observer)||a.disconnect(),delete o.classes}else if("position"===t){var l,s;null==(l=o.position)||null==(s=l.observer)||s.disconnect(),delete o.position}else{var c,f,d;null==(c=o.attributes)||null==(f=c[t])||null==(d=f.observer)||d.disconnect(),delete o.attributes[t]}}(e,t),r.setValue(e,i)}}function k(e,t){e.html&&y(t,"html",e.html),e.classes&&y(t,"class",e.classes),e.position&&y(t,"position",e.position),Object.keys(e.attributes).forEach((function(n){y(t,n,e.attributes[n])}))}function E(){n.forEach(k)}function w(e){if("position"!==e.kind||1!==e.elements.size){var t=new Set(e.elements);document.querySelectorAll(e.selector).forEach((function(n){t.has(n)||(e.elements.add(n),function(e,t){var n=null;"html"===e.kind?n=m(t):"class"===e.kind?n=V(t):"attribute"===e.kind?n=g(t,e.attribute):"position"===e.kind&&(n=b(t)),n&&(n.mutations.push(e),n.mutationRunner(n))}(e,n))}))}}function A(){r.forEach(w)}function T(){"undefined"!=typeof document&&(N||(N=new MutationObserver((function(){A()}))),A(),N.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!1,characterData:!1}))}function D(e){return"undefined"==typeof document?t:(r.add(e),w(e),{revert:function(){var t;(t=e).elements.forEach((function(e){return function(e,t){var n=null;if("html"===e.kind?n=m(t):"class"===e.kind?n=V(t):"attribute"===e.kind?n=g(t,e.attribute):"position"===e.kind&&(n=b(t)),n){var r=n.mutations.indexOf(e);-1!==r&&n.mutations.splice(r,1),n.mutationRunner(n)}}(t,e)})),t.elements.clear(),r.delete(t)}})}function L(e,t){return D({kind:"html",elements:new Set,mutate:t,selector:e})}function M(e,t){return D({kind:"position",elements:new Set,mutate:t,selector:e})}function _(e,t){return D({kind:"class",elements:new Set,mutate:t,selector:e})}function x(n,r,i){return e.test(r)?"class"===r||"className"===r?_(n,(function(e){var t=i(Array.from(e).join(" "));e.clear(),t&&t.split(/\s+/g).filter(Boolean).forEach((function(t){return e.add(t)}))})):D({kind:"attribute",attribute:r,elements:new Set,mutate:i,selector:n}):t}T();var O={html:L,classes:_,attribute:x,position:M,declarative:function(e){var n=e.selector,r=e.action,i=e.value,o=e.attribute,u=e.parentSelector,a=e.insertBeforeSelector;if("html"===o){if("append"===r)return L(n,(function(e){return e+(null!=i?i:"")}));if("set"===r)return L(n,(function(){return null!=i?i:""}))}else if("class"===o){if("append"===r)return _(n,(function(e){i&&e.add(i)}));if("remove"===r)return _(n,(function(e){i&&e.delete(i)}));if("set"===r)return _(n,(function(e){e.clear(),i&&e.add(i)}))}else if("position"===o){if("set"===r&&u)return M(n,(function(){return{insertBeforeSelector:a,parentSelector:u}}))}else{if("append"===r)return x(n,o,(function(e){return null!==e?e+(null!=i?i:""):null!=i?i:""}));if("set"===r)return x(n,o,(function(){return null!=i?i:""}));if("remove"===r)return x(n,o,(function(){return null}))}return t}};exports.connectGlobalObserver=T,exports.default=O,exports.disconnectGlobalObserver=function(){N&&N.disconnect()},exports.validAttributeName=e; | ||
//# sourceMappingURL=dom-mutator.cjs.production.min.js.map |
@@ -44,4 +44,13 @@ var validAttributeName = /^[a-zA-Z:_][a-zA-Z0-9:_.-]*$/; | ||
el: el, | ||
_positionTimeout: null, | ||
observer: new MutationObserver(function () { | ||
// enact a 1 second timeout that blocks subsequent firing of the | ||
// observer until the timeout is complete. This will prevent multiple | ||
// mutations from firing in quick succession, which can cause the | ||
// mutation to be reverted before the DOM has a chance to update. | ||
if (attr === 'position' && record._positionTimeout) return;else if (attr === 'position') record._positionTimeout = setTimeout(function () { | ||
record._positionTimeout = null; | ||
}, 1000); | ||
var currentValue = getCurrentValue(el); | ||
if (attr === 'position' && currentValue.parentNode === record.virtualValue.parentNode && currentValue.insertBeforeNode === record.virtualValue.insertBeforeNode) return; | ||
if (currentValue === record.virtualValue) return; | ||
@@ -55,3 +64,14 @@ record.originalValue = currentValue; | ||
}; | ||
record.observer.observe(el, getObserverInit(attr)); | ||
if (attr === 'position' && el.parentNode) { | ||
record.observer.observe(el.parentNode, { | ||
childList: true, | ||
subtree: true, | ||
attributes: false, | ||
characterData: false | ||
}); | ||
} else { | ||
record.observer.observe(el, getObserverInit(attr)); | ||
} | ||
return record; | ||
@@ -67,7 +87,7 @@ } | ||
record.isDirty = true; | ||
queueDOMUpdates(); | ||
runDOMUpdates(); | ||
} | ||
} else if (val !== currentVal) { | ||
record.isDirty = true; | ||
queueDOMUpdates(); | ||
runDOMUpdates(); | ||
} | ||
@@ -151,2 +171,8 @@ } | ||
var setElementPosition = function setElementPosition(el, value) { | ||
if (value.insertBeforeNode && !value.parentNode.contains(value.insertBeforeNode)) { | ||
// skip position mutation - insertBeforeNode not a child of parent. happens | ||
// when mutation observer for indvidual element fires out of order | ||
return; | ||
} | ||
value.parentNode.insertBefore(el, value.insertBeforeNode); | ||
@@ -257,4 +283,2 @@ }; | ||
var raf = false; | ||
function setValue(m, el) { | ||
@@ -269,12 +293,4 @@ m.html && setPropertyValue(el, 'html', m.html); | ||
function setValues() { | ||
raf = false; | ||
function runDOMUpdates() { | ||
elements.forEach(setValue); | ||
} | ||
function queueDOMUpdates() { | ||
if (!raf) { | ||
raf = true; | ||
requestAnimationFrame(setValues); | ||
} | ||
} // find or create ElementPropertyRecord, add mutation to it, then run | ||
@@ -323,8 +339,8 @@ | ||
function refreshElementsSet(mutation) { | ||
// if a position mutation has already found an element to move, don't move | ||
// any more elements | ||
if (mutation.kind === 'position' && mutation.elements.size === 1) return; | ||
var existingElements = new Set(mutation.elements); | ||
var newElements = new Set(); | ||
var matchingElements = document.querySelectorAll(mutation.selector); | ||
matchingElements.forEach(function (el) { | ||
newElements.add(el); | ||
if (!existingElements.has(el)) { | ||
@@ -335,8 +351,2 @@ mutation.elements.add(el); | ||
}); | ||
existingElements.forEach(function (el) { | ||
if (!newElements.has(el)) { | ||
mutation.elements["delete"](el); | ||
stopMutating(mutation, el); | ||
} | ||
}); | ||
} | ||
@@ -343,0 +353,0 @@ |
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
interface BaseMutation { | ||
@@ -33,2 +34,3 @@ selector: string; | ||
interface ElementPropertyRecord<T, V> { | ||
_positionTimeout: NodeJS.Timeout | number | null; | ||
observer: MutationObserver; | ||
@@ -35,0 +37,0 @@ originalValue: V; |
{ | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -50,4 +50,21 @@ export const validAttributeName = /^[a-zA-Z:_][a-zA-Z0-9:_.-]*$/; | ||
el, | ||
_positionTimeout: null, | ||
observer: new MutationObserver(() => { | ||
// enact a 1 second timeout that blocks subsequent firing of the | ||
// observer until the timeout is complete. This will prevent multiple | ||
// mutations from firing in quick succession, which can cause the | ||
// mutation to be reverted before the DOM has a chance to update. | ||
if (attr === 'position' && record._positionTimeout) return; | ||
else if (attr === 'position') | ||
record._positionTimeout = setTimeout(() => { | ||
record._positionTimeout = null; | ||
}, 1000); | ||
const currentValue = getCurrentValue(el); | ||
if ( | ||
attr === 'position' && | ||
currentValue.parentNode === record.virtualValue.parentNode && | ||
currentValue.insertBeforeNode === record.virtualValue.insertBeforeNode | ||
) | ||
return; | ||
if (currentValue === record.virtualValue) return; | ||
@@ -61,3 +78,12 @@ record.originalValue = currentValue; | ||
}; | ||
record.observer.observe(el, getObserverInit(attr)); | ||
if (attr === 'position' && el.parentNode) { | ||
record.observer.observe(el.parentNode, { | ||
childList: true, | ||
subtree: true, | ||
attributes: false, | ||
characterData: false, | ||
}); | ||
} else { | ||
record.observer.observe(el, getObserverInit(attr)); | ||
} | ||
return record; | ||
@@ -79,7 +105,7 @@ } | ||
record.isDirty = true; | ||
queueDOMUpdates(); | ||
runDOMUpdates(); | ||
} | ||
} else if (val !== currentVal) { | ||
record.isDirty = true; | ||
queueDOMUpdates(); | ||
runDOMUpdates(); | ||
} | ||
@@ -159,2 +185,10 @@ } | ||
const setElementPosition = (el: Element, value: ElementPositionWithDomNode) => { | ||
if ( | ||
value.insertBeforeNode && | ||
!value.parentNode.contains(value.insertBeforeNode) | ||
) { | ||
// skip position mutation - insertBeforeNode not a child of parent. happens | ||
// when mutation observer for indvidual element fires out of order | ||
return; | ||
} | ||
value.parentNode.insertBefore(el, value.insertBeforeNode); | ||
@@ -252,4 +286,2 @@ }; | ||
let raf = false; | ||
function setValue(m: ElementRecord, el: Element) { | ||
@@ -263,12 +295,6 @@ m.html && setPropertyValue<HTMLRecord>(el, 'html', m.html); | ||
} | ||
function setValues() { | ||
raf = false; | ||
function runDOMUpdates() { | ||
elements.forEach(setValue); | ||
} | ||
function queueDOMUpdates() { | ||
if (!raf) { | ||
raf = true; | ||
requestAnimationFrame(setValues); | ||
} | ||
} | ||
@@ -312,8 +338,10 @@ // find or create ElementPropertyRecord, add mutation to it, then run | ||
function refreshElementsSet(mutation: Mutation) { | ||
// if a position mutation has already found an element to move, don't move | ||
// any more elements | ||
if (mutation.kind === 'position' && mutation.elements.size === 1) return; | ||
const existingElements = new Set(mutation.elements); | ||
const newElements: Set<Element> = new Set(); | ||
const matchingElements = document.querySelectorAll(mutation.selector); | ||
matchingElements.forEach(el => { | ||
newElements.add(el); | ||
if (!existingElements.has(el)) { | ||
@@ -324,9 +352,2 @@ mutation.elements.add(el); | ||
}); | ||
existingElements.forEach(el => { | ||
if (!newElements.has(el)) { | ||
mutation.elements.delete(el); | ||
stopMutating(mutation, el); | ||
} | ||
}); | ||
} | ||
@@ -333,0 +354,0 @@ |
@@ -45,2 +45,3 @@ interface BaseMutation { | ||
interface ElementPropertyRecord<T, V> { | ||
_positionTimeout: NodeJS.Timeout | number | null; | ||
observer: MutationObserver; | ||
@@ -47,0 +48,0 @@ originalValue: V; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
151188
1539