as-custom-element
Advanced tools
Comparing version 0.0.0 to 0.0.1
'use strict'; | ||
const wm = new WeakMap; | ||
const attributeChangedCallback = records => { | ||
const attributeChanged = records => { | ||
for (let i = 0, {length} = records; i < length; i++) { | ||
@@ -28,2 +28,10 @@ const {attributeName, oldValue, target} = records[i]; | ||
const mainLoop = records => { | ||
for (let i = 0, {length} = records; i < length; i++) { | ||
const {addedNodes, removedNodes} = records[i]; | ||
invoke(addedNodes, 'c'); | ||
invoke(removedNodes, 'd'); | ||
} | ||
}; | ||
const set = target => { | ||
@@ -35,10 +43,8 @@ const sets = {a: new Set, c: new Set, d: new Set, o: new Set}; | ||
const mo = new MutationObserver(records => { | ||
for (let i = 0, {length} = records; i < length; i++) { | ||
const {addedNodes, removedNodes} = records[i]; | ||
invoke(addedNodes, 'c'); | ||
invoke(removedNodes, 'd'); | ||
} | ||
}); | ||
const takeRecords = mo => { | ||
attributeChanged(mo.takeRecords()); | ||
}; | ||
const mo = new MutationObserver(mainLoop); | ||
mo.observe( | ||
@@ -49,9 +55,17 @@ document, | ||
module.exports = (target, setup) => { | ||
const {observedAttributes} = setup; | ||
module.exports = ( | ||
target, | ||
{ | ||
// connected/disconnected | ||
connectedCallback, | ||
disconnectedCallback, | ||
// attributes to be notified about | ||
observedAttributes, | ||
attributeChangedCallback | ||
} | ||
) => { | ||
mainLoop(mo.takeRecords()); | ||
const {a, c, d, o} = wm.get(target) || set(target); | ||
c.add(setup.connectedCallback || fallback); | ||
d.add(setup.disconnectedCallback || fallback); | ||
if (observedAttributes) { | ||
const mo = new MutationObserver(attributeChangedCallback); | ||
const mo = new MutationObserver(attributeChanged); | ||
mo.observe(target, { | ||
@@ -62,10 +76,14 @@ attributes: true, | ||
}); | ||
const callback = setup.attributeChangedCallback || fallback; | ||
a.add(callback); | ||
a.add(attributeChangedCallback || fallback); | ||
o.add(mo); | ||
observedAttributes.forEach(attributeName => { | ||
if (target.hasAttribute(attributeName)) | ||
callback.call(target, attributeName, null, target.getAttribute(attributeName)); | ||
(attributeChangedCallback || fallback) | ||
.call(target, attributeName, null, target.getAttribute(attributeName)); | ||
}); | ||
} | ||
c.add(connectedCallback || fallback); | ||
d.add(disconnectedCallback || fallback); | ||
if (target.ownerDocument.contains(target)) | ||
(connectedCallback || fallback).call(target); | ||
return target; | ||
@@ -77,5 +95,1 @@ }; | ||
} | ||
function takeRecords(mo) { | ||
attributeChangedCallback(mo.takeRecords()); | ||
} |
@@ -1,1 +0,1 @@ | ||
self.asCustomElement=function(t){"use strict";const e=new WeakMap,a=t=>{for(let a=0,{length:n}=t;a<n;a++){const{attributeName:n,oldValue:r,target:o}=t[a],c=o.getAttribute(n);e.get(o).a.forEach(t=>{t.call(o,n,r,c)})}},n=()=>{},r=(t,a)=>{for(let n=0,{length:d}=t;n<d;n++){const d=t[n];e.has(d)&&("d"===a&&e.get(d).o.forEach(c),e.get(d)[a].forEach(o,d)),r(d.children||[],a)}};new MutationObserver(t=>{for(let e=0,{length:a}=t;e<a;e++){const{addedNodes:a,removedNodes:n}=t[e];r(a,"c"),r(n,"d")}}).observe(document,{childList:!0,subtree:!0});function o(t){t.call(this)}function c(t){a(t.takeRecords())}return t.default=(t,r)=>{const{observedAttributes:o}=r,{a:c,c:d,d:l,o:s}=e.get(t)||(t=>{const a={a:new Set,c:new Set,d:new Set,o:new Set};return e.set(t,a),a})(t);if(d.add(r.connectedCallback||n),l.add(r.disconnectedCallback||n),o){const e=new MutationObserver(a);e.observe(t,{attributes:!0,attributeFilter:o,attributeOldValue:!0});const d=r.attributeChangedCallback||n;c.add(d),s.add(e),o.forEach(e=>{t.hasAttribute(e)&&d.call(t,e,null,t.getAttribute(e))})}return t},t}({}).default; | ||
self.asCustomElement=function(t){"use strict";const e=new WeakMap,a=t=>{for(let a=0,{length:n}=t;a<n;a++){const{attributeName:n,oldValue:r,target:o}=t[a],c=o.getAttribute(n);e.get(o).a.forEach(t=>{t.call(o,n,r,c)})}},n=()=>{},r=(t,a)=>{for(let n=0,{length:o}=t;n<o;n++){const o=t[n];e.has(o)&&("d"===a&&e.get(o).o.forEach(c),e.get(o)[a].forEach(l,o)),r(o.children||[],a)}},o=t=>{for(let e=0,{length:a}=t;e<a;e++){const{addedNodes:a,removedNodes:n}=t[e];r(a,"c"),r(n,"d")}},c=t=>{a(t.takeRecords())},d=new MutationObserver(o);d.observe(document,{childList:!0,subtree:!0});function l(t){t.call(this)}return t.default=(t,{connectedCallback:r,disconnectedCallback:c,observedAttributes:l,attributeChangedCallback:s})=>{o(d.takeRecords());const{a:u,c:i,d:b,o:h}=e.get(t)||(t=>{const a={a:new Set,c:new Set,d:new Set,o:new Set};return e.set(t,a),a})(t);if(l){const e=new MutationObserver(a);e.observe(t,{attributes:!0,attributeFilter:l,attributeOldValue:!0}),u.add(s||n),h.add(e),l.forEach(e=>{t.hasAttribute(e)&&(s||n).call(t,e,null,t.getAttribute(e))})}return i.add(r||n),b.add(c||n),t.ownerDocument.contains(t)&&(r||n).call(t),t},t}({}).default; |
const wm = new WeakMap; | ||
const attributeChangedCallback = records => { | ||
const attributeChanged = records => { | ||
for (let i = 0, {length} = records; i < length; i++) { | ||
@@ -27,2 +27,10 @@ const {attributeName, oldValue, target} = records[i]; | ||
const mainLoop = records => { | ||
for (let i = 0, {length} = records; i < length; i++) { | ||
const {addedNodes, removedNodes} = records[i]; | ||
invoke(addedNodes, 'c'); | ||
invoke(removedNodes, 'd'); | ||
} | ||
}; | ||
const set = target => { | ||
@@ -34,10 +42,8 @@ const sets = {a: new Set, c: new Set, d: new Set, o: new Set}; | ||
const mo = new MutationObserver(records => { | ||
for (let i = 0, {length} = records; i < length; i++) { | ||
const {addedNodes, removedNodes} = records[i]; | ||
invoke(addedNodes, 'c'); | ||
invoke(removedNodes, 'd'); | ||
} | ||
}); | ||
const takeRecords = mo => { | ||
attributeChanged(mo.takeRecords()); | ||
}; | ||
const mo = new MutationObserver(mainLoop); | ||
mo.observe( | ||
@@ -48,9 +54,17 @@ document, | ||
export default (target, setup) => { | ||
const {observedAttributes} = setup; | ||
export default ( | ||
target, | ||
{ | ||
// connected/disconnected | ||
connectedCallback, | ||
disconnectedCallback, | ||
// attributes to be notified about | ||
observedAttributes, | ||
attributeChangedCallback | ||
} | ||
) => { | ||
mainLoop(mo.takeRecords()); | ||
const {a, c, d, o} = wm.get(target) || set(target); | ||
c.add(setup.connectedCallback || fallback); | ||
d.add(setup.disconnectedCallback || fallback); | ||
if (observedAttributes) { | ||
const mo = new MutationObserver(attributeChangedCallback); | ||
const mo = new MutationObserver(attributeChanged); | ||
mo.observe(target, { | ||
@@ -61,10 +75,14 @@ attributes: true, | ||
}); | ||
const callback = setup.attributeChangedCallback || fallback; | ||
a.add(callback); | ||
a.add(attributeChangedCallback || fallback); | ||
o.add(mo); | ||
observedAttributes.forEach(attributeName => { | ||
if (target.hasAttribute(attributeName)) | ||
callback.call(target, attributeName, null, target.getAttribute(attributeName)); | ||
(attributeChangedCallback || fallback) | ||
.call(target, attributeName, null, target.getAttribute(attributeName)); | ||
}); | ||
} | ||
c.add(connectedCallback || fallback); | ||
d.add(disconnectedCallback || fallback); | ||
if (target.ownerDocument.contains(target)) | ||
(connectedCallback || fallback).call(target); | ||
return target; | ||
@@ -76,5 +94,1 @@ }; | ||
} | ||
function takeRecords(mo) { | ||
attributeChangedCallback(mo.takeRecords()); | ||
} |
61
index.js
@@ -6,3 +6,3 @@ self.asCustomElement = (function (exports) { | ||
var attributeChangedCallback = function attributeChangedCallback(records) { | ||
var attributeChanged = function attributeChanged(records) { | ||
var _loop = function _loop(i, length) { | ||
@@ -39,2 +39,12 @@ var _records$i = records[i], | ||
var mainLoop = function mainLoop(records) { | ||
for (var i = 0, length = records.length; i < length; i++) { | ||
var _records$i2 = records[i], | ||
addedNodes = _records$i2.addedNodes, | ||
removedNodes = _records$i2.removedNodes; | ||
invoke(addedNodes, 'c'); | ||
invoke(removedNodes, 'd'); | ||
} | ||
}; | ||
var set = function set(target) { | ||
@@ -51,11 +61,7 @@ var sets = { | ||
var mo = new MutationObserver(function (records) { | ||
for (var i = 0, length = records.length; i < length; i++) { | ||
var _records$i2 = records[i], | ||
addedNodes = _records$i2.addedNodes, | ||
removedNodes = _records$i2.removedNodes; | ||
invoke(addedNodes, 'c'); | ||
invoke(removedNodes, 'd'); | ||
} | ||
}); | ||
var takeRecords = function takeRecords(mo) { | ||
attributeChanged(mo.takeRecords()); | ||
}; | ||
var mo = new MutationObserver(mainLoop); | ||
mo.observe(document, { | ||
@@ -65,16 +71,17 @@ childList: true, | ||
}); | ||
var index = (function (target, setup) { | ||
var observedAttributes = setup.observedAttributes; | ||
var index = (function (target, _ref) { | ||
var connectedCallback = _ref.connectedCallback, | ||
disconnectedCallback = _ref.disconnectedCallback, | ||
observedAttributes = _ref.observedAttributes, | ||
attributeChangedCallback = _ref.attributeChangedCallback; | ||
mainLoop(mo.takeRecords()); | ||
var _ref = wm.get(target) || set(target), | ||
a = _ref.a, | ||
c = _ref.c, | ||
d = _ref.d, | ||
o = _ref.o; | ||
var _ref2 = wm.get(target) || set(target), | ||
a = _ref2.a, | ||
c = _ref2.c, | ||
d = _ref2.d, | ||
o = _ref2.o; | ||
c.add(setup.connectedCallback || fallback); | ||
d.add(setup.disconnectedCallback || fallback); | ||
if (observedAttributes) { | ||
var _mo = new MutationObserver(attributeChangedCallback); | ||
var _mo = new MutationObserver(attributeChanged); | ||
@@ -87,10 +94,12 @@ _mo.observe(target, { | ||
var callback = setup.attributeChangedCallback || fallback; | ||
a.add(callback); | ||
a.add(attributeChangedCallback || fallback); | ||
o.add(_mo); | ||
observedAttributes.forEach(function (attributeName) { | ||
if (target.hasAttribute(attributeName)) callback.call(target, attributeName, null, target.getAttribute(attributeName)); | ||
if (target.hasAttribute(attributeName)) (attributeChangedCallback || fallback).call(target, attributeName, null, target.getAttribute(attributeName)); | ||
}); | ||
} | ||
c.add(connectedCallback || fallback); | ||
d.add(disconnectedCallback || fallback); | ||
if (target.ownerDocument.contains(target)) (connectedCallback || fallback).call(target); | ||
return target; | ||
@@ -103,6 +112,2 @@ }); | ||
function takeRecords(mo) { | ||
attributeChangedCallback(mo.takeRecords()); | ||
} | ||
exports.default = index; | ||
@@ -109,0 +114,0 @@ |
@@ -1,1 +0,1 @@ | ||
self.asCustomElement=function(t){"use strict";var e=new WeakMap,a=function(t){for(var a=function(a,n){var r=t[a],o=r.attributeName,c=r.oldValue,u=r.target,i=u.getAttribute(o);e.get(u).a.forEach((function(t){t.call(u,o,c,i)}))},n=0,r=t.length;n<r;n++)a(n)},n=function(){},r=function t(a,n){for(var r=0,u=a.length;r<u;r++){var i=a[r];e.has(i)&&("d"===n&&e.get(i).o.forEach(c),e.get(i)[n].forEach(o,i)),t(i.children||[],n)}};new MutationObserver((function(t){for(var e=0,a=t.length;e<a;e++){var n=t[e],o=n.addedNodes,c=n.removedNodes;r(o,"c"),r(c,"d")}})).observe(document,{childList:!0,subtree:!0});function o(t){t.call(this)}function c(t){a(t.takeRecords())}return t.default=function(t,r){var o=r.observedAttributes,c=e.get(t)||function(t){var a={a:new Set,c:new Set,d:new Set,o:new Set};return e.set(t,a),a}(t),u=c.a,i=c.c,d=c.d,l=c.o;if(i.add(r.connectedCallback||n),d.add(r.disconnectedCallback||n),o){var f=new MutationObserver(a);f.observe(t,{attributes:!0,attributeFilter:o,attributeOldValue:!0});var s=r.attributeChangedCallback||n;u.add(s),l.add(f),o.forEach((function(e){t.hasAttribute(e)&&s.call(t,e,null,t.getAttribute(e))}))}return t},t}({}).default; | ||
self.asCustomElement=function(t){"use strict";var e=new WeakMap,a=function(t){for(var a=function(a,n){var r=t[a],o=r.attributeName,c=r.oldValue,u=r.target,i=u.getAttribute(o);e.get(u).a.forEach((function(t){t.call(u,o,c,i)}))},n=0,r=t.length;n<r;n++)a(n)},n=function(){},r=function t(a,n){for(var r=0,o=a.length;r<o;r++){var u=a[r];e.has(u)&&("d"===n&&e.get(u).o.forEach(c),e.get(u)[n].forEach(i,u)),t(u.children||[],n)}},o=function(t){for(var e=0,a=t.length;e<a;e++){var n=t[e],o=n.addedNodes,c=n.removedNodes;r(o,"c"),r(c,"d")}},c=function(t){a(t.takeRecords())},u=new MutationObserver(o);u.observe(document,{childList:!0,subtree:!0});function i(t){t.call(this)}return t.default=function(t,r){var c=r.connectedCallback,i=r.disconnectedCallback,d=r.observedAttributes,l=r.attributeChangedCallback;o(u.takeRecords());var s=e.get(t)||function(t){var a={a:new Set,c:new Set,d:new Set,o:new Set};return e.set(t,a),a}(t),f=s.a,b=s.c,v=s.d,h=s.o;if(d){var g=new MutationObserver(a);g.observe(t,{attributes:!0,attributeFilter:d,attributeOldValue:!0}),f.add(l||n),h.add(g),d.forEach((function(e){t.hasAttribute(e)&&(l||n).call(t,e,null,t.getAttribute(e))}))}return b.add(c||n),v.add(i||n),t.ownerDocument.contains(t)&&(c||n).call(t),t},t}({}).default; |
{ | ||
"name": "as-custom-element", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "Setup any element as if it was a Custom Element", | ||
@@ -14,3 +14,8 @@ "main": "./cjs/index.js", | ||
}, | ||
"keywords": ["custom", "elements", "built-in", "extend"], | ||
"keywords": [ | ||
"custom", | ||
"elements", | ||
"built-in", | ||
"extend" | ||
], | ||
"author": "Andrea Giammarchi", | ||
@@ -37,2 +42,2 @@ "license": "ISC", | ||
"unpkg": "min.js" | ||
} | ||
} |
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
12697
9
255
1
22