Comparing version 1.0.0 to 1.0.1
# ultrahtml | ||
## 1.0.1 | ||
### Patch Changes | ||
- b136e51: Fix unhandled edge case with `sanitize` transformer | ||
- dce0b68: Fix style and script elements having their contents parsed as HTML | ||
## 1.0.0 | ||
@@ -4,0 +11,0 @@ |
@@ -1,1 +0,1 @@ | ||
var I=0,L=1,A=2,R=3,k=4;function $(t,n={},...r){let o={type:1,name:typeof t=="function"?t.name:t,attributes:n||{},children:r.map(e=>typeof e=="string"?{type:2,value:x(String(e))}:e),parent:void 0,loc:[]};return typeof t=="function"&&P(o,t),o}var b=Symbol("Fragment"),v=new Set(["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"]),D=/([\@\.a-z0-9_\:\-]*)\s*?=?\s*?(['"]?)(.*?)\2\s+/gim,i=/(?:<(\/?)([a-zA-Z][a-zA-Z0-9\:-]*)(?:\s([^>]*?))?((?:\s*\/)?)>|(<\!\-\-)([\s\S]*?)(\-\->)|(<\!)([\s\S]*?)(>))/gm;function S(t){let n={},r;if(t)for(D.lastIndex=0,t=" "+(t||"")+" ";r=D.exec(t);)r[0]!==" "&&(n[r[1]]=r[3]);return n}function M(t){let n=typeof t=="string"?t:t.value,r,o,e,s,c,d,N,f,a,l=[];i.lastIndex=0,o=r={type:0,children:[]};let E=0;function O(){s=n.substring(E,i.lastIndex-e[0].length),s&&o.children.push({type:2,value:s,parent:o})}for(;e=i.exec(n);)d=e[5]||e[8],N=e[6]||e[9],f=e[7]||e[10],d==="<!--"?(c=i.lastIndex-e[0].length,a={type:3,value:N,parent:o,loc:[{start:c,end:c+d.length},{start:i.lastIndex-f.length,end:i.lastIndex}]},l.push(a),a.parent.children.push(a)):d==="<!"?(c=i.lastIndex-e[0].length,a={type:4,value:N,parent:o,loc:[{start:c,end:c+d.length},{start:i.lastIndex-f.length,end:i.lastIndex}]},l.push(a),a.parent.children.push(a)):e[1]!=="/"?(O(),a={type:1,name:e[2]+"",attributes:S(e[3]),parent:o,children:[],loc:[{start:i.lastIndex-e[0].length,end:i.lastIndex}]},l.push(a),a.parent.children.push(a),e[4]&&e[4].indexOf("/")>-1||v.has(a.name)?(a.loc[1]=a.loc[0],a.isSelfClosingTag=!0):o=a):(O(),e[2]+""===o.name?(a=o,o=a.parent,a.loc.push({start:i.lastIndex-e[0].length,end:i.lastIndex}),s=n.substring(a.loc[0].end,a.loc[1].start),a.children.length===0&&a.children.push({type:2,value:s,parent:o})):e[2]+""===l[l.length-1].name&&l[l.length-1].isSelfClosingTag===!0&&(a=l[l.length-1],a.loc.push({start:i.lastIndex-e[0].length,end:i.lastIndex}))),E=i.lastIndex;return s=n.slice(E),o.children.push({type:2,value:s,parent:o}),r}var y=class{constructor(n){this.callback=n}async visit(n,r,o){if(await this.callback(n,r,o),Array.isArray(n.children)){let e=[];for(let s=0;s<n.children.length;s++){let c=n.children[s];e.push(this.visit(c,n,s))}await Promise.all(e)}}},g=class{constructor(n){this.callback=n}visit(n,r,o){if(this.callback(n,r,o),Array.isArray(n.children))for(let e=0;e<n.children.length;e++){let s=n.children[e];this.visit(s,n,e)}}},p=Symbol("HTMLString"),_=Symbol("AttrString"),m=Symbol("RenderFn");function u(t,n=[p]){let r={value:t};for(let o of n)Object.defineProperty(r,o,{value:!0,enumerable:!1,writable:!1});return r}function X(t){return u(t)}function P(t,n){return Object.defineProperty(t,m,{value:n,enumerable:!1}),t}var w={"&":"&","<":"<",">":">"};function x(t){return t.replace(/[&<>]/g,n=>w[n]||n)}function h(t){let n="";for(let[r,o]of Object.entries(t))n+=` ${r}="${o}"`;return u(n,[p,_])}function j(t,...n){let r="";for(let o=0;o<t.length;o++){r+=t[o];let e=n[o];r.endsWith("...")&&e&&typeof e=="object"?(r=r.slice(0,-3).trimEnd(),r+=h(e).value):e&&e[_]?(r=r.trimEnd(),r+=e.value):e&&e[p]?r+=e.value:typeof e=="string"?r+=x(e):(e||e===0)&&(r+=String(e))}return u(r)}function V(t,n){return new y(n).visit(t)}function F(t,n){return new g(n).visit(t)}async function C(t){let{name:n,attributes:r={}}=t,o=await Promise.all(t.children.map(e=>T(e))).then(e=>e.join(""));if(m in t){let e=await t[m](r,u(o));return e&&e[p]?e.value:x(String(e))}return n===b?o:v.has(n)?`<${t.name}${h(r).value}>`:`<${t.name}${h(r).value}>${o}</${t.name}>`}async function T(t){switch(t.type){case 0:return Promise.all(t.children.map(n=>T(n))).then(n=>n.join(""));case 1:return C(t);case 2:return`${t.value}`;case 3:return`<!--${t.value}-->`;case 4:return`<!${t.value}>`}}async function H(t,n=[]){if(!Array.isArray(n))throw new Error(`Invalid second argument for \`transform\`! Expected \`Transformer[]\` but got \`${typeof n}\``);let o=typeof t=="string"?M(t):t;for(let e of n)o=await e(o);return T(o)}export{R as COMMENT_NODE,k as DOCTYPE_NODE,I as DOCUMENT_NODE,L as ELEMENT_NODE,b as Fragment,m as RenderFn,A as TEXT_NODE,X as __unsafeHTML,P as __unsafeRenderFn,h as attrs,$ as h,j as html,M as parse,T as render,H as transform,V as walk,F as walkSync}; | ||
var A=0,L=1,R=2,k=3,$=4;function X(t,n={},...o){let r={type:1,name:typeof t=="function"?t.name:t,attributes:n||{},children:o.map(e=>typeof e=="string"?{type:2,value:x(String(e))}:e),parent:void 0,loc:[]};return typeof t=="function"&&w(r,t),r}var b=Symbol("Fragment"),v=new Set(["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"]),S=new Set(["script","style"]),D=/([\@\.a-z0-9_\:\-]*)\s*?=?\s*?(['"]?)(.*?)\2\s+/gim,i=/(?:<(\/?)([a-zA-Z][a-zA-Z0-9\:-]*)(?:\s([^>]*?))?((?:\s*\/)?)>|(<\!\-\-)([\s\S]*?)(\-\->)|(<\!)([\s\S]*?)(>))/gm;function M(t){let n={},o;if(t)for(D.lastIndex=0,t=" "+(t||"")+" ";o=D.exec(t);)o[0]!==" "&&(n[o[1]]=o[3]);return n}function P(t){let n=typeof t=="string"?t:t.value,o,r,e,s,l,d,f,N,a,c=[];i.lastIndex=0,r=o={type:0,children:[]};let E=0;function O(){s=n.substring(E,i.lastIndex-e[0].length),s&&r.children.push({type:2,value:s,parent:r})}for(;e=i.exec(n);){if(d=e[5]||e[8],f=e[6]||e[9],N=e[7]||e[10],S.has(r.name)&&e[2]!==r.name){l=i.lastIndex-e[0].length,r.children.length>0&&(r.children[0].value+=e[0]);continue}else d==="<!--"?(l=i.lastIndex-e[0].length,a={type:3,value:f,parent:r,loc:[{start:l,end:l+d.length},{start:i.lastIndex-N.length,end:i.lastIndex}]},c.push(a),a.parent.children.push(a)):d==="<!"?(l=i.lastIndex-e[0].length,a={type:4,value:f,parent:r,loc:[{start:l,end:l+d.length},{start:i.lastIndex-N.length,end:i.lastIndex}]},c.push(a),a.parent.children.push(a)):e[1]!=="/"?(O(),a={type:1,name:e[2]+"",attributes:M(e[3]),parent:r,children:[],loc:[{start:i.lastIndex-e[0].length,end:i.lastIndex}]},c.push(a),a.parent.children.push(a),e[4]&&e[4].indexOf("/")>-1||v.has(a.name)?(a.loc[1]=a.loc[0],a.isSelfClosingTag=!0):r=a):(O(),e[2]+""===r.name?(a=r,r=a.parent,a.loc.push({start:i.lastIndex-e[0].length,end:i.lastIndex}),s=n.substring(a.loc[0].end,a.loc[1].start),a.children.length===0&&a.children.push({type:2,value:s,parent:r})):e[2]+""===c[c.length-1].name&&c[c.length-1].isSelfClosingTag===!0&&(a=c[c.length-1],a.loc.push({start:i.lastIndex-e[0].length,end:i.lastIndex})));E=i.lastIndex}return s=n.slice(E),r.children.push({type:2,value:s,parent:r}),o}var y=class{constructor(n){this.callback=n}async visit(n,o,r){if(await this.callback(n,o,r),Array.isArray(n.children)){let e=[];for(let s=0;s<n.children.length;s++){let l=n.children[s];e.push(this.visit(l,n,s))}await Promise.all(e)}}},g=class{constructor(n){this.callback=n}visit(n,o,r){if(this.callback(n,o,r),Array.isArray(n.children))for(let e=0;e<n.children.length;e++){let s=n.children[e];this.visit(s,n,e)}}},p=Symbol("HTMLString"),_=Symbol("AttrString"),h=Symbol("RenderFn");function u(t,n=[p]){let o={value:t};for(let r of n)Object.defineProperty(o,r,{value:!0,enumerable:!1,writable:!1});return o}function j(t){return u(t)}function w(t,n){return Object.defineProperty(t,h,{value:n,enumerable:!1}),t}var C={"&":"&","<":"<",">":">"};function x(t){return t.replace(/[&<>]/g,n=>C[n]||n)}function m(t){let n="";for(let[o,r]of Object.entries(t))n+=` ${o}="${r}"`;return u(n,[p,_])}function V(t,...n){let o="";for(let r=0;r<t.length;r++){o+=t[r];let e=n[r];o.endsWith("...")&&e&&typeof e=="object"?(o=o.slice(0,-3).trimEnd(),o+=m(e).value):e&&e[_]?(o=o.trimEnd(),o+=e.value):e&&e[p]?o+=e.value:typeof e=="string"?o+=x(e):(e||e===0)&&(o+=String(e))}return u(o)}function F(t,n){return new y(n).visit(t)}function H(t,n){return new g(n).visit(t)}async function I(t){let{name:n,attributes:o={}}=t,r=await Promise.all(t.children.map(e=>T(e))).then(e=>e.join(""));if(h in t){let e=await t[h](o,u(r));return e&&e[p]?e.value:x(String(e))}return n===b?r:v.has(n)?`<${t.name}${m(o).value}>`:`<${t.name}${m(o).value}>${r}</${t.name}>`}async function T(t){switch(t.type){case 0:return Promise.all(t.children.map(n=>T(n))).then(n=>n.join(""));case 1:return I(t);case 2:return`${t.value}`;case 3:return`<!--${t.value}-->`;case 4:return`<!${t.value}>`}}async function U(t,n=[]){if(!Array.isArray(n))throw new Error(`Invalid second argument for \`transform\`! Expected \`Transformer[]\` but got \`${typeof n}\``);let r=typeof t=="string"?P(t):t;for(let e of n)r=await e(r);return T(r)}export{k as COMMENT_NODE,$ as DOCTYPE_NODE,A as DOCUMENT_NODE,L as ELEMENT_NODE,b as Fragment,h as RenderFn,R as TEXT_NODE,j as __unsafeHTML,w as __unsafeRenderFn,m as attrs,X as h,V as html,P as parse,T as render,U as transform,F as walk,H as walkSync}; |
@@ -1,1 +0,1 @@ | ||
import{ELEMENT_NODE as c,walkSync as d}from"../index.js";function a(t){var n;if(t===void 0)return{allowElements:[],dropElements:["script"],allowComponents:!1,allowCustomElements:!1,allowComments:!1};{let e=new Set([]);(n=t.allowElements)!=null&&n.includes("script")||e.add("script");for(let o of t.dropElements??[])e.add(o);return{allowComponents:!1,allowCustomElements:!1,allowComments:!1,...t,dropElements:Array.from(e)}}}function f(t){return t.name.includes("-")?"custom-element":/[\_\$A-Z]/.test(t.name[0])||t.name.includes(".")?"component":"element"}function p(t,n,e){var o,l,r;return((o=e.allowElements)==null?void 0:o.length)>0&&e.allowElements.includes(t)?"allow":((l=e.blockElements)==null?void 0:l.length)>0&&e.blockElements.includes(t)?"block":((r=e.dropElements)==null?void 0:r.length)>0&&e.dropElements.find(s=>s===t)||n==="component"&&!e.allowComponents||n==="custom-element"&&!e.allowCustomElements?"drop":"allow"}function E(t,n){var o,l,r,s,u,m;let e=t.attributes;for(let i of Object.keys(t.attributes))((o=n.allowAttributes)==null?void 0:o[i])&&((l=n.allowAttributes)==null?void 0:l[i].includes(t.name))||((r=n.allowAttributes)==null?void 0:r[i].includes("*"))||(((s=n.dropAttributes)==null?void 0:s[i])&&((u=n.dropAttributes)==null?void 0:u[i].includes(t.name))||((m=n.dropAttributes)==null?void 0:m[i].includes("*")))&&delete e[i];return e}function w(t,n,e){let o=f(n),{name:l}=n,r=p(l,o,t);return r==="drop"?()=>{e.children=e.children.filter(s=>s!==n)}:r==="block"?()=>{e.children=e.children.map(s=>s===n?s.children:s).flat(1)}:()=>{n.attributes=E(n,t)}}function b(t){let n=a(t);return e=>{let o=[];d(e,(l,r)=>{switch(l.type){case c:{o.push(w(n,l,r));return}default:return}});for(let l of o)l();return e}}export{b as default}; | ||
import{ELEMENT_NODE as a,walkSync as f}from"../index.js";function p(t){var n;if(t===void 0)return{allowElements:[],dropElements:["script"],allowComponents:!1,allowCustomElements:!1,allowComments:!1};{let e=new Set([]);(n=t.allowElements)!=null&&n.includes("script")||e.add("script");for(let o of t.dropElements??[])e.add(o);return{allowComponents:!1,allowCustomElements:!1,allowComments:!1,...t,dropElements:Array.from(e)}}}function E(t){return t.name.includes("-")?"custom-element":/[\_\$A-Z]/.test(t.name[0])||t.name.includes(".")?"component":"element"}function w(t,n,e){var o,l,r;return((o=e.allowElements)==null?void 0:o.length)>0&&e.allowElements.includes(t)?"allow":((l=e.blockElements)==null?void 0:l.length)>0&&e.blockElements.includes(t)?"block":((r=e.dropElements)==null?void 0:r.length)>0&&e.dropElements.find(s=>s===t)||n==="component"&&!e.allowComponents||n==="custom-element"&&!e.allowCustomElements?"drop":"allow"}function b(t,n){var o,l,r,s,u,m,c,d;let e=t.attributes;for(let i of Object.keys(t.attributes))((o=n.allowAttributes)==null?void 0:o[i])&&((l=n.allowAttributes)==null?void 0:l[i].includes(t.name))||((s=(r=n.allowAttributes)==null?void 0:r[i])==null?void 0:s.includes("*"))||(((u=n.dropAttributes)==null?void 0:u[i])&&((m=n.dropAttributes)==null?void 0:m[i].includes(t.name))||((d=(c=n.dropAttributes)==null?void 0:c[i])==null?void 0:d.includes("*")))&&delete e[i];return e}function g(t,n,e){let o=E(n),{name:l}=n,r=w(l,o,t);return r==="drop"?()=>{e.children=e.children.filter(s=>s!==n)}:r==="block"?()=>{e.children=e.children.map(s=>s===n?s.children:s).flat(1)}:()=>{n.attributes=b(n,t)}}function N(t){let n=p(t);return e=>{let o=[];f(e,(l,r)=>{switch(l.type){case a:{o.push(g(n,l,r));return}default:return}});for(let l of o)l();return e}}export{N as default}; |
{ | ||
"name": "ultrahtml", | ||
"type": "module", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"types": "./dist/index.d.ts", | ||
@@ -6,0 +6,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
183678
267