@takumi-rs/helpers 2.13.6 → 2.14.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/README.md +4 -4
- package/dist/html.cjs +1 -1
- package/dist/html.mjs +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @takumi-rs/helpers
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Convert JSX and HTML into Takumi node trees and prepare fonts, images, and emoji.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Use these helpers when working with the native or WebAssembly bindings directly. With `takumi-js`, import them from `takumi-js/helpers` and its subpaths.
|
|
6
6
|
|
|
7
7
|
[Documentation](https://takumi.kane.tw/docs/helpers#parsing-templates) · [GitHub](https://github.com/kane50613/takumi)
|
|
8
8
|
|
|
@@ -16,7 +16,7 @@ npm install @takumi-rs/helpers
|
|
|
16
16
|
|
|
17
17
|
### JSX to Node Tree
|
|
18
18
|
|
|
19
|
-
Convert React-like elements into a serializable node tree
|
|
19
|
+
Convert React-like elements into a serializable node tree and its CSS.
|
|
20
20
|
|
|
21
21
|
```tsx
|
|
22
22
|
import { fromJsx } from "@takumi-rs/helpers/jsx";
|
|
@@ -36,7 +36,7 @@ const { node, css } = await fromHtml("<div style='color: red'>Hello</div>");
|
|
|
36
36
|
|
|
37
37
|
### Emoji Processing
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
Replace emoji in text nodes with image nodes from the selected provider.
|
|
40
40
|
|
|
41
41
|
```ts
|
|
42
42
|
import { extractEmojis } from "@takumi-rs/helpers/emoji";
|
package/dist/html.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./helpers-4kGcvc-Q.cjs"),t=require("./utils-BndQkSnW.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}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}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={"&":`&`,"<":`<`,">":`>`};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):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:[],css:[]},a=t.f(n?.defaultStyles),o=n?.tailwindClassesProperty??`tw`;for(let e of r.children)j(e,a,o,i.nodes,i.css);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.d(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(n){let{nodes:r,css:i}=A(n);for(;r[0]&&z(r[0]);)r.shift();for(;r.at(-1)&&z(r.at(-1));)r.pop();let a;a=r.length===0?e.t({}):r.length===1&&r[0]?r[0]:e.t({style:{display:`block`,width:e.a(100),height:e.a(100)},children:r});let o={node:a,css:i,get stylesheets(){return t.u(),i}};return t.l(o),o}exports.fromHtml=B;
|
|
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:O(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.d(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(n){let{nodes:r,css:i}=A(n);for(;r[0]&&z(r[0]);)r.shift();for(;r.at(-1)&&z(r.at(-1));)r.pop();let a;a=r.length===0?e.t({}):r.length===1&&r[0]?r[0]:e.t({style:{display:`block`,width:e.a(100),height:e.a(100)},children:r});let o={node:a,css:i,get stylesheets(){return t.u(),i}};return t.l(o),o}exports.fromHtml=B;
|
package/dist/html.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{a as e,i as t,l as n,t as r}from"./helpers-CVQCT1Rh.mjs";import{d as i,f as a,i as o,l as s,u as c}from"./utils-4GQubbLq.mjs";var l=Symbol(`Fragment`),u=new Set([`area`,`base`,`br`,`col`,`embed`,`hr`,`img`,`input`,`keygen`,`link`,`meta`,`param`,`source`,`track`,`wbr`]),d=new Set([`script`,`style`]),f=/(?:<(\/?)([a-zA-Z][a-zA-Z0-9\:-]*)(?:\s([^>]*?))?((?:\s*\/)?)>|(<\!\-\-)([\s\S]*?)(\-\->)|(<\!)([\s\S]*?)(>))/gm,p=64,m=46,h=45,g=58,_=95,v=61,y=34,b=39,x=92;function S(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===p||e===m||e===h||e===g||e===_}function C(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`)S(s)?(r&&(t[r]=i,r=void 0,i=``),a=o,n=`key`):s===v&&r&&(n=`value`);else if(n===`key`)S(s)||(r=e.substring(a,o),n=s===v?`value`:`none`);else if(s===y||s===b){let t=s===y?`"`:`'`,r=o+1,a=e.indexOf(t,r);for(;a>0&&e.charCodeAt(a-1)===x;)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 w(e){let t=typeof e==`string`?e:e.value,n,r,i,a,o,s,c,l,p,m=[];f.lastIndex=0,r=n={type:0,children:[]};let h=0;function g(){a=t.substring(h,f.lastIndex-i[0].length),a&&r.children.push({type:2,value:a,parent:r})}for(;i=f.exec(t);){if(s=i[5]||i[8],c=i[6]||i[9],l=i[7]||i[10],d.has(r.name)&&i[2]!==r.name){o=f.lastIndex-i[0].length,r.children.length>0&&(r.children[0].value+=i[0]);continue}if(s===`<!--`){if(o=f.lastIndex-i[0].length,d.has(r.name))continue;p={type:3,value:c,parent:r,loc:[{start:o,end:o+s.length},{start:f.lastIndex-l.length,end:f.lastIndex}]},m.push(p),p.parent.children.push(p)}else if(s===`<!`)o=f.lastIndex-i[0].length,p={type:4,value:c,parent:r,loc:[{start:o,end:o+s.length},{start:f.lastIndex-l.length,end:f.lastIndex}]},m.push(p),p.parent.children.push(p);else if(i[1]!==`/`){if(g(),d.has(r.name)){h=f.lastIndex,g();continue}p={type:1,name:i[2]+``,attributes:C(i[3]),parent:r,children:[],loc:[{start:f.lastIndex-i[0].length,end:f.lastIndex}]},m.push(p),p.parent.children.push(p),i[4]&&i[4].indexOf(`/`)>-1||u.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:f.lastIndex-i[0].length,end:f.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:f.lastIndex-i[0].length,end:f.lastIndex}));h=f.lastIndex}return a=t.slice(h),r.children.push({type:2,value:a,parent:r}),n}var T=Symbol(`HTMLString`),E=Symbol(`RenderFn`);function D(e,t=[T]){let n={value:e};for(let e of t)Object.defineProperty(n,e,{value:!0,enumerable:!1,writable:!1});return n}var O={"&":`&`,"<":`<`,">":`>`};function k(e){return e.replace(/[&<>]/g,e=>O[e]||e)}function A(e){let t=``;for(let[n,r]of Object.entries(e))t+=` ${n}="${r}"`;return t}function j(e){if(e.children.length===0){let t=e;for(;t=t.parent;)if(t.name===`svg`)return!0}return!1}function M(e){let{name:t,attributes:n={}}=e,r=e.children.map(e=>N(e)).join(``);if(E in e){let t=e[E](n,D(r));return t&&t[T]?t.value:k(String(t))}if(t===l)return r;let i=j(e);return i||u.has(t)?`<${e.name}${A(n)}${i?` /`:``}>`:`<${e.name}${A(n)}>${r}</${e.name}>`}function N(e){switch(e.type){case 0:return e.children.map(e=>N(e)).join(``);case 1:return M(e);case 2:return`${e.value}`;case 3:return`<!--${e.value}-->`;case 4:return`<!${e.value}>`}}const P={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 F(e){return e.includes(`&`)?e.replace(/&(?:#(\d+)|#[xX]([\da-fA-F]+)|([a-zA-Z][\w-]+));/g,(e,t,n,r)=>t?I(Number(t))??e:n?I(Number.parseInt(n,16))??e:Object.hasOwn(P,r)?P[r]??e:e):e}function I(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 L(e,t){let n=w(e),r={nodes:[],css:[]},i=a(t?.defaultStyles),o=t?.tailwindClassesProperty??`tw`;for(let e of n.children)R(e,i,o,r.nodes,r.css);return r}function R(e,i,a,s,c){if(e.type===3)return;if(e.type===2){let t=F(e.value??``);t&&s.push(n({text:t,preset:i?.span}));return}if(e.type===0){for(let t of e.children)R(t,i,a,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)R(t,i,a,e,c);return}let u=z(l,i,a);if(l.name===`br`){s.push(n({text:`
|
|
2
|
-
`,preset:i?.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:G(l.attributes?.width),height:G(l.attributes?.height),...u}));return}if(o(l.name))return;if(l.name===`svg`){s.push(t({src:N(l),width:G(l.attributes?.width),height:G(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:F(f),...u}));return}let p=[];for(let e of l.children)R(e,i,a,p,c);s.push(r({children:p,...u}))}function z(e,t,n){let r=e.attributes?B(e.attributes):{},a=typeof r.style==`string`?V(r.style):void 0,o=i(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:a,preset:c}}function B(e){let t={};for(let n in e){let r=e[n];r!==void 0&&(t[n]=F(r))}return t}function V(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[W(a)]=o)};for(let t=0;t<e.length;t+=1){let o=e[t];if(o===`\\`)t+=1;else if(o===`"`||o===`'`)t=H(e,t);else if(o===`/`&&e[t+1]===`*`)t=U(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 H(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 U(e,t){let n=e.indexOf(`*/`,t+2);return n<0?e.length:n+1}function W(e){return e.startsWith(`--`)?e:e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function G(e){if(!e)return;let t=Number(e);return Number.isFinite(t)?t:void 0}const K=e=>`text`in e&&typeof e.text==`string`&&e.text.trim()===``;function q(t){let{nodes:n,css:i}=L(t);for(;n[0]&&K(n[0]);)n.shift();for(;n.at(-1)&&K(n.at(-1));)n.pop();let a;a=n.length===0?r({}):n.length===1&&n[0]?n[0]:r({style:{display:`block`,width:e(100),height:e(100)},children:n});let o={node:a,css:i,get stylesheets(){return c(),i}};return s(o),o}export{q as fromHtml};
|
|
2
|
+
`,preset:i?.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:F(e),width:G(l.attributes?.width),height:G(l.attributes?.height),...u}));return}if(o(l.name))return;if(l.name===`svg`){s.push(t({src:N(l),width:G(l.attributes?.width),height:G(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:F(f),...u}));return}let p=[];for(let e of l.children)R(e,i,a,p,c);s.push(r({children:p,...u}))}function z(e,t,n){let r=e.attributes?B(e.attributes):{},a=typeof r.style==`string`?V(r.style):void 0,o=i(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:a,preset:c}}function B(e){let t={};for(let n in e){let r=e[n];r!==void 0&&(t[n]=F(r))}return t}function V(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[W(a)]=o)};for(let t=0;t<e.length;t+=1){let o=e[t];if(o===`\\`)t+=1;else if(o===`"`||o===`'`)t=H(e,t);else if(o===`/`&&e[t+1]===`*`)t=U(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 H(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 U(e,t){let n=e.indexOf(`*/`,t+2);return n<0?e.length:n+1}function W(e){return e.startsWith(`--`)?e:e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function G(e){if(!e)return;let t=Number(e);return Number.isFinite(t)?t:void 0}const K=e=>`text`in e&&typeof e.text==`string`&&e.text.trim()===``;function q(t){let{nodes:n,css:i}=L(t);for(;n[0]&&K(n[0]);)n.shift();for(;n.at(-1)&&K(n.at(-1));)n.pop();let a;a=n.length===0?r({}):n.length===1&&n[0]?n[0]:r({style:{display:`block`,width:e(100),height:e(100)},children:n});let o={node:a,css:i,get stylesheets(){return c(),i}};return s(o),o}export{q as fromHtml};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takumi-rs/helpers",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.0",
|
|
4
4
|
"description": "Convert JSX and HTML to Takumi node trees. Load fonts and emoji.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"emoji",
|
|
@@ -95,14 +95,14 @@
|
|
|
95
95
|
"publish-lint": "attw --pack . && publint --strict ."
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
|
-
"@types/bun": "^1.4.
|
|
98
|
+
"@types/bun": "^1.4.1",
|
|
99
99
|
"@types/react": "19.2.18",
|
|
100
|
-
"@types/react-dom": "^19.2.
|
|
101
|
-
"lucide-react": "^1.
|
|
100
|
+
"@types/react-dom": "^19.2.7",
|
|
101
|
+
"lucide-react": "^1.45.0",
|
|
102
102
|
"preact": "^10.29.8",
|
|
103
103
|
"react": "^19.2.8",
|
|
104
104
|
"react-dom": "^19.2.8",
|
|
105
|
-
"tsdown": "0.
|
|
105
|
+
"tsdown": "0.23.0",
|
|
106
106
|
"ultrahtml": "^1.7.0",
|
|
107
107
|
"unrun": "^0.3.1"
|
|
108
108
|
},
|