@takumi-rs/helpers 2.10.0 → 2.11.0

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.
package/dist/html.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./helpers-4kGcvc-Q.cjs"),t=require("./utils-Cg2JlrJr.cjs");var n=Symbol(`Fragment`),r=new Set([`area`,`base`,`br`,`col`,`embed`,`hr`,`img`,`input`,`keygen`,`link`,`meta`,`param`,`source`,`track`,`wbr`]),i=new Set([`script`,`style`]),a=/(?:<(\/?)([a-zA-Z][a-zA-Z0-9\:-]*)(?:\s([^>]*?))?((?:\s*\/)?)>|(<\!\-\-)([\s\S]*?)(\-\->)|(<\!)([\s\S]*?)(>))/gm,o=64,s=46,c=45,l=58,u=95,d=61,f=34,p=39,m=92;function h(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===o||e===s||e===c||e===l||e===u}function g(e){let t={};if(e){let n=`none`,r,i=``,a;for(let o=0;o<e.length;o++){let s=e.charCodeAt(o);if(n===`none`)h(s)?(r&&(t[r]=i,r=void 0,i=``),a=o,n=`key`):s===d&&r&&(n=`value`);else if(n===`key`)h(s)||(r=e.substring(a,o),n=s===d?`value`:`none`);else if(s===f||s===p){let t=s===f?`"`:`'`,r=o+1,a=e.indexOf(t,r);for(;a>0&&e.charCodeAt(a-1)===m;)a=e.indexOf(t,a+1);if(a===-1)break;i=e.substring(r,a),o=a,n=`none`}}n===`key`&&a!=null&&a<e.length&&(r=e.substring(a,e.length)),r&&(t[r]=i)}return t}function _(e){let t=typeof e==`string`?e:e.value,n,o,s,c,l,u,d,f,p,m=[];a.lastIndex=0,o=n={type:0,children:[]};let h=0;function _(){c=t.substring(h,a.lastIndex-s[0].length),c&&o.children.push({type:2,value:c,parent:o})}for(;s=a.exec(t);){if(u=s[5]||s[8],d=s[6]||s[9],f=s[7]||s[10],i.has(o.name)&&s[2]!==o.name){l=a.lastIndex-s[0].length,o.children.length>0&&(o.children[0].value+=s[0]);continue}else if(u===`<!--`){if(l=a.lastIndex-s[0].length,i.has(o.name))continue;p={type:3,value:d,parent:o,loc:[{start:l,end:l+u.length},{start:a.lastIndex-f.length,end:a.lastIndex}]},m.push(p),p.parent.children.push(p)}else if(u===`<!`)l=a.lastIndex-s[0].length,p={type:4,value:d,parent:o,loc:[{start:l,end:l+u.length},{start:a.lastIndex-f.length,end:a.lastIndex}]},m.push(p),p.parent.children.push(p);else if(s[1]!==`/`)if(_(),i.has(o.name)){h=a.lastIndex,_();continue}else p={type:1,name:s[2]+``,attributes:g(s[3]),parent:o,children:[],loc:[{start:a.lastIndex-s[0].length,end:a.lastIndex}]},m.push(p),p.parent.children.push(p),s[4]&&s[4].indexOf(`/`)>-1||r.has(p.name)?(p.loc[1]=p.loc[0],p.isSelfClosingTag=!0):o=p;else _(),s[2]+``===o.name?(p=o,o=p.parent,p.loc.push({start:a.lastIndex-s[0].length,end:a.lastIndex}),c=t.substring(p.loc[0].end,p.loc[1].start),p.children.length===0&&p.children.push({type:2,value:c,parent:o})):s[2]+``===m[m.length-1].name&&m[m.length-1].isSelfClosingTag===!0&&(p=m[m.length-1],p.loc.push({start:a.lastIndex-s[0].length,end:a.lastIndex}));h=a.lastIndex}return c=t.slice(h),o.children.push({type:2,value:c,parent:o}),n}var v=Symbol(`HTMLString`),y=Symbol(`RenderFn`);function b(e,t=[v]){let n={value:e};for(let e of t)Object.defineProperty(n,e,{value:!0,enumerable:!1,writable:!1});return n}var x={"&":`&amp;`,"<":`&lt;`,">":`&gt;`};function S(e){return e.replace(/[&<>]/g,e=>x[e]||e)}function C(e){let t=``;for(let[n,r]of Object.entries(e))t+=` ${n}="${r}"`;return t}function w(e){if(e.children.length===0){let t=e;for(;t=t.parent;)if(t.name===`svg`)return!0}return!1}function T(e){let{name:t,attributes:i={}}=e,a=e.children.map(e=>E(e)).join(``);if(y in e){let t=e[y](i,b(a));return t&&t[v]?t.value:S(String(t))}if(t===n)return a;let o=w(e);return o||r.has(t)?`<${e.name}${C(i)}${o?` /`:``}>`:`<${e.name}${C(i)}>${a}</${e.name}>`}function E(e){switch(e.type){case 0:return e.children.map(e=>E(e)).join(``);case 1:return T(e);case 2:return`${e.value}`;case 3:return`<!--${e.value}-->`;case 4:return`<!${e.value}>`}}const D={quot:`"`,amp:`&`,lt:`<`,gt:`>`,apos:`'`,nbsp:`\xA0`,iexcl:`¡`,cent:`¢`,pound:`£`,curren:`¤`,yen:`¥`,brvbar:`¦`,sect:`§`,uml:`¨`,copy:`©`,ordf:`ª`,laquo:`«`,not:`¬`,shy:`­`,reg:`®`,macr:`¯`,deg:`°`,plusmn:`±`,sup2:`²`,sup3:`³`,acute:`´`,micro:`µ`,para:`¶`,middot:`·`,cedil:`¸`,sup1:`¹`,ordm:`º`,raquo:`»`,frac14:`¼`,frac12:`½`,frac34:`¾`,iquest:`¿`,Agrave:`À`,Aacute:`Á`,Acirc:`Â`,Atilde:`Ã`,Auml:`Ä`,Aring:`Å`,AElig:`Æ`,Ccedil:`Ç`,Egrave:`È`,Eacute:`É`,Ecirc:`Ê`,Euml:`Ë`,Igrave:`Ì`,Iacute:`Í`,Icirc:`Î`,Iuml:`Ï`,ETH:`Ð`,Ntilde:`Ñ`,Ograve:`Ò`,Oacute:`Ó`,Ocirc:`Ô`,Otilde:`Õ`,Ouml:`Ö`,times:`×`,Oslash:`Ø`,Ugrave:`Ù`,Uacute:`Ú`,Ucirc:`Û`,Uuml:`Ü`,Yacute:`Ý`,THORN:`Þ`,szlig:`ß`,agrave:`à`,aacute:`á`,acirc:`â`,atilde:`ã`,auml:`ä`,aring:`å`,aelig:`æ`,ccedil:`ç`,egrave:`è`,eacute:`é`,ecirc:`ê`,euml:`ë`,igrave:`ì`,iacute:`í`,icirc:`î`,iuml:`ï`,eth:`ð`,ntilde:`ñ`,ograve:`ò`,oacute:`ó`,ocirc:`ô`,otilde:`õ`,ouml:`ö`,divide:`÷`,oslash:`ø`,ugrave:`ù`,uacute:`ú`,ucirc:`û`,uuml:`ü`,yacute:`ý`,thorn:`þ`,yuml:`ÿ`,fnof:`ƒ`,Alpha:`Α`,Beta:`Β`,Gamma:`Γ`,Delta:`Δ`,Epsilon:`Ε`,Zeta:`Ζ`,Eta:`Η`,Theta:`Θ`,Iota:`Ι`,Kappa:`Κ`,Lambda:`Λ`,Mu:`Μ`,Nu:`Ν`,Xi:`Ξ`,Omicron:`Ο`,Pi:`Π`,Rho:`Ρ`,Sigma:`Σ`,Tau:`Τ`,Upsilon:`Υ`,Phi:`Φ`,Chi:`Χ`,Psi:`Ψ`,Omega:`Ω`,alpha:`α`,beta:`β`,gamma:`γ`,delta:`δ`,epsilon:`ε`,zeta:`ζ`,eta:`η`,theta:`θ`,iota:`ι`,kappa:`κ`,lambda:`λ`,mu:`μ`,nu:`ν`,xi:`ξ`,omicron:`ο`,pi:`π`,rho:`ρ`,sigmaf:`ς`,sigma:`σ`,tau:`τ`,upsilon:`υ`,phi:`φ`,chi:`χ`,psi:`ψ`,omega:`ω`,thetasym:`ϑ`,upsih:`ϒ`,piv:`ϖ`,bull:`•`,hellip:`…`,prime:`′`,Prime:`″`,oline:`‾`,frasl:`⁄`,weierp:`℘`,image:`ℑ`,real:`ℜ`,trade:`™`,alefsym:`ℵ`,larr:`←`,uarr:`↑`,rarr:`→`,darr:`↓`,harr:`↔`,crarr:`↵`,lArr:`⇐`,uArr:`⇑`,rArr:`⇒`,dArr:`⇓`,hArr:`⇔`,forall:`∀`,part:`∂`,exist:`∃`,empty:`∅`,nabla:`∇`,isin:`∈`,notin:`∉`,ni:`∋`,prod:`∏`,sum:`∑`,minus:`−`,lowast:`∗`,radic:`√`,prop:`∝`,infin:`∞`,ang:`∠`,and:`∧`,or:`∨`,cap:`∩`,cup:`∪`,int:`∫`,there4:`∴`,sim:`∼`,cong:`≅`,asymp:`≈`,ne:`≠`,equiv:`≡`,le:`≤`,ge:`≥`,sub:`⊂`,sup:`⊃`,nsub:`⊄`,sube:`⊆`,supe:`⊇`,oplus:`⊕`,otimes:`⊗`,perp:`⊥`,sdot:`⋅`,lceil:`⌈`,rceil:`⌉`,lfloor:`⌊`,rfloor:`⌋`,lang:`⟨`,rang:`⟩`,loz:`◊`,spades:`♠`,clubs:`♣`,hearts:`♥`,diams:`♦`,OElig:`Œ`,oelig:`œ`,Scaron:`Š`,scaron:`š`,Yuml:`Ÿ`,circ:`ˆ`,tilde:`˜`,ensp:` `,emsp:` `,thinsp:` `,zwnj:`‌`,zwj:`‍`,lrm:`‎`,rlm:`‏`,ndash:`–`,mdash:`—`,lsquo:`‘`,rsquo:`’`,sbquo:`‚`,ldquo:`“`,rdquo:`”`,bdquo:`„`,dagger:`†`,Dagger:`‡`,permil:`‰`,lsaquo:`‹`,rsaquo:`›`,euro:`€`};function O(e){return e.includes(`&`)?e.replace(/&(?:#(\d+)|#x([\da-fA-F]+)|([a-zA-Z][\w-]+));/g,(e,t,n,r)=>t?k(Number(t))??e:n?k(Number.parseInt(n,16))??e:Object.hasOwn(D,r)?D[r]:e):e}function k(e){if(!(!Number.isInteger(e)||e<0||e>1114111)&&!(e>=55296&&e<=57343))try{return String.fromCodePoint(e)}catch{return}}function A(e,n){let r=_(e),i={nodes:[],stylesheets:[]},a=t.u(n?.defaultStyles),o=n?.tailwindClassesProperty??`tw`;for(let e of r.children)j(e,a,o,i.nodes,i.stylesheets);return i}function j(n,r,i,a,o){if(n.type===3)return;if(n.type===2){let t=O(n.value??``);t&&a.push(e.l({text:t,preset:r?.span}));return}if(n.type===0){for(let e of n.children)j(e,r,i,a,o);return}if(n.type!==1)return;let s=n;if(s.name===`style`){let e=``;for(let t of s.children)t.type===2&&typeof t.value==`string`&&(e+=t.value);e&&o.push(e);return}if(s.name===`head`){let e=[];for(let t of s.children)j(t,r,i,e,o);return}let c=M(s,r,i);if(s.name===`br`){a.push(e.l({text:`
2
- `,preset:r?.br,...c}));return}if(s.name===`img`){let t=s.attributes?.src;if(!t)throw Error(`Image element must have a 'src' prop.`);a.push(e.i({src:t,width:I(s.attributes?.width),height:I(s.attributes?.height),...c}));return}if(t.i(s.name))return;if(s.name===`svg`){a.push(e.i({src:E(s),width:I(s.attributes?.width),height:I(s.attributes?.height),...c}));return}let l=!0,u=``;for(let e of s.children)if(e.type!==3){if(e.type!==2){l=!1;break}u+=e.value??``}if(l&&u){a.push(e.l({text:O(u),...c}));return}let d=[];for(let e of s.children)j(e,r,i,d,o);a.push(e.t({children:d,...c}))}function M(e,n,r){let i=e.attributes?N(e.attributes):{},a=typeof i.style==`string`?P(i.style):void 0,o=t.l(i,r),s=typeof i[r]==`string`?i[r]:void 0,c=n&&e.name in n?n[e.name]:void 0;return{tagName:e.name,className:i.class,id:i.id,dir:i.dir,lang:i.lang,attributes:o,tw:s,style:a,preset:c}}function N(e){let t={};for(let n in e){let r=e[n];r!==void 0&&(t[n]=O(r))}return t}function P(e){let t={};for(let n of e.split(`;`)){let[e,...r]=n.split(`:`);if(!e||r.length===0)continue;let i=e.trim(),a=r.join(`:`).trim();!i||!a||(t[F(i)]=a)}return Object.keys(t).length>0?t:void 0}function F(e){return e.startsWith(`--`)?e:e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function I(e){if(!e)return;let t=Number(e);return Number.isFinite(t)?t:void 0}const L=e=>`text`in e&&typeof e.text==`string`&&e.text.trim()===``;function R(t){let{nodes:n,stylesheets:r}=A(t);for(;n[0]&&L(n[0]);)n.shift();for(;n.at(-1)&&L(n.at(-1));)n.pop();return n.length===0?{node:e.t({}),stylesheets:r}:n.length===1&&n[0]?{node:n[0],stylesheets:r}:{node:e.t({style:{display:`block`,width:e.a(100),height:e.a(100)},children:n}),stylesheets:r}}exports.fromHtml=R;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./helpers-4kGcvc-Q.cjs"),t=require("./utils-Cg2JlrJr.cjs");var n=Symbol(`Fragment`),r=new Set([`area`,`base`,`br`,`col`,`embed`,`hr`,`img`,`input`,`keygen`,`link`,`meta`,`param`,`source`,`track`,`wbr`]),i=new Set([`script`,`style`]),a=/(?:<(\/?)([a-zA-Z][a-zA-Z0-9\:-]*)(?:\s([^>]*?))?((?:\s*\/)?)>|(<\!\-\-)([\s\S]*?)(\-\->)|(<\!)([\s\S]*?)(>))/gm,o=64,s=46,c=45,l=58,u=95,d=61,f=34,p=39,m=92;function h(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===o||e===s||e===c||e===l||e===u}function g(e){let t={};if(e){let n=`none`,r,i=``,a;for(let o=0;o<e.length;o++){let s=e.charCodeAt(o);if(n===`none`)h(s)?(r&&(t[r]=i,r=void 0,i=``),a=o,n=`key`):s===d&&r&&(n=`value`);else if(n===`key`)h(s)||(r=e.substring(a,o),n=s===d?`value`:`none`);else if(s===f||s===p){let t=s===f?`"`:`'`,r=o+1,a=e.indexOf(t,r);for(;a>0&&e.charCodeAt(a-1)===m;)a=e.indexOf(t,a+1);if(a===-1)break;i=e.substring(r,a),o=a,n=`none`}}n===`key`&&a!=null&&a<e.length&&(r=e.substring(a,e.length)),r&&(t[r]=i)}return t}function _(e){let t=typeof e==`string`?e:e.value,n,o,s,c,l,u,d,f,p,m=[];a.lastIndex=0,o=n={type:0,children:[]};let h=0;function _(){c=t.substring(h,a.lastIndex-s[0].length),c&&o.children.push({type:2,value:c,parent:o})}for(;s=a.exec(t);){if(u=s[5]||s[8],d=s[6]||s[9],f=s[7]||s[10],i.has(o.name)&&s[2]!==o.name){l=a.lastIndex-s[0].length,o.children.length>0&&(o.children[0].value+=s[0]);continue}else if(u===`<!--`){if(l=a.lastIndex-s[0].length,i.has(o.name))continue;p={type:3,value:d,parent:o,loc:[{start:l,end:l+u.length},{start:a.lastIndex-f.length,end:a.lastIndex}]},m.push(p),p.parent.children.push(p)}else if(u===`<!`)l=a.lastIndex-s[0].length,p={type:4,value:d,parent:o,loc:[{start:l,end:l+u.length},{start:a.lastIndex-f.length,end:a.lastIndex}]},m.push(p),p.parent.children.push(p);else if(s[1]!==`/`)if(_(),i.has(o.name)){h=a.lastIndex,_();continue}else p={type:1,name:s[2]+``,attributes:g(s[3]),parent:o,children:[],loc:[{start:a.lastIndex-s[0].length,end:a.lastIndex}]},m.push(p),p.parent.children.push(p),s[4]&&s[4].indexOf(`/`)>-1||r.has(p.name)?(p.loc[1]=p.loc[0],p.isSelfClosingTag=!0):o=p;else _(),s[2]+``===o.name?(p=o,o=p.parent,p.loc.push({start:a.lastIndex-s[0].length,end:a.lastIndex}),c=t.substring(p.loc[0].end,p.loc[1].start),p.children.length===0&&p.children.push({type:2,value:c,parent:o})):s[2]+``===m[m.length-1].name&&m[m.length-1].isSelfClosingTag===!0&&(p=m[m.length-1],p.loc.push({start:a.lastIndex-s[0].length,end:a.lastIndex}));h=a.lastIndex}return c=t.slice(h),o.children.push({type:2,value:c,parent:o}),n}var v=Symbol(`HTMLString`),y=Symbol(`RenderFn`);function b(e,t=[v]){let n={value:e};for(let e of t)Object.defineProperty(n,e,{value:!0,enumerable:!1,writable:!1});return n}var x={"&":`&amp;`,"<":`&lt;`,">":`&gt;`};function S(e){return e.replace(/[&<>]/g,e=>x[e]||e)}function C(e){let t=``;for(let[n,r]of Object.entries(e))t+=` ${n}="${r}"`;return t}function w(e){if(e.children.length===0){let t=e;for(;t=t.parent;)if(t.name===`svg`)return!0}return!1}function T(e){let{name:t,attributes:i={}}=e,a=e.children.map(e=>E(e)).join(``);if(y in e){let t=e[y](i,b(a));return t&&t[v]?t.value:S(String(t))}if(t===n)return a;let o=w(e);return o||r.has(t)?`<${e.name}${C(i)}${o?` /`:``}>`:`<${e.name}${C(i)}>${a}</${e.name}>`}function E(e){switch(e.type){case 0:return e.children.map(e=>E(e)).join(``);case 1:return T(e);case 2:return`${e.value}`;case 3:return`<!--${e.value}-->`;case 4:return`<!${e.value}>`}}const D={quot:`"`,amp:`&`,lt:`<`,gt:`>`,apos:`'`,nbsp:`\xA0`,iexcl:`¡`,cent:`¢`,pound:`£`,curren:`¤`,yen:`¥`,brvbar:`¦`,sect:`§`,uml:`¨`,copy:`©`,ordf:`ª`,laquo:`«`,not:`¬`,shy:`­`,reg:`®`,macr:`¯`,deg:`°`,plusmn:`±`,sup2:`²`,sup3:`³`,acute:`´`,micro:`µ`,para:`¶`,middot:`·`,cedil:`¸`,sup1:`¹`,ordm:`º`,raquo:`»`,frac14:`¼`,frac12:`½`,frac34:`¾`,iquest:`¿`,Agrave:`À`,Aacute:`Á`,Acirc:`Â`,Atilde:`Ã`,Auml:`Ä`,Aring:`Å`,AElig:`Æ`,Ccedil:`Ç`,Egrave:`È`,Eacute:`É`,Ecirc:`Ê`,Euml:`Ë`,Igrave:`Ì`,Iacute:`Í`,Icirc:`Î`,Iuml:`Ï`,ETH:`Ð`,Ntilde:`Ñ`,Ograve:`Ò`,Oacute:`Ó`,Ocirc:`Ô`,Otilde:`Õ`,Ouml:`Ö`,times:`×`,Oslash:`Ø`,Ugrave:`Ù`,Uacute:`Ú`,Ucirc:`Û`,Uuml:`Ü`,Yacute:`Ý`,THORN:`Þ`,szlig:`ß`,agrave:`à`,aacute:`á`,acirc:`â`,atilde:`ã`,auml:`ä`,aring:`å`,aelig:`æ`,ccedil:`ç`,egrave:`è`,eacute:`é`,ecirc:`ê`,euml:`ë`,igrave:`ì`,iacute:`í`,icirc:`î`,iuml:`ï`,eth:`ð`,ntilde:`ñ`,ograve:`ò`,oacute:`ó`,ocirc:`ô`,otilde:`õ`,ouml:`ö`,divide:`÷`,oslash:`ø`,ugrave:`ù`,uacute:`ú`,ucirc:`û`,uuml:`ü`,yacute:`ý`,thorn:`þ`,yuml:`ÿ`,fnof:`ƒ`,Alpha:`Α`,Beta:`Β`,Gamma:`Γ`,Delta:`Δ`,Epsilon:`Ε`,Zeta:`Ζ`,Eta:`Η`,Theta:`Θ`,Iota:`Ι`,Kappa:`Κ`,Lambda:`Λ`,Mu:`Μ`,Nu:`Ν`,Xi:`Ξ`,Omicron:`Ο`,Pi:`Π`,Rho:`Ρ`,Sigma:`Σ`,Tau:`Τ`,Upsilon:`Υ`,Phi:`Φ`,Chi:`Χ`,Psi:`Ψ`,Omega:`Ω`,alpha:`α`,beta:`β`,gamma:`γ`,delta:`δ`,epsilon:`ε`,zeta:`ζ`,eta:`η`,theta:`θ`,iota:`ι`,kappa:`κ`,lambda:`λ`,mu:`μ`,nu:`ν`,xi:`ξ`,omicron:`ο`,pi:`π`,rho:`ρ`,sigmaf:`ς`,sigma:`σ`,tau:`τ`,upsilon:`υ`,phi:`φ`,chi:`χ`,psi:`ψ`,omega:`ω`,thetasym:`ϑ`,upsih:`ϒ`,piv:`ϖ`,bull:`•`,hellip:`…`,prime:`′`,Prime:`″`,oline:`‾`,frasl:`⁄`,weierp:`℘`,image:`ℑ`,real:`ℜ`,trade:`™`,alefsym:`ℵ`,larr:`←`,uarr:`↑`,rarr:`→`,darr:`↓`,harr:`↔`,crarr:`↵`,lArr:`⇐`,uArr:`⇑`,rArr:`⇒`,dArr:`⇓`,hArr:`⇔`,forall:`∀`,part:`∂`,exist:`∃`,empty:`∅`,nabla:`∇`,isin:`∈`,notin:`∉`,ni:`∋`,prod:`∏`,sum:`∑`,minus:`−`,lowast:`∗`,radic:`√`,prop:`∝`,infin:`∞`,ang:`∠`,and:`∧`,or:`∨`,cap:`∩`,cup:`∪`,int:`∫`,there4:`∴`,sim:`∼`,cong:`≅`,asymp:`≈`,ne:`≠`,equiv:`≡`,le:`≤`,ge:`≥`,sub:`⊂`,sup:`⊃`,nsub:`⊄`,sube:`⊆`,supe:`⊇`,oplus:`⊕`,otimes:`⊗`,perp:`⊥`,sdot:`⋅`,lceil:`⌈`,rceil:`⌉`,lfloor:`⌊`,rfloor:`⌋`,lang:`⟨`,rang:`⟩`,loz:`◊`,spades:`♠`,clubs:`♣`,hearts:`♥`,diams:`♦`,OElig:`Œ`,oelig:`œ`,Scaron:`Š`,scaron:`š`,Yuml:`Ÿ`,circ:`ˆ`,tilde:`˜`,ensp:` `,emsp:` `,thinsp:` `,zwnj:`‌`,zwj:`‍`,lrm:`‎`,rlm:`‏`,ndash:`–`,mdash:`—`,lsquo:`‘`,rsquo:`’`,sbquo:`‚`,ldquo:`“`,rdquo:`”`,bdquo:`„`,dagger:`†`,Dagger:`‡`,permil:`‰`,lsaquo:`‹`,rsaquo:`›`,euro:`€`};function O(e){return e.includes(`&`)?e.replace(/&(?:#(\d+)|#[xX]([\da-fA-F]+)|([a-zA-Z][\w-]+));/g,(e,t,n,r)=>t?k(Number(t))??e:n?k(Number.parseInt(n,16))??e:Object.hasOwn(D,r)?D[r]:e):e}function k(e){if(!(!Number.isInteger(e)||e<0||e>1114111)&&!(e>=55296&&e<=57343)){if(e===0)return`�`;if(e>=128&&e<=159)return`€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ`[e-128];try{return String.fromCodePoint(e)}catch{return}}}function A(e,n){let r=_(e),i={nodes:[],stylesheets:[]},a=t.u(n?.defaultStyles),o=n?.tailwindClassesProperty??`tw`;for(let e of r.children)j(e,a,o,i.nodes,i.stylesheets);return i}function j(n,r,i,a,o){if(n.type===3)return;if(n.type===2){let t=O(n.value??``);t&&a.push(e.l({text:t,preset:r?.span}));return}if(n.type===0){for(let e of n.children)j(e,r,i,a,o);return}if(n.type!==1)return;let s=n;if(s.name===`style`){let e=``;for(let t of s.children)t.type===2&&typeof t.value==`string`&&(e+=t.value);e&&o.push(e);return}if(s.name===`head`){let e=[];for(let t of s.children)j(t,r,i,e,o);return}let c=M(s,r,i);if(s.name===`br`){a.push(e.l({text:`
2
+ `,preset:r?.br,...c}));return}if(s.name===`img`){let t=s.attributes?.src;if(!t)throw Error(`Image element must have a 'src' prop.`);a.push(e.i({src:t,width:R(s.attributes?.width),height:R(s.attributes?.height),...c}));return}if(t.i(s.name))return;if(s.name===`svg`){a.push(e.i({src:E(s),width:R(s.attributes?.width),height:R(s.attributes?.height),...c}));return}let l=!0,u=``;for(let e of s.children)if(e.type!==3){if(e.type!==2){l=!1;break}u+=e.value??``}if(l&&u){a.push(e.l({text:O(u),...c}));return}let d=[];for(let e of s.children)j(e,r,i,d,o);a.push(e.t({children:d,...c}))}function M(e,n,r){let i=e.attributes?N(e.attributes):{},a=typeof i.style==`string`?P(i.style):void 0,o=t.l(i,r),s=typeof i[r]==`string`?i[r]:void 0,c=n&&e.name in n?n[e.name]:void 0;return{tagName:e.name,className:i.class,id:i.id,dir:i.dir,lang:i.lang,attributes:o,tw:s,style:a,preset:c}}function N(e){let t={};for(let n in e){let r=e[n];r!==void 0&&(t[n]=O(r))}return t}function P(e){let t={},n=0,r=-1,i=0,a=i=>{if(r<0)return;let a=e.slice(n,r).trim(),o=e.slice(r+1,i).trim();a&&o&&(t[L(a)]=o)};for(let t=0;t<e.length;t+=1){let o=e[t];if(o===`\\`)t+=1;else if(o===`"`||o===`'`)t=F(e,t);else if(o===`/`&&e[t+1]===`*`)t=I(e,t);else if(o===`(`)i+=1;else if(o===`)`)i=Math.max(0,i-1);else if(i>0)continue;else o===`:`&&r<0?r=t:o===`;`&&(a(t),n=t+1,r=-1)}return a(e.length),Object.keys(t).length>0?t:void 0}function F(e,t){let n=e[t];for(let r=t+1;r<e.length;r+=1)if(e[r]===`\\`)r+=1;else if(e[r]===n)return r;return e.length}function I(e,t){let n=e.indexOf(`*/`,t+2);return n<0?e.length:n+1}function L(e){return e.startsWith(`--`)?e:e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function R(e){if(!e)return;let t=Number(e);return Number.isFinite(t)?t:void 0}const z=e=>`text`in e&&typeof e.text==`string`&&e.text.trim()===``;function B(t){let{nodes:n,stylesheets:r}=A(t);for(;n[0]&&z(n[0]);)n.shift();for(;n.at(-1)&&z(n.at(-1));)n.pop();return n.length===0?{node:e.t({}),stylesheets:r}:n.length===1&&n[0]?{node:n[0],stylesheets:r}:{node:e.t({style:{display:`block`,width:e.a(100),height:e.a(100)},children:n}),stylesheets:r}}exports.fromHtml=B;
package/dist/html.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{a as e,i as t,l as n,t as r}from"./helpers-CVQCT1Rh.mjs";import{i,l as a,u as o}from"./utils-Bhe8BVxR.mjs";var s=Symbol(`Fragment`),c=new Set([`area`,`base`,`br`,`col`,`embed`,`hr`,`img`,`input`,`keygen`,`link`,`meta`,`param`,`source`,`track`,`wbr`]),l=new Set([`script`,`style`]),u=/(?:<(\/?)([a-zA-Z][a-zA-Z0-9\:-]*)(?:\s([^>]*?))?((?:\s*\/)?)>|(<\!\-\-)([\s\S]*?)(\-\->)|(<\!)([\s\S]*?)(>))/gm,d=64,f=46,p=45,m=58,h=95,g=61,_=34,v=39,y=92;function b(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===d||e===f||e===p||e===m||e===h}function x(e){let t={};if(e){let n=`none`,r,i=``,a;for(let o=0;o<e.length;o++){let s=e.charCodeAt(o);if(n===`none`)b(s)?(r&&(t[r]=i,r=void 0,i=``),a=o,n=`key`):s===g&&r&&(n=`value`);else if(n===`key`)b(s)||(r=e.substring(a,o),n=s===g?`value`:`none`);else if(s===_||s===v){let t=s===_?`"`:`'`,r=o+1,a=e.indexOf(t,r);for(;a>0&&e.charCodeAt(a-1)===y;)a=e.indexOf(t,a+1);if(a===-1)break;i=e.substring(r,a),o=a,n=`none`}}n===`key`&&a!=null&&a<e.length&&(r=e.substring(a,e.length)),r&&(t[r]=i)}return t}function S(e){let t=typeof e==`string`?e:e.value,n,r,i,a,o,s,d,f,p,m=[];u.lastIndex=0,r=n={type:0,children:[]};let h=0;function g(){a=t.substring(h,u.lastIndex-i[0].length),a&&r.children.push({type:2,value:a,parent:r})}for(;i=u.exec(t);){if(s=i[5]||i[8],d=i[6]||i[9],f=i[7]||i[10],l.has(r.name)&&i[2]!==r.name){o=u.lastIndex-i[0].length,r.children.length>0&&(r.children[0].value+=i[0]);continue}else if(s===`<!--`){if(o=u.lastIndex-i[0].length,l.has(r.name))continue;p={type:3,value:d,parent:r,loc:[{start:o,end:o+s.length},{start:u.lastIndex-f.length,end:u.lastIndex}]},m.push(p),p.parent.children.push(p)}else if(s===`<!`)o=u.lastIndex-i[0].length,p={type:4,value:d,parent:r,loc:[{start:o,end:o+s.length},{start:u.lastIndex-f.length,end:u.lastIndex}]},m.push(p),p.parent.children.push(p);else if(i[1]!==`/`)if(g(),l.has(r.name)){h=u.lastIndex,g();continue}else p={type:1,name:i[2]+``,attributes:x(i[3]),parent:r,children:[],loc:[{start:u.lastIndex-i[0].length,end:u.lastIndex}]},m.push(p),p.parent.children.push(p),i[4]&&i[4].indexOf(`/`)>-1||c.has(p.name)?(p.loc[1]=p.loc[0],p.isSelfClosingTag=!0):r=p;else g(),i[2]+``===r.name?(p=r,r=p.parent,p.loc.push({start:u.lastIndex-i[0].length,end:u.lastIndex}),a=t.substring(p.loc[0].end,p.loc[1].start),p.children.length===0&&p.children.push({type:2,value:a,parent:r})):i[2]+``===m[m.length-1].name&&m[m.length-1].isSelfClosingTag===!0&&(p=m[m.length-1],p.loc.push({start:u.lastIndex-i[0].length,end:u.lastIndex}));h=u.lastIndex}return a=t.slice(h),r.children.push({type:2,value:a,parent:r}),n}var C=Symbol(`HTMLString`),w=Symbol(`RenderFn`);function T(e,t=[C]){let n={value:e};for(let e of t)Object.defineProperty(n,e,{value:!0,enumerable:!1,writable:!1});return n}var E={"&":`&amp;`,"<":`&lt;`,">":`&gt;`};function D(e){return e.replace(/[&<>]/g,e=>E[e]||e)}function O(e){let t=``;for(let[n,r]of Object.entries(e))t+=` ${n}="${r}"`;return t}function k(e){if(e.children.length===0){let t=e;for(;t=t.parent;)if(t.name===`svg`)return!0}return!1}function A(e){let{name:t,attributes:n={}}=e,r=e.children.map(e=>j(e)).join(``);if(w in e){let t=e[w](n,T(r));return t&&t[C]?t.value:D(String(t))}if(t===s)return r;let i=k(e);return i||c.has(t)?`<${e.name}${O(n)}${i?` /`:``}>`:`<${e.name}${O(n)}>${r}</${e.name}>`}function j(e){switch(e.type){case 0:return e.children.map(e=>j(e)).join(``);case 1:return A(e);case 2:return`${e.value}`;case 3:return`<!--${e.value}-->`;case 4:return`<!${e.value}>`}}const M={quot:`"`,amp:`&`,lt:`<`,gt:`>`,apos:`'`,nbsp:`\xA0`,iexcl:`¡`,cent:`¢`,pound:`£`,curren:`¤`,yen:`¥`,brvbar:`¦`,sect:`§`,uml:`¨`,copy:`©`,ordf:`ª`,laquo:`«`,not:`¬`,shy:`­`,reg:`®`,macr:`¯`,deg:`°`,plusmn:`±`,sup2:`²`,sup3:`³`,acute:`´`,micro:`µ`,para:`¶`,middot:`·`,cedil:`¸`,sup1:`¹`,ordm:`º`,raquo:`»`,frac14:`¼`,frac12:`½`,frac34:`¾`,iquest:`¿`,Agrave:`À`,Aacute:`Á`,Acirc:`Â`,Atilde:`Ã`,Auml:`Ä`,Aring:`Å`,AElig:`Æ`,Ccedil:`Ç`,Egrave:`È`,Eacute:`É`,Ecirc:`Ê`,Euml:`Ë`,Igrave:`Ì`,Iacute:`Í`,Icirc:`Î`,Iuml:`Ï`,ETH:`Ð`,Ntilde:`Ñ`,Ograve:`Ò`,Oacute:`Ó`,Ocirc:`Ô`,Otilde:`Õ`,Ouml:`Ö`,times:`×`,Oslash:`Ø`,Ugrave:`Ù`,Uacute:`Ú`,Ucirc:`Û`,Uuml:`Ü`,Yacute:`Ý`,THORN:`Þ`,szlig:`ß`,agrave:`à`,aacute:`á`,acirc:`â`,atilde:`ã`,auml:`ä`,aring:`å`,aelig:`æ`,ccedil:`ç`,egrave:`è`,eacute:`é`,ecirc:`ê`,euml:`ë`,igrave:`ì`,iacute:`í`,icirc:`î`,iuml:`ï`,eth:`ð`,ntilde:`ñ`,ograve:`ò`,oacute:`ó`,ocirc:`ô`,otilde:`õ`,ouml:`ö`,divide:`÷`,oslash:`ø`,ugrave:`ù`,uacute:`ú`,ucirc:`û`,uuml:`ü`,yacute:`ý`,thorn:`þ`,yuml:`ÿ`,fnof:`ƒ`,Alpha:`Α`,Beta:`Β`,Gamma:`Γ`,Delta:`Δ`,Epsilon:`Ε`,Zeta:`Ζ`,Eta:`Η`,Theta:`Θ`,Iota:`Ι`,Kappa:`Κ`,Lambda:`Λ`,Mu:`Μ`,Nu:`Ν`,Xi:`Ξ`,Omicron:`Ο`,Pi:`Π`,Rho:`Ρ`,Sigma:`Σ`,Tau:`Τ`,Upsilon:`Υ`,Phi:`Φ`,Chi:`Χ`,Psi:`Ψ`,Omega:`Ω`,alpha:`α`,beta:`β`,gamma:`γ`,delta:`δ`,epsilon:`ε`,zeta:`ζ`,eta:`η`,theta:`θ`,iota:`ι`,kappa:`κ`,lambda:`λ`,mu:`μ`,nu:`ν`,xi:`ξ`,omicron:`ο`,pi:`π`,rho:`ρ`,sigmaf:`ς`,sigma:`σ`,tau:`τ`,upsilon:`υ`,phi:`φ`,chi:`χ`,psi:`ψ`,omega:`ω`,thetasym:`ϑ`,upsih:`ϒ`,piv:`ϖ`,bull:`•`,hellip:`…`,prime:`′`,Prime:`″`,oline:`‾`,frasl:`⁄`,weierp:`℘`,image:`ℑ`,real:`ℜ`,trade:`™`,alefsym:`ℵ`,larr:`←`,uarr:`↑`,rarr:`→`,darr:`↓`,harr:`↔`,crarr:`↵`,lArr:`⇐`,uArr:`⇑`,rArr:`⇒`,dArr:`⇓`,hArr:`⇔`,forall:`∀`,part:`∂`,exist:`∃`,empty:`∅`,nabla:`∇`,isin:`∈`,notin:`∉`,ni:`∋`,prod:`∏`,sum:`∑`,minus:`−`,lowast:`∗`,radic:`√`,prop:`∝`,infin:`∞`,ang:`∠`,and:`∧`,or:`∨`,cap:`∩`,cup:`∪`,int:`∫`,there4:`∴`,sim:`∼`,cong:`≅`,asymp:`≈`,ne:`≠`,equiv:`≡`,le:`≤`,ge:`≥`,sub:`⊂`,sup:`⊃`,nsub:`⊄`,sube:`⊆`,supe:`⊇`,oplus:`⊕`,otimes:`⊗`,perp:`⊥`,sdot:`⋅`,lceil:`⌈`,rceil:`⌉`,lfloor:`⌊`,rfloor:`⌋`,lang:`⟨`,rang:`⟩`,loz:`◊`,spades:`♠`,clubs:`♣`,hearts:`♥`,diams:`♦`,OElig:`Œ`,oelig:`œ`,Scaron:`Š`,scaron:`š`,Yuml:`Ÿ`,circ:`ˆ`,tilde:`˜`,ensp:` `,emsp:` `,thinsp:` `,zwnj:`‌`,zwj:`‍`,lrm:`‎`,rlm:`‏`,ndash:`–`,mdash:`—`,lsquo:`‘`,rsquo:`’`,sbquo:`‚`,ldquo:`“`,rdquo:`”`,bdquo:`„`,dagger:`†`,Dagger:`‡`,permil:`‰`,lsaquo:`‹`,rsaquo:`›`,euro:`€`};function N(e){return e.includes(`&`)?e.replace(/&(?:#(\d+)|#x([\da-fA-F]+)|([a-zA-Z][\w-]+));/g,(e,t,n,r)=>t?P(Number(t))??e:n?P(Number.parseInt(n,16))??e:Object.hasOwn(M,r)?M[r]:e):e}function P(e){if(!(!Number.isInteger(e)||e<0||e>1114111)&&!(e>=55296&&e<=57343))try{return String.fromCodePoint(e)}catch{return}}function F(e,t){let n=S(e),r={nodes:[],stylesheets:[]},i=o(t?.defaultStyles),a=t?.tailwindClassesProperty??`tw`;for(let e of n.children)I(e,i,a,r.nodes,r.stylesheets);return r}function I(e,a,o,s,c){if(e.type===3)return;if(e.type===2){let t=N(e.value??``);t&&s.push(n({text:t,preset:a?.span}));return}if(e.type===0){for(let t of e.children)I(t,a,o,s,c);return}if(e.type!==1)return;let l=e;if(l.name===`style`){let e=``;for(let t of l.children)t.type===2&&typeof t.value==`string`&&(e+=t.value);e&&c.push(e);return}if(l.name===`head`){let e=[];for(let t of l.children)I(t,a,o,e,c);return}let u=L(l,a,o);if(l.name===`br`){s.push(n({text:`
2
- `,preset:a?.br,...u}));return}if(l.name===`img`){let e=l.attributes?.src;if(!e)throw Error(`Image element must have a 'src' prop.`);s.push(t({src:e,width:V(l.attributes?.width),height:V(l.attributes?.height),...u}));return}if(i(l.name))return;if(l.name===`svg`){s.push(t({src:j(l),width:V(l.attributes?.width),height:V(l.attributes?.height),...u}));return}let d=!0,f=``;for(let e of l.children)if(e.type!==3){if(e.type!==2){d=!1;break}f+=e.value??``}if(d&&f){s.push(n({text:N(f),...u}));return}let p=[];for(let e of l.children)I(e,a,o,p,c);s.push(r({children:p,...u}))}function L(e,t,n){let r=e.attributes?R(e.attributes):{},i=typeof r.style==`string`?z(r.style):void 0,o=a(r,n),s=typeof r[n]==`string`?r[n]:void 0,c=t&&e.name in t?t[e.name]:void 0;return{tagName:e.name,className:r.class,id:r.id,dir:r.dir,lang:r.lang,attributes:o,tw:s,style:i,preset:c}}function R(e){let t={};for(let n in e){let r=e[n];r!==void 0&&(t[n]=N(r))}return t}function z(e){let t={};for(let n of e.split(`;`)){let[e,...r]=n.split(`:`);if(!e||r.length===0)continue;let i=e.trim(),a=r.join(`:`).trim();!i||!a||(t[B(i)]=a)}return Object.keys(t).length>0?t:void 0}function B(e){return e.startsWith(`--`)?e:e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function V(e){if(!e)return;let t=Number(e);return Number.isFinite(t)?t:void 0}const H=e=>`text`in e&&typeof e.text==`string`&&e.text.trim()===``;function U(t){let{nodes:n,stylesheets:i}=F(t);for(;n[0]&&H(n[0]);)n.shift();for(;n.at(-1)&&H(n.at(-1));)n.pop();return n.length===0?{node:r({}),stylesheets:i}:n.length===1&&n[0]?{node:n[0],stylesheets:i}:{node:r({style:{display:`block`,width:e(100),height:e(100)},children:n}),stylesheets:i}}export{U as fromHtml};
1
+ import{a as e,i as t,l as n,t as r}from"./helpers-CVQCT1Rh.mjs";import{i,l as a,u as o}from"./utils-Bhe8BVxR.mjs";var s=Symbol(`Fragment`),c=new Set([`area`,`base`,`br`,`col`,`embed`,`hr`,`img`,`input`,`keygen`,`link`,`meta`,`param`,`source`,`track`,`wbr`]),l=new Set([`script`,`style`]),u=/(?:<(\/?)([a-zA-Z][a-zA-Z0-9\:-]*)(?:\s([^>]*?))?((?:\s*\/)?)>|(<\!\-\-)([\s\S]*?)(\-\->)|(<\!)([\s\S]*?)(>))/gm,d=64,f=46,p=45,m=58,h=95,g=61,_=34,v=39,y=92;function b(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===d||e===f||e===p||e===m||e===h}function x(e){let t={};if(e){let n=`none`,r,i=``,a;for(let o=0;o<e.length;o++){let s=e.charCodeAt(o);if(n===`none`)b(s)?(r&&(t[r]=i,r=void 0,i=``),a=o,n=`key`):s===g&&r&&(n=`value`);else if(n===`key`)b(s)||(r=e.substring(a,o),n=s===g?`value`:`none`);else if(s===_||s===v){let t=s===_?`"`:`'`,r=o+1,a=e.indexOf(t,r);for(;a>0&&e.charCodeAt(a-1)===y;)a=e.indexOf(t,a+1);if(a===-1)break;i=e.substring(r,a),o=a,n=`none`}}n===`key`&&a!=null&&a<e.length&&(r=e.substring(a,e.length)),r&&(t[r]=i)}return t}function S(e){let t=typeof e==`string`?e:e.value,n,r,i,a,o,s,d,f,p,m=[];u.lastIndex=0,r=n={type:0,children:[]};let h=0;function g(){a=t.substring(h,u.lastIndex-i[0].length),a&&r.children.push({type:2,value:a,parent:r})}for(;i=u.exec(t);){if(s=i[5]||i[8],d=i[6]||i[9],f=i[7]||i[10],l.has(r.name)&&i[2]!==r.name){o=u.lastIndex-i[0].length,r.children.length>0&&(r.children[0].value+=i[0]);continue}else if(s===`<!--`){if(o=u.lastIndex-i[0].length,l.has(r.name))continue;p={type:3,value:d,parent:r,loc:[{start:o,end:o+s.length},{start:u.lastIndex-f.length,end:u.lastIndex}]},m.push(p),p.parent.children.push(p)}else if(s===`<!`)o=u.lastIndex-i[0].length,p={type:4,value:d,parent:r,loc:[{start:o,end:o+s.length},{start:u.lastIndex-f.length,end:u.lastIndex}]},m.push(p),p.parent.children.push(p);else if(i[1]!==`/`)if(g(),l.has(r.name)){h=u.lastIndex,g();continue}else p={type:1,name:i[2]+``,attributes:x(i[3]),parent:r,children:[],loc:[{start:u.lastIndex-i[0].length,end:u.lastIndex}]},m.push(p),p.parent.children.push(p),i[4]&&i[4].indexOf(`/`)>-1||c.has(p.name)?(p.loc[1]=p.loc[0],p.isSelfClosingTag=!0):r=p;else g(),i[2]+``===r.name?(p=r,r=p.parent,p.loc.push({start:u.lastIndex-i[0].length,end:u.lastIndex}),a=t.substring(p.loc[0].end,p.loc[1].start),p.children.length===0&&p.children.push({type:2,value:a,parent:r})):i[2]+``===m[m.length-1].name&&m[m.length-1].isSelfClosingTag===!0&&(p=m[m.length-1],p.loc.push({start:u.lastIndex-i[0].length,end:u.lastIndex}));h=u.lastIndex}return a=t.slice(h),r.children.push({type:2,value:a,parent:r}),n}var C=Symbol(`HTMLString`),w=Symbol(`RenderFn`);function T(e,t=[C]){let n={value:e};for(let e of t)Object.defineProperty(n,e,{value:!0,enumerable:!1,writable:!1});return n}var E={"&":`&amp;`,"<":`&lt;`,">":`&gt;`};function D(e){return e.replace(/[&<>]/g,e=>E[e]||e)}function O(e){let t=``;for(let[n,r]of Object.entries(e))t+=` ${n}="${r}"`;return t}function k(e){if(e.children.length===0){let t=e;for(;t=t.parent;)if(t.name===`svg`)return!0}return!1}function A(e){let{name:t,attributes:n={}}=e,r=e.children.map(e=>j(e)).join(``);if(w in e){let t=e[w](n,T(r));return t&&t[C]?t.value:D(String(t))}if(t===s)return r;let i=k(e);return i||c.has(t)?`<${e.name}${O(n)}${i?` /`:``}>`:`<${e.name}${O(n)}>${r}</${e.name}>`}function j(e){switch(e.type){case 0:return e.children.map(e=>j(e)).join(``);case 1:return A(e);case 2:return`${e.value}`;case 3:return`<!--${e.value}-->`;case 4:return`<!${e.value}>`}}const M={quot:`"`,amp:`&`,lt:`<`,gt:`>`,apos:`'`,nbsp:`\xA0`,iexcl:`¡`,cent:`¢`,pound:`£`,curren:`¤`,yen:`¥`,brvbar:`¦`,sect:`§`,uml:`¨`,copy:`©`,ordf:`ª`,laquo:`«`,not:`¬`,shy:`­`,reg:`®`,macr:`¯`,deg:`°`,plusmn:`±`,sup2:`²`,sup3:`³`,acute:`´`,micro:`µ`,para:`¶`,middot:`·`,cedil:`¸`,sup1:`¹`,ordm:`º`,raquo:`»`,frac14:`¼`,frac12:`½`,frac34:`¾`,iquest:`¿`,Agrave:`À`,Aacute:`Á`,Acirc:`Â`,Atilde:`Ã`,Auml:`Ä`,Aring:`Å`,AElig:`Æ`,Ccedil:`Ç`,Egrave:`È`,Eacute:`É`,Ecirc:`Ê`,Euml:`Ë`,Igrave:`Ì`,Iacute:`Í`,Icirc:`Î`,Iuml:`Ï`,ETH:`Ð`,Ntilde:`Ñ`,Ograve:`Ò`,Oacute:`Ó`,Ocirc:`Ô`,Otilde:`Õ`,Ouml:`Ö`,times:`×`,Oslash:`Ø`,Ugrave:`Ù`,Uacute:`Ú`,Ucirc:`Û`,Uuml:`Ü`,Yacute:`Ý`,THORN:`Þ`,szlig:`ß`,agrave:`à`,aacute:`á`,acirc:`â`,atilde:`ã`,auml:`ä`,aring:`å`,aelig:`æ`,ccedil:`ç`,egrave:`è`,eacute:`é`,ecirc:`ê`,euml:`ë`,igrave:`ì`,iacute:`í`,icirc:`î`,iuml:`ï`,eth:`ð`,ntilde:`ñ`,ograve:`ò`,oacute:`ó`,ocirc:`ô`,otilde:`õ`,ouml:`ö`,divide:`÷`,oslash:`ø`,ugrave:`ù`,uacute:`ú`,ucirc:`û`,uuml:`ü`,yacute:`ý`,thorn:`þ`,yuml:`ÿ`,fnof:`ƒ`,Alpha:`Α`,Beta:`Β`,Gamma:`Γ`,Delta:`Δ`,Epsilon:`Ε`,Zeta:`Ζ`,Eta:`Η`,Theta:`Θ`,Iota:`Ι`,Kappa:`Κ`,Lambda:`Λ`,Mu:`Μ`,Nu:`Ν`,Xi:`Ξ`,Omicron:`Ο`,Pi:`Π`,Rho:`Ρ`,Sigma:`Σ`,Tau:`Τ`,Upsilon:`Υ`,Phi:`Φ`,Chi:`Χ`,Psi:`Ψ`,Omega:`Ω`,alpha:`α`,beta:`β`,gamma:`γ`,delta:`δ`,epsilon:`ε`,zeta:`ζ`,eta:`η`,theta:`θ`,iota:`ι`,kappa:`κ`,lambda:`λ`,mu:`μ`,nu:`ν`,xi:`ξ`,omicron:`ο`,pi:`π`,rho:`ρ`,sigmaf:`ς`,sigma:`σ`,tau:`τ`,upsilon:`υ`,phi:`φ`,chi:`χ`,psi:`ψ`,omega:`ω`,thetasym:`ϑ`,upsih:`ϒ`,piv:`ϖ`,bull:`•`,hellip:`…`,prime:`′`,Prime:`″`,oline:`‾`,frasl:`⁄`,weierp:`℘`,image:`ℑ`,real:`ℜ`,trade:`™`,alefsym:`ℵ`,larr:`←`,uarr:`↑`,rarr:`→`,darr:`↓`,harr:`↔`,crarr:`↵`,lArr:`⇐`,uArr:`⇑`,rArr:`⇒`,dArr:`⇓`,hArr:`⇔`,forall:`∀`,part:`∂`,exist:`∃`,empty:`∅`,nabla:`∇`,isin:`∈`,notin:`∉`,ni:`∋`,prod:`∏`,sum:`∑`,minus:`−`,lowast:`∗`,radic:`√`,prop:`∝`,infin:`∞`,ang:`∠`,and:`∧`,or:`∨`,cap:`∩`,cup:`∪`,int:`∫`,there4:`∴`,sim:`∼`,cong:`≅`,asymp:`≈`,ne:`≠`,equiv:`≡`,le:`≤`,ge:`≥`,sub:`⊂`,sup:`⊃`,nsub:`⊄`,sube:`⊆`,supe:`⊇`,oplus:`⊕`,otimes:`⊗`,perp:`⊥`,sdot:`⋅`,lceil:`⌈`,rceil:`⌉`,lfloor:`⌊`,rfloor:`⌋`,lang:`⟨`,rang:`⟩`,loz:`◊`,spades:`♠`,clubs:`♣`,hearts:`♥`,diams:`♦`,OElig:`Œ`,oelig:`œ`,Scaron:`Š`,scaron:`š`,Yuml:`Ÿ`,circ:`ˆ`,tilde:`˜`,ensp:` `,emsp:` `,thinsp:` `,zwnj:`‌`,zwj:`‍`,lrm:`‎`,rlm:`‏`,ndash:`–`,mdash:`—`,lsquo:`‘`,rsquo:`’`,sbquo:`‚`,ldquo:`“`,rdquo:`”`,bdquo:`„`,dagger:`†`,Dagger:`‡`,permil:`‰`,lsaquo:`‹`,rsaquo:`›`,euro:`€`};function N(e){return e.includes(`&`)?e.replace(/&(?:#(\d+)|#[xX]([\da-fA-F]+)|([a-zA-Z][\w-]+));/g,(e,t,n,r)=>t?P(Number(t))??e:n?P(Number.parseInt(n,16))??e:Object.hasOwn(M,r)?M[r]:e):e}function P(e){if(!(!Number.isInteger(e)||e<0||e>1114111)&&!(e>=55296&&e<=57343)){if(e===0)return`�`;if(e>=128&&e<=159)return`€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ`[e-128];try{return String.fromCodePoint(e)}catch{return}}}function F(e,t){let n=S(e),r={nodes:[],stylesheets:[]},i=o(t?.defaultStyles),a=t?.tailwindClassesProperty??`tw`;for(let e of n.children)I(e,i,a,r.nodes,r.stylesheets);return r}function I(e,a,o,s,c){if(e.type===3)return;if(e.type===2){let t=N(e.value??``);t&&s.push(n({text:t,preset:a?.span}));return}if(e.type===0){for(let t of e.children)I(t,a,o,s,c);return}if(e.type!==1)return;let l=e;if(l.name===`style`){let e=``;for(let t of l.children)t.type===2&&typeof t.value==`string`&&(e+=t.value);e&&c.push(e);return}if(l.name===`head`){let e=[];for(let t of l.children)I(t,a,o,e,c);return}let u=L(l,a,o);if(l.name===`br`){s.push(n({text:`
2
+ `,preset:a?.br,...u}));return}if(l.name===`img`){let e=l.attributes?.src;if(!e)throw Error(`Image element must have a 'src' prop.`);s.push(t({src:e,width:U(l.attributes?.width),height:U(l.attributes?.height),...u}));return}if(i(l.name))return;if(l.name===`svg`){s.push(t({src:j(l),width:U(l.attributes?.width),height:U(l.attributes?.height),...u}));return}let d=!0,f=``;for(let e of l.children)if(e.type!==3){if(e.type!==2){d=!1;break}f+=e.value??``}if(d&&f){s.push(n({text:N(f),...u}));return}let p=[];for(let e of l.children)I(e,a,o,p,c);s.push(r({children:p,...u}))}function L(e,t,n){let r=e.attributes?R(e.attributes):{},i=typeof r.style==`string`?z(r.style):void 0,o=a(r,n),s=typeof r[n]==`string`?r[n]:void 0,c=t&&e.name in t?t[e.name]:void 0;return{tagName:e.name,className:r.class,id:r.id,dir:r.dir,lang:r.lang,attributes:o,tw:s,style:i,preset:c}}function R(e){let t={};for(let n in e){let r=e[n];r!==void 0&&(t[n]=N(r))}return t}function z(e){let t={},n=0,r=-1,i=0,a=i=>{if(r<0)return;let a=e.slice(n,r).trim(),o=e.slice(r+1,i).trim();a&&o&&(t[H(a)]=o)};for(let t=0;t<e.length;t+=1){let o=e[t];if(o===`\\`)t+=1;else if(o===`"`||o===`'`)t=B(e,t);else if(o===`/`&&e[t+1]===`*`)t=V(e,t);else if(o===`(`)i+=1;else if(o===`)`)i=Math.max(0,i-1);else if(i>0)continue;else o===`:`&&r<0?r=t:o===`;`&&(a(t),n=t+1,r=-1)}return a(e.length),Object.keys(t).length>0?t:void 0}function B(e,t){let n=e[t];for(let r=t+1;r<e.length;r+=1)if(e[r]===`\\`)r+=1;else if(e[r]===n)return r;return e.length}function V(e,t){let n=e.indexOf(`*/`,t+2);return n<0?e.length:n+1}function H(e){return e.startsWith(`--`)?e:e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function U(e){if(!e)return;let t=Number(e);return Number.isFinite(t)?t:void 0}const W=e=>`text`in e&&typeof e.text==`string`&&e.text.trim()===``;function G(t){let{nodes:n,stylesheets:i}=F(t);for(;n[0]&&W(n[0]);)n.shift();for(;n.at(-1)&&W(n.at(-1));)n.pop();return n.length===0?{node:r({}),stylesheets:i}:n.length===1&&n[0]?{node:n[0],stylesheets:i}:{node:r({style:{display:`block`,width:e(100),height:e(100)},children:n}),stylesheets:i}}export{G as fromHtml};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takumi-rs/helpers",
3
- "version": "2.10.0",
3
+ "version": "2.11.0",
4
4
  "description": "Convert JSX and HTML to Takumi node trees. Load fonts and emoji.",
5
5
  "keywords": [
6
6
  "emoji",