@webreflection/elements 0.0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +5 -8
  2. package/min.js +3 -0
  3. package/package.json +3 -2
package/README.md CHANGED
@@ -4,15 +4,16 @@ HTML & SVG Custom Elements, glueing [qsa-observer](https://github.com/WebReflect
4
4
 
5
5
  ```html
6
6
  <script type="module">
7
+
7
8
  import { elements, HTML, SVG } from 'https://esm.run/@webreflection/elements';
8
9
 
9
10
  // same Custom Elements API
10
- elements.whenDefined('header').then(() => {
11
- console.log('header defined');
11
+ elements.whenDefined('my-h1').then(Class => {
12
+ console.log(Class.name, 'defined');
12
13
  });
13
14
 
14
15
  // native extends out of the box
15
- elements.define('header', class extends HTML.H1 {
16
+ elements.define('my-h1', class MyH1 extends HTML.H1 {
16
17
  // anything that works with classes works here
17
18
  #private;
18
19
 
@@ -30,12 +31,8 @@ HTML & SVG Custom Elements, glueing [qsa-observer](https://github.com/WebReflect
30
31
  }
31
32
  });
32
33
 
33
- // automatic upgrades per element
34
- elements.whenDefined('header').then(() => {
35
- console.log('header defined');
36
- });
37
34
  </script>
38
- <h1 is="header"></h1>
35
+ <h1 is="my-h1"></h1>
39
36
  ```
40
37
 
41
38
  Enjoy 👋
package/min.js ADDED
@@ -0,0 +1,3 @@
1
+ /*! (c) Andrea Giammarchi - ISC */
2
+ const e=!0,t=!1,o="querySelectorAll",r="querySelectorAll",{document:n,Element:s,MutationObserver:l,Set:a,WeakMap:c}=self,d=e=>r in e,{filter:i}=[];const{setPrototypeOf:u}=Object;const h="attributeChangedCallback",f="connectedCallback",w="disconnectedCallback";var p=(e,{MutationObserver:t,Element:o})=>{const r=new WeakSet,n=(e,t,o,s,l)=>{for(const a of e)(l||"querySelectorAll"in a)&&(s?t.has(a)||(t.add(a),o.delete(a),r.has(a)&&a[f]?.()):o.has(a)||(o.add(a),t.delete(a),r.has(a)&&a[w]?.()),l||n(a.querySelectorAll("*"),t,o,s,!0))},s=e=>{const t=new Set,o=new Set;for(const{addedNodes:r,removedNodes:s}of e)n(s,t,o,!1,!1),n(r,t,o,!0,!1)},l=t||globalThis.MutationObserver,a=new l(s),c=new l(e=>{for(const{target:t,attributeName:o,oldValue:r}of e)t[h](o,r,t.getAttribute(o))}),d=e=>{a.observe(e,{subtree:!0,childList:!0})};d(e);const i=o||globalThis.Element;if(i){const e=i.prototype.attachShadow;i.prototype.attachShadow=function(t){const o=e.call(this,t);return d(o),o}}return e=>{const{[h]:t,[f]:o,[w]:n}=e;if(t&&c.observe(e,{attributes:!0,attributeOldValue:!0,attributeFilter:e.constructor.observedAttributes.map(o=>{const r=e.getAttribute(o);return null!=r&&t.call(e,o,null,r),o})}),o||n){const t=a.takeRecords();t.length&&s(t),r.add(e),Promise.resolve().then(()=>{e.isConnected&&o?.call(e)})}return e}};
3
+ /*! (c) Andrea Giammarchi - ISC */let b={HTML:"http://www.w3.org/1999/xhtml",SVG:"http://www.w3.org/2000/svg"};const g=[],m=new Map,v=new Map,{parse:S}=(u=>{const h=new c,f=(e,t)=>{let o;if(t)for(let r,n=(e=>e.matches||e.webkitMatchesSelector||e.msMatchesSelector)(e),s=0,{length:l}=p;s<l;s++)n.call(e,r=p[s])&&(h.has(e)||h.set(e,new a),o=h.get(e),o.has(r)||(o.add(r),u.handle(e,t,r)));else h.has(e)&&(o=h.get(e),h.delete(e),o.forEach(o=>{u.handle(e,t,o)}))},w=(e,t=!0)=>{for(let o=0,{length:r}=e;o<r;o++)f(e[o],t)},{query:p}=u,b=u.root||n,g=((r,n=document,s=MutationObserver,l=["*"])=>{const a=(t,n,s,l,c,d)=>{for(const i of t)(d||o in i)&&(c?s.has(i)||(s.add(i),l.delete(i),r(i,c)):l.has(i)||(l.add(i),s.delete(i),r(i,c)),d||a(i[o](n),n,s,l,c,e))},c=new s(o=>{if(l.length){const r=l.join(","),n=new Set,s=new Set;for(const{addedNodes:l,removedNodes:c}of o)a(c,r,n,s,t,t),a(l,r,n,s,e,t)}}),{observe:d}=c;return(c.observe=t=>d.call(c,t,{subtree:e,childList:e}))(n),c})(f,b,l,p),{attachShadow:m}=s.prototype;return m&&(s.prototype.attachShadow=function(e){const t=m.call(this,e);return g.observe(t),t}),p.length&&w(b[r](p)),{drop:e=>{for(let t=0,{length:o}=e;t<o;t++)h.delete(e[t])},flush:()=>{const e=g.takeRecords();for(let t=0,{length:o}=e;t<o;t++)w(i.call(e[t].removedNodes,d),!1),w(i.call(e[t].addedNodes,d),!0)},observer:g,parse:w}})({query:g,handle(e,t,o){if(t){const t=m.get((e=>{const t=e.indexOf('="');return e.slice(t+2,-2)})(o));e instanceof t||new t(e)}}}),y=e=>(v.has(e)||v.set(e,Promise.withResolvers()),v.get(e)),{HTML:M,SVG:A}=((e=b)=>{const t=e.document||document,o=p(t,e);return new Proxy(new Map,{get(r,n){let s=r.get(n);if(!s){const l=new Map,a=t.createElementNS.bind(t,e[n]||b[n]),c=(t,r)=>{let s=l.get(r);s||l.set(r,s=a(r).constructor);class c extends((e=>{function t(e){return u(e,new.target.prototype)}return t.prototype=e.prototype,t})(s)){static tag=r;constructor(t){const s=e[n]||b[n];if(t&&t.namespaceURI!==s){const{attributes:e,childNodes:o}=t;t=a(r);for(const{name:o,value:r}of e)t.setAttribute(o,r);t.replaceChildren(...o)}return o(super(t||a(r)))}}return t.set(r,c),c};r.set(n,s=new Proxy(new Map,{get(e,t){const o=t.toLowerCase();return e.get(o)||c(e,o)}}))}return s}})})(),N={define(e,t){if(m.has(e)||customElements.get(e))throw new DOMException(`Element ${e} already defined`);m.set(e,t),y(e).resolve(t);const o=`[is="${e}"]`;g.push(o),S(document.querySelectorAll(o))},get:e=>m.get(e),whenDefined:e=>y(e).promise};export{M as HTML,A as SVG,N as elements};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webreflection/elements",
3
- "version": "0.0.1",
3
+ "version": "0.1.1",
4
4
  "description": "HTML & SVG Custom Elements",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -8,12 +8,13 @@
8
8
  },
9
9
  "exports": {
10
10
  ".": "./index.js",
11
+ "./native": "./native.js",
11
12
  "./package.json": "./package.json",
12
13
  "./min": "./min.js"
13
14
  },
14
15
  "files": [
15
- "elements.js",
16
16
  "index.js",
17
+ "min.js",
17
18
  "README.md",
18
19
  "LICENSE"
19
20
  ],