diff --git a/esm/handler.js b/esm/handler.js index 196835e..5329169 100644 --- a/esm/handler.js +++ b/esm/handler.js @@ -153,14 +153,19 @@ export const attr = new Map([ /** * @param {Element} element * @param {string} name + * @param {boolean} svg * @returns */ -export const attribute = (element, name) => { +export const attribute = (element, name, svg) => { switch (name[0]) { case '.': return dot; case '?': return toggle; case '@': return at; - default: return attr.get(name) || (name in element ? direct : regular); + default: return ( + svg ? + regular : + (attr.get(name) || (name in element ? direct : regular)) + ); } }; diff --git a/esm/parser.js b/esm/parser.js index 373dce1..1be6b81 100644 --- a/esm/parser.js +++ b/esm/parser.js @@ -64,7 +64,7 @@ const resolve = (template, values, xml) => { while (node.hasAttribute(search)) { if (!path) path = createPath(node); const name = node.getAttribute(search); - entries.push(entry(ATTRIBUTE_NODE, path, attribute(node, name), name)); + entries.push(entry(ATTRIBUTE_NODE, path, attribute(node, name, xml), name)); node.removeAttribute(search); search = `${prefix}${i++}`; } diff --git a/index.js b/index.js index 66f10e3..9bfc7b8 100644 --- a/index.js +++ b/index.js @@ -1,2 +1,2 @@ -const{isArray:e}=Array,t=[],n=()=>document.createRange(),s=(e,t,n)=>(e.set(t,n),n),r=(e,t,n,s="")=>({t:e,p:t,u:n,n:s}),l=e=>({s:e,t:null,n:null,d:t}),{setPrototypeOf:o}=Object;let i;var c=(e,t,s)=>(i||(i=n()),s?i.setStartAfter(e):i.setStartBefore(e),i.setEndAfter(t),i.deleteContents(),e);const a=({firstChild:e,lastChild:t})=>c(e,t,!0);let u=!1;const h=(e,t)=>u&&11===e.nodeType?1/t<0?t?a(e):e.lastChild:t?e.valueOf():e.firstChild:e;class d extends((e=>{function t(e){return o(e,new.target.prototype)}return t.prototype=e.prototype,t})(DocumentFragment)){#e;#t;constructor(e){super(e),this.#e=[...e.childNodes],this.#t=this.#e.length,u=!0}get firstChild(){return this.#e[0]}get lastChild(){return this.#e.at(-1)}replaceWith(e){a(this).replaceWith(e)}valueOf(){return this.childNodes.length!==this.#t&&this.append(...this.#e),this}}const f=(e,t)=>t.reduceRight(p,e),p=(e,t)=>e.childNodes[t];var g=e=>(n,s)=>{const{c:r,e:l,l:o}=e(n,s),i=r.cloneNode(!0);let c,a,u=l.length,h=u?l.slice(0):t;for(;u--;){const{t:e,p:n,u:r,n:o}=l[u],d=n===a?c:c=f(i,a=n),p=8===e?r():r;h[u]={v:p(d,s[u],o,t),u:p,t:d,n:o}}return((e,t)=>({n:e,d:t}))(1===o?i.firstChild:new d(i),h)};const m=/^(?:plaintext|script|style|textarea|title|xmp)$/i,v=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i,x=/<([a-zA-Z0-9]+[a-zA-Z0-9:._-]*)([^>]*?)(\/?)>/g,b=/([^\s\\>"'=]+)\s*=\s*(['"]?)\x01/g,$=/[\x01\x02]/g;let C;const w=(t,n,r)=>{r=r.slice(1),C||(C=new WeakMap);const l=C.get(t)||s(C,t,{});let o=l[r];return o&&o[0]&&t.removeEventListener(...o),o=e(n)?n:[n,!1],l[r]=o,o[0]&&t.addEventListener(...o),n},y=(e,t,n)=>e[n]=t,N=(e,t,n)=>y(e,t,n.slice(1)),A=(e,t,n)=>(null==t?e.removeAttribute(n):e.setAttribute(n,t),t),W=(e,t,n)=>(e.toggleAttribute(n.slice(1),t),t),k=(e,n,s,r)=>n.length?((e,t,n,s,r)=>{const l=n.length;let o=t.length,i=l,c=0,a=0,u=null;for(;cr-a){const l=s(t[c],0);for(;a{for(const n in t){const s=t[n],r="role"===n?n:`aria-${n}`;null==s?e.removeAttribute(r):e.setAttribute(r,s)}return t}],["class",(e,t)=>y(e,t,"className")],["data",(e,t)=>{const{dataset:n}=e;for(const e in t)null==t[e]?delete n[e]:n[e]=t[e];return t}],["ref",(e,t)=>("function"==typeof t?t(e):t.current=e,t)],["style",(e,t)=>y(e.style,t,"cssText")]]),M=(e,t)=>{switch(t[0]){case".":return N;case"?":return W;case"@":return w;default:return E.get(t)||(t in e?y:A)}},O=(e,t)=>(e.texContent=null==t?"":t,t);function S(e,t){const n=this.n||(this.n=e);switch(typeof t){case"string":case"number":case"boolean":n!==e&&n.replaceWith(this.n=e),this.n.data=t;break;case"object":case"undefined":null==t?(this.n=e).data="":this.n=t.valueOf(),n.replaceWith(this.n)}return t}let T,B,j=document.createElement("template");var L=(e,t)=>{if(t)return T||(T=document.createElementNS("http://www.w3.org/2000/svg","svg"),B=n(),B.selectNodeContents(T)),B.createContextualFragment(e);j.innerHTML=e;const{content:s}=j;return j=j.cloneNode(!1),s};const z=e=>{const t=[];let n;for(;n=e.parentNode;)t.push(t.indexOf.call(n.childNodes,e)),e=n;return t},F=()=>S.bind({n:null}),R=()=>k,Z=(n,l,o)=>{const i=L(((e,t,n)=>{let s=0;return e.join("").trim().replace(x,((e,t,s,r)=>`<${t}${s.replace(b,"=$2$1").trimEnd()}${r?n||v.test(t)?" /":`>`)).replace($,(e=>""===e?`\x3c!--${t+s++}--\x3e`:t+s++))})(n,H,o),o);let c=t;const{length:a}=n;if(a>1){const t=document.createTreeWalker(i,129),n=[];let s=0,o=`${H}${s++}`;for(c=[];s(t,n)=>D.get(t)||Z(t,n,e);const _=g(P(!1)),q=g(P(!0)),G=(e,{s:n,t:s,v:r})=>{r.length&&e.s===t&&(e.s=[]);const l=I(e,r);if(e.t!==s){const{n:t,d:l}=(n?q:_)(s,r);e.t=s,e.n=t,e.d=l}else{const{d:t}=e;for(let e=0;e{const{length:r}=s;for(let o=0;o{const r=K.get(e)||s(K,e,l(t));return r.n!==G(r,"function"==typeof n?n():n)&&e.replaceChildren(r.n),e}; +const{isArray:e}=Array,t=[],n=()=>document.createRange(),s=(e,t,n)=>(e.set(t,n),n),r=(e,t,n,s="")=>({t:e,p:t,u:n,n:s}),l=e=>({s:e,t:null,n:null,d:t}),{setPrototypeOf:o}=Object;let i;var c=(e,t,s)=>(i||(i=n()),s?i.setStartAfter(e):i.setStartBefore(e),i.setEndAfter(t),i.deleteContents(),e);const a=({firstChild:e,lastChild:t})=>c(e,t,!0);let u=!1;const h=(e,t)=>u&&11===e.nodeType?1/t<0?t?a(e):e.lastChild:t?e.valueOf():e.firstChild:e;class d extends((e=>{function t(e){return o(e,new.target.prototype)}return t.prototype=e.prototype,t})(DocumentFragment)){#e;#t;constructor(e){super(e),this.#e=[...e.childNodes],this.#t=this.#e.length,u=!0}get firstChild(){return this.#e[0]}get lastChild(){return this.#e.at(-1)}replaceWith(e){a(this).replaceWith(e)}valueOf(){return this.childNodes.length!==this.#t&&this.append(...this.#e),this}}const f=(e,t)=>t.reduceRight(p,e),p=(e,t)=>e.childNodes[t];var g=e=>(n,s)=>{const{c:r,e:l,l:o}=e(n,s),i=r.cloneNode(!0);let c,a,u=l.length,h=u?l.slice(0):t;for(;u--;){const{t:e,p:n,u:r,n:o}=l[u],d=n===a?c:c=f(i,a=n),p=8===e?r():r;h[u]={v:p(d,s[u],o,t),u:p,t:d,n:o}}return((e,t)=>({n:e,d:t}))(1===o?i.firstChild:new d(i),h)};const m=/^(?:plaintext|script|style|textarea|title|xmp)$/i,v=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i,x=/<([a-zA-Z0-9]+[a-zA-Z0-9:._-]*)([^>]*?)(\/?)>/g,b=/([^\s\\>"'=]+)\s*=\s*(['"]?)\x01/g,$=/[\x01\x02]/g;let C;const w=(t,n,r)=>{r=r.slice(1),C||(C=new WeakMap);const l=C.get(t)||s(C,t,{});let o=l[r];return o&&o[0]&&t.removeEventListener(...o),o=e(n)?n:[n,!1],l[r]=o,o[0]&&t.addEventListener(...o),n},y=(e,t,n)=>e[n]=t,N=(e,t,n)=>y(e,t,n.slice(1)),A=(e,t,n)=>(null==t?e.removeAttribute(n):e.setAttribute(n,t),t),W=(e,t,n)=>(e.toggleAttribute(n.slice(1),t),t),k=(e,n,s,r)=>n.length?((e,t,n,s,r)=>{const l=n.length;let o=t.length,i=l,c=0,a=0,u=null;for(;cr-a){const l=s(t[c],0);for(;a{for(const n in t){const s=t[n],r="role"===n?n:`aria-${n}`;null==s?e.removeAttribute(r):e.setAttribute(r,s)}return t}],["class",(e,t)=>y(e,t,"className")],["data",(e,t)=>{const{dataset:n}=e;for(const e in t)null==t[e]?delete n[e]:n[e]=t[e];return t}],["ref",(e,t)=>("function"==typeof t?t(e):t.current=e,t)],["style",(e,t)=>y(e.style,t,"cssText")]]),M=(e,t,n)=>{switch(t[0]){case".":return N;case"?":return W;case"@":return w;default:return n?A:E.get(t)||(t in e?y:A)}},O=(e,t)=>(e.texContent=null==t?"":t,t);function S(e,t){const n=this.n||(this.n=e);switch(typeof t){case"string":case"number":case"boolean":n!==e&&n.replaceWith(this.n=e),this.n.data=t;break;case"object":case"undefined":null==t?(this.n=e).data="":this.n=t.valueOf(),n.replaceWith(this.n)}return t}let T,B,j=document.createElement("template");var L=(e,t)=>{if(t)return T||(T=document.createElementNS("http://www.w3.org/2000/svg","svg"),B=n(),B.selectNodeContents(T)),B.createContextualFragment(e);j.innerHTML=e;const{content:s}=j;return j=j.cloneNode(!1),s};const z=e=>{const t=[];let n;for(;n=e.parentNode;)t.push(t.indexOf.call(n.childNodes,e)),e=n;return t},F=()=>S.bind({n:null}),R=()=>k,Z=(n,l,o)=>{const i=L(((e,t,n)=>{let s=0;return e.join("").trim().replace(x,((e,t,s,r)=>`<${t}${s.replace(b,"=$2$1").trimEnd()}${r?n||v.test(t)?" /":`>`)).replace($,(e=>""===e?`\x3c!--${t+s++}--\x3e`:t+s++))})(n,H,o),o);let c=t;const{length:a}=n;if(a>1){const t=document.createTreeWalker(i,129),n=[];let s=0,u=`${H}${s++}`;for(c=[];s(t,n)=>D.get(t)||Z(t,n,e);const _=g(P(!1)),q=g(P(!0)),G=(e,{s:n,t:s,v:r})=>{r.length&&e.s===t&&(e.s=[]);const l=I(e,r);if(e.t!==s){const{n:t,d:l}=(n?q:_)(s,r);e.t=s,e.n=t,e.d=l}else{const{d:t}=e;for(let e=0;e{const{length:r}=s;for(let o=0;o{const r=K.get(e)||s(K,e,l(t));return r.n!==G(r,"function"==typeof n?n():n)&&e.replaceChildren(r.n),e}; /*! (c) Andrea Giammarchi - MIT */const U=e=>(t,...n)=>new J(e,t,n),V=U(!1),X=U(!0);export{J as Hole,E as attr,V as html,Q as render,X as svg}; diff --git a/keyed.js b/keyed.js index 47ac443..6ec6e0a 100644 --- a/keyed.js +++ b/keyed.js @@ -1,2 +1,2 @@ -const{isArray:e}=Array,t=[],n=()=>document.createRange(),s=(e,t,n)=>(e.set(t,n),n),r=(e,t,n,s="")=>({t:e,p:t,u:n,n:s}),l=e=>({s:e,t:null,n:null,d:t}),{setPrototypeOf:o}=Object;let i;var c=(e,t,s)=>(i||(i=n()),s?i.setStartAfter(e):i.setStartBefore(e),i.setEndAfter(t),i.deleteContents(),e);const a=({firstChild:e,lastChild:t})=>c(e,t,!0);let u=!1;const h=(e,t)=>u&&11===e.nodeType?1/t<0?t?a(e):e.lastChild:t?e.valueOf():e.firstChild:e;class d extends((e=>{function t(e){return o(e,new.target.prototype)}return t.prototype=e.prototype,t})(DocumentFragment)){#e;#t;constructor(e){super(e),this.#e=[...e.childNodes],this.#t=this.#e.length,u=!0}get firstChild(){return this.#e[0]}get lastChild(){return this.#e.at(-1)}replaceWith(e){a(this).replaceWith(e)}valueOf(){return this.childNodes.length!==this.#t&&this.append(...this.#e),this}}const f=(e,t)=>t.reduceRight(p,e),p=(e,t)=>e.childNodes[t];var g=e=>(n,s)=>{const{c:r,e:l,l:o}=e(n,s),i=r.cloneNode(!0);let c,a,u=l.length,h=u?l.slice(0):t;for(;u--;){const{t:e,p:n,u:r,n:o}=l[u],d=n===a?c:c=f(i,a=n),p=8===e?r():r;h[u]={v:p(d,s[u],o,t),u:p,t:d,n:o}}return((e,t)=>({n:e,d:t}))(1===o?i.firstChild:new d(i),h)};const m=/^(?:plaintext|script|style|textarea|title|xmp)$/i,v=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i,b=/<([a-zA-Z0-9]+[a-zA-Z0-9:._-]*)([^>]*?)(\/?)>/g,x=/([^\s\\>"'=]+)\s*=\s*(['"]?)\x01/g,$=/[\x01\x02]/g;let w;const C=(t,n,r)=>{r=r.slice(1),w||(w=new WeakMap);const l=w.get(t)||s(w,t,{});let o=l[r];return o&&o[0]&&t.removeEventListener(...o),o=e(n)?n:[n,!1],l[r]=o,o[0]&&t.addEventListener(...o),n},y=(e,t,n)=>e[n]=t,N=(e,t,n)=>y(e,t,n.slice(1)),A=(e,t,n)=>(null==t?e.removeAttribute(n):e.setAttribute(n,t),t),W=(e,t,n)=>(e.toggleAttribute(n.slice(1),t),t),k=(e,n,s,r)=>n.length?((e,t,n,s,r)=>{const l=n.length;let o=t.length,i=l,c=0,a=0,u=null;for(;cr-a){const l=s(t[c],0);for(;a{for(const n in t){const s=t[n],r="role"===n?n:`aria-${n}`;null==s?e.removeAttribute(r):e.setAttribute(r,s)}return t}],["class",(e,t)=>y(e,t,"className")],["data",(e,t)=>{const{dataset:n}=e;for(const e in t)null==t[e]?delete n[e]:n[e]=t[e];return t}],["ref",(e,t)=>("function"==typeof t?t(e):t.current=e,t)],["style",(e,t)=>y(e.style,t,"cssText")]]),E=(e,t)=>{switch(t[0]){case".":return N;case"?":return W;case"@":return C;default:return M.get(t)||(t in e?y:A)}},O=(e,t)=>(e.texContent=null==t?"":t,t);function S(e,t){const n=this.n||(this.n=e);switch(typeof t){case"string":case"number":case"boolean":n!==e&&n.replaceWith(this.n=e),this.n.data=t;break;case"object":case"undefined":null==t?(this.n=e).data="":this.n=t.valueOf(),n.replaceWith(this.n)}return t}let T,B,j=document.createElement("template");var L=(e,t)=>{if(t)return T||(T=document.createElementNS("http://www.w3.org/2000/svg","svg"),B=n(),B.selectNodeContents(T)),B.createContextualFragment(e);j.innerHTML=e;const{content:s}=j;return j=j.cloneNode(!1),s};const z=e=>{const t=[];let n;for(;n=e.parentNode;)t.push(t.indexOf.call(n.childNodes,e)),e=n;return t},F=()=>S.bind({n:null}),R=()=>k,Z=(n,l,o)=>{const i=L(((e,t,n)=>{let s=0;return e.join("").trim().replace(b,((e,t,s,r)=>`<${t}${s.replace(x,"=$2$1").trimEnd()}${r?n||v.test(t)?" /":`>`)).replace($,(e=>""===e?`\x3c!--${t+s++}--\x3e`:t+s++))})(n,H,o),o);let c=t;const{length:a}=n;if(a>1){const t=document.createTreeWalker(i,129),n=[];let s=0,o=`${H}${s++}`;for(c=[];s(t,n)=>D.get(t)||Z(t,n,e);const _=g(P(!1)),q=g(P(!0)),G=(e,{s:n,t:s,v:r})=>{r.length&&e.s===t&&(e.s=[]);const l=I(e,r);if(e.t!==s){const{n:t,d:l}=(n?q:_)(s,r);e.t=s,e.n=t,e.d=l}else{const{d:t}=e;for(let e=0;e{const{length:r}=s;for(let o=0;odocument.createRange(),s=(e,t,n)=>(e.set(t,n),n),r=(e,t,n,s="")=>({t:e,p:t,u:n,n:s}),l=e=>({s:e,t:null,n:null,d:t}),{setPrototypeOf:o}=Object;let i;var c=(e,t,s)=>(i||(i=n()),s?i.setStartAfter(e):i.setStartBefore(e),i.setEndAfter(t),i.deleteContents(),e);const a=({firstChild:e,lastChild:t})=>c(e,t,!0);let u=!1;const h=(e,t)=>u&&11===e.nodeType?1/t<0?t?a(e):e.lastChild:t?e.valueOf():e.firstChild:e;class d extends((e=>{function t(e){return o(e,new.target.prototype)}return t.prototype=e.prototype,t})(DocumentFragment)){#e;#t;constructor(e){super(e),this.#e=[...e.childNodes],this.#t=this.#e.length,u=!0}get firstChild(){return this.#e[0]}get lastChild(){return this.#e.at(-1)}replaceWith(e){a(this).replaceWith(e)}valueOf(){return this.childNodes.length!==this.#t&&this.append(...this.#e),this}}const f=(e,t)=>t.reduceRight(p,e),p=(e,t)=>e.childNodes[t];var g=e=>(n,s)=>{const{c:r,e:l,l:o}=e(n,s),i=r.cloneNode(!0);let c,a,u=l.length,h=u?l.slice(0):t;for(;u--;){const{t:e,p:n,u:r,n:o}=l[u],d=n===a?c:c=f(i,a=n),p=8===e?r():r;h[u]={v:p(d,s[u],o,t),u:p,t:d,n:o}}return((e,t)=>({n:e,d:t}))(1===o?i.firstChild:new d(i),h)};const m=/^(?:plaintext|script|style|textarea|title|xmp)$/i,v=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i,b=/<([a-zA-Z0-9]+[a-zA-Z0-9:._-]*)([^>]*?)(\/?)>/g,x=/([^\s\\>"'=]+)\s*=\s*(['"]?)\x01/g,$=/[\x01\x02]/g;let w;const C=(t,n,r)=>{r=r.slice(1),w||(w=new WeakMap);const l=w.get(t)||s(w,t,{});let o=l[r];return o&&o[0]&&t.removeEventListener(...o),o=e(n)?n:[n,!1],l[r]=o,o[0]&&t.addEventListener(...o),n},y=(e,t,n)=>e[n]=t,N=(e,t,n)=>y(e,t,n.slice(1)),A=(e,t,n)=>(null==t?e.removeAttribute(n):e.setAttribute(n,t),t),W=(e,t,n)=>(e.toggleAttribute(n.slice(1),t),t),k=(e,n,s,r)=>n.length?((e,t,n,s,r)=>{const l=n.length;let o=t.length,i=l,c=0,a=0,u=null;for(;cr-a){const l=s(t[c],0);for(;a{for(const n in t){const s=t[n],r="role"===n?n:`aria-${n}`;null==s?e.removeAttribute(r):e.setAttribute(r,s)}return t}],["class",(e,t)=>y(e,t,"className")],["data",(e,t)=>{const{dataset:n}=e;for(const e in t)null==t[e]?delete n[e]:n[e]=t[e];return t}],["ref",(e,t)=>("function"==typeof t?t(e):t.current=e,t)],["style",(e,t)=>y(e.style,t,"cssText")]]),E=(e,t,n)=>{switch(t[0]){case".":return N;case"?":return W;case"@":return C;default:return n?A:M.get(t)||(t in e?y:A)}},O=(e,t)=>(e.texContent=null==t?"":t,t);function S(e,t){const n=this.n||(this.n=e);switch(typeof t){case"string":case"number":case"boolean":n!==e&&n.replaceWith(this.n=e),this.n.data=t;break;case"object":case"undefined":null==t?(this.n=e).data="":this.n=t.valueOf(),n.replaceWith(this.n)}return t}let T,B,j=document.createElement("template");var L=(e,t)=>{if(t)return T||(T=document.createElementNS("http://www.w3.org/2000/svg","svg"),B=n(),B.selectNodeContents(T)),B.createContextualFragment(e);j.innerHTML=e;const{content:s}=j;return j=j.cloneNode(!1),s};const z=e=>{const t=[];let n;for(;n=e.parentNode;)t.push(t.indexOf.call(n.childNodes,e)),e=n;return t},F=()=>S.bind({n:null}),R=()=>k,Z=(n,l,o)=>{const i=L(((e,t,n)=>{let s=0;return e.join("").trim().replace(b,((e,t,s,r)=>`<${t}${s.replace(x,"=$2$1").trimEnd()}${r?n||v.test(t)?" /":`>`)).replace($,(e=>""===e?`\x3c!--${t+s++}--\x3e`:t+s++))})(n,H,o),o);let c=t;const{length:a}=n;if(a>1){const t=document.createTreeWalker(i,129),n=[];let s=0,u=`${H}${s++}`;for(c=[];s(t,n)=>D.get(t)||Z(t,n,e);const _=g(P(!1)),q=g(P(!0)),G=(e,{s:n,t:s,v:r})=>{r.length&&e.s===t&&(e.s=[]);const l=I(e,r);if(e.t!==s){const{n:t,d:l}=(n?q:_)(s,r);e.t=s,e.n=t,e.d=l}else{const{d:t}=e;for(let e=0;e{const{length:r}=s;for(let o=0;o(t,...n)=>new J(e,t,n),Q=K(!1),U=K(!0),V=new WeakMap;var X=(e,n)=>{const r=V.get(e)||s(V,e,l(t)),o="function"==typeof n?n():n,{n:i}=r,c=o instanceof J?G(r,o):o;return i!==c&&e.replaceChildren(r.n=c),e};const Y=new WeakMap,ee=e=>(n,r)=>{const o=Y.get(n)||s(Y,n,new Map);return o.get(r)||s(o,r,function(t,...n){return G(this,new J(e,t,n))}.bind(l(t)))},te=ee(!1),ne=ee(!0);export{J as Hole,M as attr,Q as html,te as htmlFor,X as render,U as svg,ne as svgFor}; diff --git a/node.js b/node.js index b8c28c1..5a79be8 100644 --- a/node.js +++ b/node.js @@ -1,3 +1,3 @@ -const{setPrototypeOf:e}=Object;const{isArray:t}=Array,n=[],r=()=>document.createRange(),s=(e,t,n)=>(e.set(t,n),n);let l;var o=(e,t,n)=>(l||(l=r()),n?l.setStartAfter(e):l.setStartBefore(e),l.setEndAfter(t),l.deleteContents(),e);const i=({firstChild:e,lastChild:t})=>o(e,t,!0);let c=!1;const a=(e,t)=>c&&11===e.nodeType?1/t<0?t?i(e):e.lastChild:t?e.valueOf():e.firstChild:e;class u extends((t=>{function n(t){return e(t,new.target.prototype)}return n.prototype=t.prototype,n})(DocumentFragment)){#e;#t;constructor(e){super(e),this.#e=[...e.childNodes],this.#t=this.#e.length,c=!0}get firstChild(){return this.#e[0]}get lastChild(){return this.#e.at(-1)}replaceWith(e){i(this).replaceWith(e)}valueOf(){return this.childNodes.length!==this.#t&&this.append(...this.#e),this}}const h=(e,t,n,r="")=>({t:e,p:t,u:n,n:r}),d=(e,t)=>t.reduceRight(f,e),f=(e,t)=>e.childNodes[t];const p=/^(?:plaintext|script|style|textarea|title|xmp)$/i,g=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i,m=/<([a-zA-Z0-9]+[a-zA-Z0-9:._-]*)([^>]*?)(\/?)>/g,x=/([^\s\\>"'=]+)\s*=\s*(['"]?)\x01/g,b=/[\x01\x02]/g;let v;const $=(e,n,r)=>{r=r.slice(1),v||(v=new WeakMap);const l=v.get(e)||s(v,e,{});let o=l[r];return o&&o[0]&&e.removeEventListener(...o),o=t(n)?n:[n,!1],l[r]=o,o[0]&&e.addEventListener(...o),n},C=(e,t,n)=>e[n]=t,y=(e,t,n)=>C(e,t,n.slice(1)),N=(e,t,n)=>(null==t?e.removeAttribute(n):e.setAttribute(n,t),t),A=(e,t,n)=>(e.toggleAttribute(n.slice(1),t),t),w=(e,t,r,s)=>t.length?((e,t,n,r,s)=>{const l=n.length;let o=t.length,i=l,c=0,a=0,u=null;for(;cs-a){const l=r(t[c],0);for(;a{for(const n in t){const r=t[n],s="role"===n?n:`aria-${n}`;null==r?e.removeAttribute(s):e.setAttribute(s,r)}return t}],["class",(e,t)=>C(e,t,"className")],["data",(e,t)=>{const{dataset:n}=e;for(const e in t)null==t[e]?delete n[e]:n[e]=t[e];return t}],["ref",(e,t)=>("function"==typeof t?t(e):t.current=e,t)],["style",(e,t)=>C(e.style,t,"cssText")]]),k=(e,t)=>{switch(t[0]){case".":return y;case"?":return A;case"@":return $;default:return W.get(t)||(t in e?C:N)}},E=(e,t)=>(e.texContent=null==t?"":t,t);function O(e,t){const n=this.n||(this.n=e);switch(typeof t){case"string":case"number":case"boolean":n!==e&&n.replaceWith(this.n=e),this.n.data=t;break;case"object":case"undefined":null==t?(this.n=e).data="":this.n=t.valueOf(),n.replaceWith(this.n)}return t}let S,T,B=document.createElement("template");var M=(e,t)=>{if(t)return S||(S=document.createElementNS("http://www.w3.org/2000/svg","svg"),T=r(),T.selectNodeContents(S)),T.createContextualFragment(e);B.innerHTML=e;const{content:n}=B;return B=B.cloneNode(!1),n};const j=e=>{const t=[];let n;for(;n=e.parentNode;)t.push(t.indexOf.call(n.childNodes,e)),e=n;return t},L=()=>O.bind({n:null}),z=()=>w,F=(e,r,l)=>{const o=M(((e,t,n)=>{let r=0;return e.join("").trim().replace(m,((e,t,r,s)=>`<${t}${r.replace(x,"=$2$1").trimEnd()}${s?n||g.test(t)?" /":`>`)).replace(b,(e=>""===e?`\x3c!--${t+r++}--\x3e`:t+r++))})(e,Z,l),l);let i=n;const{length:c}=e;if(c>1){const e=document.createTreeWalker(o,129),n=[];let s=0,l=`${Z}${s++}`;for(i=[];s(e.replaceChildren("function"==typeof t?t():t),e); +const{setPrototypeOf:e}=Object;const{isArray:t}=Array,n=[],r=()=>document.createRange(),s=(e,t,n)=>(e.set(t,n),n);let l;var o=(e,t,n)=>(l||(l=r()),n?l.setStartAfter(e):l.setStartBefore(e),l.setEndAfter(t),l.deleteContents(),e);const i=({firstChild:e,lastChild:t})=>o(e,t,!0);let c=!1;const a=(e,t)=>c&&11===e.nodeType?1/t<0?t?i(e):e.lastChild:t?e.valueOf():e.firstChild:e;class u extends((t=>{function n(t){return e(t,new.target.prototype)}return n.prototype=t.prototype,n})(DocumentFragment)){#e;#t;constructor(e){super(e),this.#e=[...e.childNodes],this.#t=this.#e.length,c=!0}get firstChild(){return this.#e[0]}get lastChild(){return this.#e.at(-1)}replaceWith(e){i(this).replaceWith(e)}valueOf(){return this.childNodes.length!==this.#t&&this.append(...this.#e),this}}const h=(e,t,n,r="")=>({t:e,p:t,u:n,n:r}),d=(e,t)=>t.reduceRight(f,e),f=(e,t)=>e.childNodes[t];const p=/^(?:plaintext|script|style|textarea|title|xmp)$/i,g=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i,m=/<([a-zA-Z0-9]+[a-zA-Z0-9:._-]*)([^>]*?)(\/?)>/g,x=/([^\s\\>"'=]+)\s*=\s*(['"]?)\x01/g,b=/[\x01\x02]/g;let v;const $=(e,n,r)=>{r=r.slice(1),v||(v=new WeakMap);const l=v.get(e)||s(v,e,{});let o=l[r];return o&&o[0]&&e.removeEventListener(...o),o=t(n)?n:[n,!1],l[r]=o,o[0]&&e.addEventListener(...o),n},C=(e,t,n)=>e[n]=t,y=(e,t,n)=>C(e,t,n.slice(1)),N=(e,t,n)=>(null==t?e.removeAttribute(n):e.setAttribute(n,t),t),A=(e,t,n)=>(e.toggleAttribute(n.slice(1),t),t),w=(e,t,r,s)=>t.length?((e,t,n,r,s)=>{const l=n.length;let o=t.length,i=l,c=0,a=0,u=null;for(;cs-a){const l=r(t[c],0);for(;a{for(const n in t){const r=t[n],s="role"===n?n:`aria-${n}`;null==r?e.removeAttribute(s):e.setAttribute(s,r)}return t}],["class",(e,t)=>C(e,t,"className")],["data",(e,t)=>{const{dataset:n}=e;for(const e in t)null==t[e]?delete n[e]:n[e]=t[e];return t}],["ref",(e,t)=>("function"==typeof t?t(e):t.current=e,t)],["style",(e,t)=>C(e.style,t,"cssText")]]),k=(e,t,n)=>{switch(t[0]){case".":return y;case"?":return A;case"@":return $;default:return n?N:W.get(t)||(t in e?C:N)}},E=(e,t)=>(e.texContent=null==t?"":t,t);function O(e,t){const n=this.n||(this.n=e);switch(typeof t){case"string":case"number":case"boolean":n!==e&&n.replaceWith(this.n=e),this.n.data=t;break;case"object":case"undefined":null==t?(this.n=e).data="":this.n=t.valueOf(),n.replaceWith(this.n)}return t}let S,T,B=document.createElement("template");var M=(e,t)=>{if(t)return S||(S=document.createElementNS("http://www.w3.org/2000/svg","svg"),T=r(),T.selectNodeContents(S)),T.createContextualFragment(e);B.innerHTML=e;const{content:n}=B;return B=B.cloneNode(!1),n};const j=e=>{const t=[];let n;for(;n=e.parentNode;)t.push(t.indexOf.call(n.childNodes,e)),e=n;return t},L=()=>O.bind({n:null}),z=()=>w,F=(e,r,l)=>{const o=M(((e,t,n)=>{let r=0;return e.join("").trim().replace(m,((e,t,r,s)=>`<${t}${r.replace(x,"=$2$1").trimEnd()}${s?n||g.test(t)?" /":`>`)).replace(b,(e=>""===e?`\x3c!--${t+r++}--\x3e`:t+r++))})(e,Z,l),l);let i=n;const{length:c}=e;if(c>1){const e=document.createTreeWalker(o,129),n=[];let s=0,a=`${Z}${s++}`;for(i=[];s(e.replaceChildren("function"==typeof t?t():t),e); /*! (c) Andrea Giammarchi - MIT */ const H=e=>{const t=(e=>(t,r)=>{const{c:s,e:l,l:o}=e(t,r),i=s.cloneNode(!0);let c,a,h=l.length,f=h?l.slice(0):n;for(;h--;){const{t:e,p:t,u:s,n:o}=l[h],u=t===a?c:c=d(i,a=t),p=8===e?s():s;f[h]={v:p(u,r[h],o,n),u:p,t:u,n:o}}return{n:1===o?i.firstChild:new u(i),d:f}})((r=e,(e,t)=>R.get(e)||F(e,t,r)));var r;return(e,...n)=>t(e,n).n},P=H(!1),_=H(!0);export{W as attr,P as html,D as render,_ as svg}; diff --git a/test/svg.html b/test/svg.html index f0c9bc1..1c7b650 100644 --- a/test/svg.html +++ b/test/svg.html @@ -3,25 +3,21 @@ - - - \ No newline at end of file + diff --git a/types/handler.d.ts b/types/handler.d.ts index 41e18d8..b2d447c 100644 --- a/types/handler.d.ts +++ b/types/handler.d.ts @@ -19,5 +19,5 @@ export class hole { } export function array(node: Node, value: T, _: string, prev: Node[]): T; export const attr: Map(element: Element, value: T) => T>; -export function attribute(element: Element, name: string): (element: Element, value: T, name: string) => T; +export function attribute(element: Element, name: string, svg: boolean): (element: Element, value: T, name: string) => T; export function text(element: Element, value: T): T;