Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ultrahtml

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ultrahtml - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

6

CHANGELOG.md
# ultrahtml
## 1.1.0
### Minor Changes
- d910619: Remove `resolveAsset` option from `inline` transformer, making it synchronous again.
## 1.0.4

@@ -4,0 +10,0 @@

5

dist/transformers/inline.d.ts

@@ -1,5 +0,4 @@

import { Node, ElementNode } from "../index.js";
import { Node } from "../index.js";
export interface InlineOptions {
resolveAsset: (node: ElementNode) => void | string | Promise<string | void>;
}
export default function inline(opts?: InlineOptions): (doc: Node) => Promise<Node>;
export default function inline(opts?: InlineOptions): (doc: Node) => Node;

4

dist/transformers/inline.js

@@ -1,2 +0,2 @@

import{walkSync as ue,ELEMENT_NODE as le,TEXT_NODE as xe}from"../index.js";import{querySelectorAll as me,specificity as fe}from"../selector.js";var Y="comm",q="rule",B="decl";var G=Math.abs,P=String.fromCharCode;function U(e){return e.trim()}function D(e,t,a){return e.replace(t,a)}function X(e,t){return e.indexOf(t)}function M(e,t){return e.charCodeAt(t)|0}function y(e,t,a){return e.slice(t,a)}function w(e){return e.length}function Z(e){return e.length}function R(e,t){return t.push(e),e}var _=1,S=1,J=0,h=0,i=0,C="";function z(e,t,a,p,u,E,O){return{value:e,root:t,parent:a,type:p,props:u,children:E,line:_,column:S,length:O,return:""}}function Q(){return i}function ee(){return i=h>0?M(C,--h):0,S--,i===10&&(S=1,_--),i}function d(){return i=h<J?M(C,h++):0,S++,i===10&&(S=1,_++),i}function T(){return M(C,h)}function j(){return h}function F(e,t){return y(C,e,t)}function H(e){switch(e){case 0:case 9:case 10:case 13:case 32:return 5;case 33:case 43:case 44:case 47:case 62:case 64:case 126:case 59:case 123:case 125:return 4;case 58:return 3;case 34:case 39:case 40:case 91:return 2;case 41:case 93:return 1}return 0}function re(e){return _=S=1,J=w(C=e),h=0,[]}function te(e){return C="",e}function $(e){return U(F(h-1,K(e===91?e+2:e===40?e+1:e)))}function ne(e){for(;(i=T())&&i<33;)d();return H(e)>2||H(i)>3?"":" "}function oe(e,t){for(;--t&&d()&&!(i<48||i>102||i>57&&i<65||i>70&&i<97););return F(e,j()+(t<6&&T()==32&&d()==32))}function K(e){for(;d();)switch(i){case e:return h;case 34:case 39:e!==34&&e!==39&&K(i);break;case 40:e===41&&K(e);break;case 92:d();break}return h}function ae(e,t){for(;d()&&e+i!==47+10;)if(e+i===42+42&&T()===47)break;return"/*"+F(t,h-1)+"*"+P(e===47?e:d())}function ce(e){for(;!H(T());)d();return F(e,h)}function V(e){return te(W("",null,null,null,[""],e=re(e),0,[0],e))}function W(e,t,a,p,u,E,O,m,k){for(var n=0,f=0,r=O,c=0,s=0,l=0,v=1,I=1,b=1,x=0,N="",L=u,A=E,g=p,o=N;I;)switch(l=x,x=d()){case 40:if(l!=108&&M(o,r-1)==58){X(o+=D($(x),"&","&\f"),"&\f")!=-1&&(b=-1);break}case 34:case 39:case 91:o+=$(x);break;case 9:case 10:case 13:case 32:o+=ne(l);break;case 92:o+=oe(j()-1,7);continue;case 47:switch(T()){case 42:case 47:R(pe(ae(d(),j()),t,a),k);break;default:o+="/"}break;case 123*v:m[n++]=w(o)*b;case 125*v:case 59:case 0:switch(x){case 0:case 125:I=0;case 59+f:s>0&&w(o)-r&&R(s>32?ie(o+";",p,a,r-1):ie(D(o," ","")+";",p,a,r-2),k);break;case 59:o+=";";default:if(R(g=se(o,t,a,n,f,u,m,N,L=[],A=[],r),E),x===123)if(f===0)W(o,t,g,g,L,E,r,m,A);else switch(c){case 100:case 109:case 115:W(e,g,g,p&&R(se(e,g,g,0,0,u,m,N,u,L=[],r),A),u,A,r,m,p?L:A);break;default:W(o,g,g,g,[""],A,0,m,A)}}n=f=s=0,v=b=1,N=o="",r=O;break;case 58:r=1+w(o),s=l;default:if(v<1){if(x==123)--v;else if(x==125&&v++==0&&ee()==125)continue}switch(o+=P(x),x*v){case 38:b=f>0?1:(o+="\f",-1);break;case 44:m[n++]=(w(o)-1)*b,b=1;break;case 64:T()===45&&(o+=$(d())),c=T(),f=r=w(N=o+=ce(j())),x++;break;case 45:l===45&&w(o)==2&&(v=0)}}return E}function se(e,t,a,p,u,E,O,m,k,n,f){for(var r=u-1,c=u===0?E:[""],s=Z(c),l=0,v=0,I=0;l<p;++l)for(var b=0,x=y(e,r+1,r=G(v=O[l])),N=e;b<s;++b)(N=U(v>0?c[b]+" "+x:D(x,/&\f/g,c[b])))&&(k[I++]=N);return z(e,t,a,u===0?q:m,k,n,f)}function pe(e,t,a){return z(e,t,a,Y,P(Q()),y(e,2,-2),0)}function ie(e,t,a,p){return z(e,t,a,B,y(e,0,p),y(e,p+1,-1),p)}function he(e){return async t=>{let a=[],p=[],u=[];ue(t,(n,f)=>{if(n.type===le){if(typeof(e==null?void 0:e.resolveAsset)=="function"&&n.name==="link"&&n.attributes.rel==="stylesheet"){let r=a.push("");u.push(Promise.resolve(e.resolveAsset(n)).then(c=>{c&&(a[r]=c,p.push(()=>{f.children=f.children.filter(s=>s!==n)}))}))}n.name==="style"&&(a.push(n.children.map(r=>r.type===xe?r.value:"").join("")),p.push(()=>{f.children=f.children.filter(r=>r!==n)}))}}),await Promise.all(u);for(let n of p)n();let E=a.join(`
`),O=V(E),m=new Map;for(let n of O)if(n.type==="rule"){let f=Object.fromEntries(n.children.map(r=>[r.props,r.children]));for(let r of n.props){let c=Object.assign(m.get(r)??{},f);m.set(r,c)}}let k=new Map;for(let[n,f]of Array.from(m).sort(([r],[c])=>{let s=fe(r),l=fe(c);return s>l?1:l>s?-1:0})){let r=me(t,n);for(let c of r){let s=k.get(c)??{};k.set(c,Object.assign(s,f))}}for(let[n,f]of k){let r=n.attributes.style??"",c={};for(let s of V(r))s.type==="decl"&&typeof s.props=="string"&&typeof s.children=="string"&&(c[s.props]=s.children);c=Object.assign({},f,c),n.attributes.style=`${Object.entries(c).map(([s,l])=>`${s}:${l.replace("!important","")};`).join("")}`}return t}}export{he as default};
import{walkSync as ue,ELEMENT_NODE as le,TEXT_NODE as xe}from"../index.js";import{querySelectorAll as me,specificity as pe}from"../selector.js";var Y="comm",q="rule",B="decl";var G=Math.abs,j=String.fromCharCode;function P(e){return e.trim()}function D(e,r,c){return e.replace(r,c)}function X(e,r){return e.indexOf(r)}function R(e,r){return e.charCodeAt(r)|0}function M(e,r,c){return e.slice(r,c)}function O(e){return e.length}function Z(e){return e.length}function y(e,r){return r.push(e),e}var _=1,S=1,J=0,h=0,a=0,C="";function z(e,r,c,f,m,E,w){return{value:e,root:r,parent:c,type:f,props:m,children:E,line:_,column:S,length:w,return:""}}function Q(){return a}function ee(){return a=h>0?R(C,--h):0,S--,a===10&&(S=1,_--),a}function d(){return a=h<J?R(C,h++):0,S++,a===10&&(S=1,_++),a}function T(){return R(C,h)}function I(){return h}function F(e,r){return M(C,e,r)}function H(e){switch(e){case 0:case 9:case 10:case 13:case 32:return 5;case 33:case 43:case 44:case 47:case 62:case 64:case 126:case 59:case 123:case 125:return 4;case 58:return 3;case 34:case 39:case 40:case 91:return 2;case 41:case 93:return 1}return 0}function re(e){return _=S=1,J=O(C=e),h=0,[]}function te(e){return C="",e}function $(e){return P(F(h-1,K(e===91?e+2:e===40?e+1:e)))}function ne(e){for(;(a=T())&&a<33;)d();return H(e)>2||H(a)>3?"":" "}function oe(e,r){for(;--r&&d()&&!(a<48||a>102||a>57&&a<65||a>70&&a<97););return F(e,I()+(r<6&&T()==32&&d()==32))}function K(e){for(;d();)switch(a){case e:return h;case 34:case 39:e!==34&&e!==39&&K(a);break;case 40:e===41&&K(e);break;case 92:d();break}return h}function ae(e,r){for(;d()&&e+a!==47+10;)if(e+a===42+42&&T()===47)break;return"/*"+F(r,h-1)+"*"+j(e===47?e:d())}function ce(e){for(;!H(T());)d();return F(e,h)}function V(e){return te(W("",null,null,null,[""],e=re(e),0,[0],e))}function W(e,r,c,f,m,E,w,x,k){for(var n=0,p=0,t=w,i=0,s=0,u=0,v=1,L=1,b=1,l=0,N="",U=m,A=E,g=f,o=N;L;)switch(u=l,l=d()){case 40:if(u!=108&&R(o,t-1)==58){X(o+=D($(l),"&","&\f"),"&\f")!=-1&&(b=-1);break}case 34:case 39:case 91:o+=$(l);break;case 9:case 10:case 13:case 32:o+=ne(u);break;case 92:o+=oe(I()-1,7);continue;case 47:switch(T()){case 42:case 47:y(fe(ae(d(),I()),r,c),k);break;default:o+="/"}break;case 123*v:x[n++]=O(o)*b;case 125*v:case 59:case 0:switch(l){case 0:case 125:L=0;case 59+p:s>0&&O(o)-t&&y(s>32?ie(o+";",f,c,t-1):ie(D(o," ","")+";",f,c,t-2),k);break;case 59:o+=";";default:if(y(g=se(o,r,c,n,p,m,x,N,U=[],A=[],t),E),l===123)if(p===0)W(o,r,g,g,U,E,t,x,A);else switch(i){case 100:case 109:case 115:W(e,g,g,f&&y(se(e,g,g,0,0,m,x,N,m,U=[],t),A),m,A,t,x,f?U:A);break;default:W(o,g,g,g,[""],A,0,x,A)}}n=p=s=0,v=b=1,N=o="",t=w;break;case 58:t=1+O(o),s=u;default:if(v<1){if(l==123)--v;else if(l==125&&v++==0&&ee()==125)continue}switch(o+=j(l),l*v){case 38:b=p>0?1:(o+="\f",-1);break;case 44:x[n++]=(O(o)-1)*b,b=1;break;case 64:T()===45&&(o+=$(d())),i=T(),p=t=O(N=o+=ce(I())),l++;break;case 45:u===45&&O(o)==2&&(v=0)}}return E}function se(e,r,c,f,m,E,w,x,k,n,p){for(var t=m-1,i=m===0?E:[""],s=Z(i),u=0,v=0,L=0;u<f;++u)for(var b=0,l=M(e,t+1,t=G(v=w[u])),N=e;b<s;++b)(N=P(v>0?i[b]+" "+l:D(l,/&\f/g,i[b])))&&(k[L++]=N);return z(e,r,c,m===0?q:x,k,n,p)}function fe(e,r,c){return z(e,r,c,Y,j(Q()),M(e,2,-2),0)}function ie(e,r,c,f){return z(e,r,c,B,M(e,0,f),M(e,f+1,-1),f)}function he(e){return r=>{let c=[],f=[],m=[];ue(r,(n,p)=>{n.type===le&&n.name==="style"&&(c.push(n.children.map(t=>t.type===xe?t.value:"").join("")),f.push(()=>{p.children=p.children.filter(t=>t!==n)}))});for(let n of f)n();let E=c.join(`
`),w=V(E),x=new Map;for(let n of w)if(n.type==="rule"){let p=Object.fromEntries(n.children.map(t=>[t.props,t.children]));for(let t of n.props){let i=Object.assign(x.get(t)??{},p);x.set(t,i)}}let k=new Map;for(let[n,p]of Array.from(x).sort(([t],[i])=>{let s=pe(t),u=pe(i);return s>u?1:u>s?-1:0})){let t=me(r,n);for(let i of t){let s=k.get(i)??{};k.set(i,Object.assign(s,p))}}for(let[n,p]of k){let t=n.attributes.style??"",i={};for(let s of V(t))s.type==="decl"&&typeof s.props=="string"&&typeof s.children=="string"&&(i[s.props]=s.children);i=Object.assign({},p,i),n.attributes.style=`${Object.entries(i).map(([s,u])=>`${s}:${u.replace("!important","")};`).join("")}`}return r}}export{he as default};
{
"name": "ultrahtml",
"type": "module",
"version": "1.0.4",
"version": "1.1.0",
"types": "./dist/index.d.ts",

@@ -6,0 +6,0 @@ "repository": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc