@takumi-rs/helpers 2.0.0-rc.3 → 2.0.0-rc.4

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  **Utility functions and types for working with Takumi node trees.**
4
4
 
5
- This package provides the core logic for converting JSX and HTML into the layout-ready node trees that Takumi's Rust engine expects. It also handles resource fetching (fonts, images) and emoji processing.
5
+ This package provides the core logic for converting JSX and HTML into the layout-ready node trees that Takumi's Rust engine expects. It also loads fonts and processes emoji.
6
6
 
7
7
  [Documentation](https://takumi.kane.tw/docs/architecture#fromjsx-helper) · [GitHub](https://github.com/kane50613/takumi)
8
8
 
@@ -34,17 +34,6 @@ import { fromHtml } from "@takumi-rs/helpers/html";
34
34
  const { node, stylesheets } = await fromHtml("<div style='color: red'>Hello</div>");
35
35
  ```
36
36
 
37
- ### Resource Fetching
38
-
39
- Extract and fetch external resources (images, fonts) mentioned in a node tree.
40
-
41
- ```ts
42
- import { extractResourceUrls, fetchResources } from "@takumi-rs/helpers";
43
-
44
- const urls = extractResourceUrls(node);
45
- const resources = await fetchResources(urls);
46
- ```
47
-
48
37
  ### Emoji Processing
49
38
 
50
39
  Find and replace emoji characters in text nodes with image nodes (Twemoji or custom).
@@ -9706,39 +9706,54 @@ interface GoogleFontCatalog {
9706
9706
  }
9707
9707
  //#endregion
9708
9708
  //#region src/utils.d.ts
9709
- declare function extractResourceUrls(node: Node): string[];
9710
9709
  type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
9711
9710
  type FetchOptions = {
9712
9711
  /** Custom fetch implementation. @default globalThis.fetch */fetch?: FetchLike; /** Abort the request after this many milliseconds. */
9713
- timeout?: number;
9712
+ timeout?: number; /** Caller abort signal, combined with the timeout. */
9713
+ signal?: AbortSignal;
9714
9714
  };
9715
9715
  /** Fetches a URL, applying a timeout signal and throwing on a non-OK status. */
9716
9716
  declare function fetchOk(url: string, options?: FetchOptions & {
9717
9717
  init?: RequestInit;
9718
9718
  }): Promise<Response>;
9719
- type FetchResourcesOptions = FetchOptions & {
9720
- /**
9721
- * Whether to throw on any fetch failure. If false, returns only successful fetches.
9722
- * @default true
9723
- */
9719
+ /**
9720
+ * A cache of image fetches keyed by URL. Sharing one across renders deduplicates concurrent
9721
+ * requests for the same URL (single-flight) and reuses their bytes. Any object with `Map`-like
9722
+ * `get`/`set`/`delete` works, so LRU/TTL policies can be plugged in.
9723
+ */
9724
+ interface ImageFetchCache {
9725
+ get(url: string): Promise<ArrayBuffer> | undefined;
9726
+ set(url: string, data: Promise<ArrayBuffer>): unknown;
9727
+ delete(url: string): unknown;
9728
+ }
9729
+ /** A fetched image entry: its source URL and raw bytes. */
9730
+ interface FetchedImage {
9731
+ src: string;
9732
+ data: ArrayBuffer;
9733
+ }
9734
+ type PrepareImagesOptions<T extends {
9735
+ src: string;
9736
+ } = FetchedImage> = FetchOptions & {
9737
+ /** The node tree(s) whose remote images to fetch. */node: Node | Node[]; /** Pre-fetched entries; their URLs are not re-fetched. */
9738
+ sources?: T[]; /** Single-flight byte cache shared across renders. */
9739
+ fetchCache?: ImageFetchCache; /** Throw on any fetch failure; if `false`, failed URLs are dropped. @default true */
9724
9740
  throwOnError?: boolean;
9725
- /**
9726
- * Cache for fetched resources.
9727
- * Custom features (like LRU, TTL, etc.) can be implemented by providing an extended `Map<string, ArrayBuffer>`.
9728
- */
9729
- cache?: Pick<Map<string, ArrayBuffer>, "has" | "get" | "set">;
9730
9741
  };
9731
9742
  /**
9732
- * Fetches multiple resources concurrently, deduplicating URLs.
9733
- *
9734
- * @param urls - URLs to fetch
9735
- * @param options - Fetch options; `timeout` defaults to 5000ms
9736
- * @returns Array of { src: string, data: ArrayBuffer }
9743
+ * Collects every remote image a node tree references, fetches the ones not already in `sources`,
9744
+ * and returns them as entries ready to hand to a renderer.
9737
9745
  */
9738
- declare function fetchResources(urls: string[], options?: FetchResourcesOptions): Promise<{
9746
+ declare function prepareImages<T extends {
9739
9747
  src: string;
9740
- data: ArrayBuffer;
9741
- }[]>;
9748
+ } = FetchedImage>({
9749
+ node,
9750
+ sources,
9751
+ fetchCache,
9752
+ fetch,
9753
+ timeout,
9754
+ signal,
9755
+ throwOnError
9756
+ }: PrepareImagesOptions<T>): Promise<(T | FetchedImage)[]>;
9742
9757
  //#endregion
9743
9758
  //#region src/fonts.d.ts
9744
9759
  type FontStyle = "normal" | "italic";
@@ -9810,16 +9825,6 @@ declare function fontFromUrl(url: string): {
9810
9825
  key: string;
9811
9826
  data: () => Promise<ArrayBuffer>;
9812
9827
  };
9813
- /** Apply {@link subsetFonts} unless `subset` is `false`. Passes `undefined` fonts through. */
9814
- declare function pickFonts<T>({
9815
- fonts,
9816
- source,
9817
- subset
9818
- }: {
9819
- fonts: T[] | undefined;
9820
- source: string | Node | Node[];
9821
- subset?: boolean;
9822
- }): T[] | undefined;
9823
9828
  /**
9824
9829
  * Load Google Font families in one css2 request, returning every coverage subset. Each keeps
9825
9830
  * its `unicode-range` and registers uniquely-named under its `subsetOf` family, which
@@ -9847,4 +9852,4 @@ declare function rem(rem: number): `${number}rem`;
9847
9852
  declare function fr(fr: number): `${number}fr`;
9848
9853
  declare function rgba(r: number, g: number, b: number, a?: number): `rgb(${number} ${number} ${number} / ${number})`;
9849
9854
  //#endregion
9850
- export { extractResourceUrls as C, FetchResourcesOptions as S, fetchResources as T, googleFonts as _, percentage as a, FetchLike as b, style as c, vw as d, FontSubset as f, fontFromUrl as g, collectCodepoints as h, image as i, text as l, GoogleFontsOptions as m, em as n, rem as o, GoogleFontFamily as p, fr as r, rgba as s, container as t, vh as u, pickFonts as v, fetchOk as w, FetchOptions as x, subsetFonts as y };
9855
+ export { PrepareImagesOptions as C, ImageFetchCache as S, prepareImages as T, googleFonts as _, percentage as a, FetchOptions as b, style as c, vw as d, FontSubset as f, fontFromUrl as g, collectCodepoints as h, image as i, text as l, GoogleFontsOptions as m, em as n, rem as o, GoogleFontFamily as p, fr as r, rgba as s, container as t, vh as u, subsetFonts as v, fetchOk as w, FetchedImage as x, FetchLike as y };
@@ -9706,39 +9706,54 @@ interface GoogleFontCatalog {
9706
9706
  }
9707
9707
  //#endregion
9708
9708
  //#region src/utils.d.ts
9709
- declare function extractResourceUrls(node: Node): string[];
9710
9709
  type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
9711
9710
  type FetchOptions = {
9712
9711
  /** Custom fetch implementation. @default globalThis.fetch */fetch?: FetchLike; /** Abort the request after this many milliseconds. */
9713
- timeout?: number;
9712
+ timeout?: number; /** Caller abort signal, combined with the timeout. */
9713
+ signal?: AbortSignal;
9714
9714
  };
9715
9715
  /** Fetches a URL, applying a timeout signal and throwing on a non-OK status. */
9716
9716
  declare function fetchOk(url: string, options?: FetchOptions & {
9717
9717
  init?: RequestInit;
9718
9718
  }): Promise<Response>;
9719
- type FetchResourcesOptions = FetchOptions & {
9720
- /**
9721
- * Whether to throw on any fetch failure. If false, returns only successful fetches.
9722
- * @default true
9723
- */
9719
+ /**
9720
+ * A cache of image fetches keyed by URL. Sharing one across renders deduplicates concurrent
9721
+ * requests for the same URL (single-flight) and reuses their bytes. Any object with `Map`-like
9722
+ * `get`/`set`/`delete` works, so LRU/TTL policies can be plugged in.
9723
+ */
9724
+ interface ImageFetchCache {
9725
+ get(url: string): Promise<ArrayBuffer> | undefined;
9726
+ set(url: string, data: Promise<ArrayBuffer>): unknown;
9727
+ delete(url: string): unknown;
9728
+ }
9729
+ /** A fetched image entry: its source URL and raw bytes. */
9730
+ interface FetchedImage {
9731
+ src: string;
9732
+ data: ArrayBuffer;
9733
+ }
9734
+ type PrepareImagesOptions<T extends {
9735
+ src: string;
9736
+ } = FetchedImage> = FetchOptions & {
9737
+ /** The node tree(s) whose remote images to fetch. */node: Node | Node[]; /** Pre-fetched entries; their URLs are not re-fetched. */
9738
+ sources?: T[]; /** Single-flight byte cache shared across renders. */
9739
+ fetchCache?: ImageFetchCache; /** Throw on any fetch failure; if `false`, failed URLs are dropped. @default true */
9724
9740
  throwOnError?: boolean;
9725
- /**
9726
- * Cache for fetched resources.
9727
- * Custom features (like LRU, TTL, etc.) can be implemented by providing an extended `Map<string, ArrayBuffer>`.
9728
- */
9729
- cache?: Pick<Map<string, ArrayBuffer>, "has" | "get" | "set">;
9730
9741
  };
9731
9742
  /**
9732
- * Fetches multiple resources concurrently, deduplicating URLs.
9733
- *
9734
- * @param urls - URLs to fetch
9735
- * @param options - Fetch options; `timeout` defaults to 5000ms
9736
- * @returns Array of { src: string, data: ArrayBuffer }
9743
+ * Collects every remote image a node tree references, fetches the ones not already in `sources`,
9744
+ * and returns them as entries ready to hand to a renderer.
9737
9745
  */
9738
- declare function fetchResources(urls: string[], options?: FetchResourcesOptions): Promise<{
9746
+ declare function prepareImages<T extends {
9739
9747
  src: string;
9740
- data: ArrayBuffer;
9741
- }[]>;
9748
+ } = FetchedImage>({
9749
+ node,
9750
+ sources,
9751
+ fetchCache,
9752
+ fetch,
9753
+ timeout,
9754
+ signal,
9755
+ throwOnError
9756
+ }: PrepareImagesOptions<T>): Promise<(T | FetchedImage)[]>;
9742
9757
  //#endregion
9743
9758
  //#region src/fonts.d.ts
9744
9759
  type FontStyle = "normal" | "italic";
@@ -9810,16 +9825,6 @@ declare function fontFromUrl(url: string): {
9810
9825
  key: string;
9811
9826
  data: () => Promise<ArrayBuffer>;
9812
9827
  };
9813
- /** Apply {@link subsetFonts} unless `subset` is `false`. Passes `undefined` fonts through. */
9814
- declare function pickFonts<T>({
9815
- fonts,
9816
- source,
9817
- subset
9818
- }: {
9819
- fonts: T[] | undefined;
9820
- source: string | Node | Node[];
9821
- subset?: boolean;
9822
- }): T[] | undefined;
9823
9828
  /**
9824
9829
  * Load Google Font families in one css2 request, returning every coverage subset. Each keeps
9825
9830
  * its `unicode-range` and registers uniquely-named under its `subsetOf` family, which
@@ -9847,4 +9852,4 @@ declare function rem(rem: number): `${number}rem`;
9847
9852
  declare function fr(fr: number): `${number}fr`;
9848
9853
  declare function rgba(r: number, g: number, b: number, a?: number): `rgb(${number} ${number} ${number} / ${number})`;
9849
9854
  //#endregion
9850
- export { extractResourceUrls as C, FetchResourcesOptions as S, fetchResources as T, googleFonts as _, percentage as a, FetchLike as b, style as c, vw as d, FontSubset as f, fontFromUrl as g, collectCodepoints as h, image as i, text as l, GoogleFontsOptions as m, em as n, rem as o, GoogleFontFamily as p, fr as r, rgba as s, container as t, vh as u, pickFonts as v, fetchOk as w, FetchOptions as x, subsetFonts as y };
9855
+ export { PrepareImagesOptions as C, ImageFetchCache as S, prepareImages as T, googleFonts as _, percentage as a, FetchOptions as b, style as c, vw as d, FontSubset as f, fontFromUrl as g, collectCodepoints as h, image as i, text as l, GoogleFontsOptions as m, em as n, rem as o, GoogleFontFamily as p, fr as r, rgba as s, container as t, vh as u, subsetFonts as v, fetchOk as w, FetchedImage as x, FetchLike as y };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./helpers-4kGcvc-Q.cjs"),t=/url\(\s*(['"]?)(.*?)\1\s*\)/g;function n(e){return e.startsWith(`https://`)||e.startsWith(`http://`)}function r(e,i){if(typeof e==`string`)for(let r of e.matchAll(t)){let e=r[2]?.trim();e&&n(e)&&i.add(e)}else if(Array.isArray(e))for(let t of e)r(t,i)}function i(e){let t=new Set,i=e=>{let a=e=>{e&&(r(e.backgroundImage,t),r(e.maskImage,t))};if(a(e.style),a(e.preset),r(e.tw,t),e.type===`image`){typeof e.src==`string`&&n(e.src)&&t.add(e.src);return}if(e.type===`container`)for(let t of e.children??[])i(t)};return i(e),[...t]}async function a(e,t={}){let n=t.fetch??globalThis.fetch,r=t.timeout===void 0?t.init?.signal:AbortSignal.timeout(t.timeout),i=await n(e,{...t.init,signal:r});if(!i.ok)throw Error(`HTTP ${i.status} ${i.statusText} fetching ${e}`);return i}async function o(e,t){let n=t?.throwOnError??!0,r=t?.timeout??5e3,i=[...new Set(e)].map(async e=>{if(t?.cache?.has(e)){let n=t.cache.get(e);if(n)return{src:e,data:n}}let n=await a(e,{fetch:t?.fetch,timeout:r}).then(e=>e.arrayBuffer());return t?.cache?.set(e,n),{src:e,data:n}});return n?Promise.all(i):(await Promise.allSettled(i)).filter(e=>e.status===`fulfilled`).map(e=>e.value)}function s(e,t,n,r){let i=new Map(r),a=n.includes(`italic`),o=a?n.includes(`normal`)?[0,1]:[1]:[void 0],s=[...a?[`ital`]:[],...i.keys(),`wght`].sort(),c=o.flatMap(e=>t.map(t=>s.map(n=>n===`ital`?String(e):n===`wght`?t:i.get(n)??``).join(`,`))).sort();return`${e}:${s.join(`,`)}@${c.join(`;`)}`}function c(e){let t=new URL(e.baseUrl??`https://fonts.googleapis.com/css2`);for(let n of e.families){if(typeof n==`string`){t.searchParams.append(`family`,s(n,[`400`],[`normal`],[]));continue}let e=n.weight??400,r=(Array.isArray(e)?[...e].sort((e,t)=>e-t):[e]).map(String),i=n.style??`normal`,a=(Array.isArray(i)?i:[i]).map(String),o=Object.entries(n.axes??{}).filter(([e])=>e!==`ital`&&e!==`wght`).map(([e,t])=>[e,String(t)]);t.searchParams.append(`family`,s(n.name,r,a,o))}return e.display&&t.searchParams.set(`display`,e.display),t.toString()}function l(e,t){return a(e,{...t,init:{headers:{"User-Agent":`Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36`}}}).then(e=>e.text())}async function u(e,t){let n=t.cache?.get(e);if(n!==void 0)return n;let r=await l(e,t);return t.cache?.set(e,r),r}const d=/(?:\/\*\s*([^*]+?)\s*\*\/\s*)?@font-face\s*\{([^}]*)\}/g;function f(e,t){let n=`${e.family} ${e.subset}`,r=e.ranges.map(([e,t])=>`${e}-${t}`).join(`,`);return{name:n,subsetOf:e.family,key:`${n}:${e.weight??``}:${e.style??``}:${r}`,weight:e.weight,style:e.style,ranges:e.ranges,data:()=>a(e.url,t).then(e=>e.arrayBuffer())}}function p(e){let t=[];for(let n of e.split(`,`)){let e=n.trim().replace(/^U\+/i,``);if(e)if(e.includes(`-`)){let[n,r]=e.split(`-`);n&&r&&t.push([parseInt(n,16),parseInt(r,16)])}else if(e.includes(`?`))t.push([parseInt(e.replace(/\?/g,`0`),16),parseInt(e.replace(/\?/g,`F`),16)]);else{let n=parseInt(e,16);t.push([n,n])}}return t}function m(e){let t=[],n=0;for(let r of e.matchAll(d)){let e=r[2];if(!e)continue;let i=e.match(/src:\s*url\(([^)]+)\)/)?.[1]?.replace(/['"]/g,``).trim(),a=e.match(/font-family:\s*['"]?([^'";]+)['"]?/)?.[1]?.trim();if(!i||!a)continue;let o=e.match(/unicode-range:\s*([^;]+)/)?.[1],s=e.match(/font-weight:\s*(\d+)(?:\s+(\d+))?/);t.push({family:a,subset:r[1]?.trim()||`subset-${n}`,url:i,weight:s&&!s[2]?Number(s[1]):void 0,style:e.match(/font-style:\s*([a-z]+)/i)?.[1],ranges:o?p(o):[]}),n+=1}return t}function h(e){let t=new Map;for(let n of e){let e=t.get(n.url)??new Set;e.add(n.weight),t.set(n.url,e)}let n=new Set,r=[];for(let i of e){if(n.has(i.url))continue;n.add(i.url);let e=(t.get(i.url)?.size??0)>1;r.push(e?{...i,weight:void 0}:i)}return r}function g(e){let t=new Set,n=e=>{for(let n of e)t.add(n.codePointAt(0))},r=e=>{e.type===`text`?n(e.text):e.type===`container`&&e.children?.forEach(r)};return typeof e==`string`?n(e):Array.isArray(e)?e.forEach(r):r(e),t}function _(e,t){if(e.length===0)return!0;for(let n of t)for(let[t,r]of e)if(n>=t&&n<=r)return!0;return!1}function v({fonts:e,source:t}){let n=g(t);return e.filter(e=>_(e.ranges??[],n))}function y(e){return{key:e,data:()=>a(e).then(e=>e.arrayBuffer())}}function b({fonts:e,source:t,subset:n}){return e&&n!==!1?v({fonts:e,source:t}):e}async function x(e){return e.families.length===0?[]:h(m(await u(c(e),e))).map(t=>f(t,e))}exports.collectCodepoints=g,exports.container=e.t,exports.em=e.n,exports.extractResourceUrls=i,exports.fetchOk=a,exports.fetchResources=o,exports.fontFromUrl=y,exports.fr=e.r,exports.googleFonts=x,exports.image=e.i,exports.percentage=e.a,exports.pickFonts=b,exports.rem=e.o,exports.rgba=e.s,exports.style=e.c,exports.subsetFonts=v,exports.text=e.l,exports.vh=e.u,exports.vw=e.d;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./helpers-4kGcvc-Q.cjs"),t=/url\(\s*(['"]?)(.*?)\1\s*\)/g;async function n(e,t={}){let n=t.fetch??globalThis.fetch,r=t.timeout===void 0?void 0:AbortSignal.timeout(t.timeout),i=[t.signal,t.init?.signal,r].filter(e=>e!==void 0),a=i.length?AbortSignal.any(i):void 0,o=await n(e,{...t.init,signal:a});if(!o.ok)throw Error(`HTTP ${o.status} ${o.statusText} fetching ${e}`);return o}function r(e){return e.startsWith(`https://`)||e.startsWith(`http://`)}function i(e,n){if(typeof e==`string`)for(let i of e.matchAll(t)){let e=i[2]?.trim();e&&r(e)&&n.add(e)}else if(Array.isArray(e))for(let t of e)i(t,n)}function a(e){let t=new Set,n=e=>{let a=e=>{e&&(i(e.backgroundImage,t),i(e.maskImage,t))};if(a(e.style),a(e.preset),i(e.tw,t),e.type===`image`){typeof e.src==`string`&&r(e.src)&&t.add(e.src);return}if(e.type===`container`)for(let t of e.children??[])n(t)};return n(e),[...t]}function o(e,t,r){let i=r?.get(e);if(i)return i;let a=n(e,t).then(e=>e.arrayBuffer()).catch(t=>{throw r?.delete(e),t});return r?.set(e,a),a}async function s({node:e,sources:t=[],fetchCache:n,fetch:r,timeout:i=5e3,signal:s,throwOnError:c=!0}){let l=Array.isArray(e)?e:[e],u=new Map;for(let e of t)u.set(e.src,e);let d=[...new Set(l.flatMap(a))].filter(e=>!u.has(e)),f={fetch:r,timeout:i,signal:s},p=d.map(async e=>({src:e,data:await o(e,f,n)})),m=c?await Promise.all(p):(await Promise.allSettled(p)).filter(e=>e.status===`fulfilled`).map(e=>e.value);return[...u.values(),...m]}function c(e,t,n,r){let i=new Map(r),a=n.includes(`italic`),o=a?n.includes(`normal`)?[0,1]:[1]:[void 0],s=[...a?[`ital`]:[],...i.keys(),`wght`].sort(),c=o.flatMap(e=>t.map(t=>s.map(n=>n===`ital`?String(e):n===`wght`?t:i.get(n)??``).join(`,`))).sort();return`${e}:${s.join(`,`)}@${c.join(`;`)}`}function l(e){let t=new URL(e.baseUrl??`https://fonts.googleapis.com/css2`);for(let n of e.families){if(typeof n==`string`){t.searchParams.append(`family`,c(n,[`400`],[`normal`],[]));continue}let e=n.weight??400,r=(Array.isArray(e)?[...e].sort((e,t)=>e-t):[e]).map(String),i=n.style??`normal`,a=(Array.isArray(i)?i:[i]).map(String),o=Object.entries(n.axes??{}).filter(([e])=>e!==`ital`&&e!==`wght`).map(([e,t])=>[e,String(t)]);t.searchParams.append(`family`,c(n.name,r,a,o))}return e.display&&t.searchParams.set(`display`,e.display),t.toString()}function u(e,t){return n(e,{...t,init:{headers:{"User-Agent":`Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36`}}}).then(e=>e.text())}async function d(e,t){let n=t.cache?.get(e);if(n!==void 0)return n;let r=await u(e,t);return t.cache?.set(e,r),r}const f=/(?:\/\*\s*([^*]+?)\s*\*\/\s*)?@font-face\s*\{([^}]*)\}/g;function p(e,t){let r=`${e.family} ${e.subset}`,i=e.ranges.map(([e,t])=>`${e}-${t}`).join(`,`);return{name:r,subsetOf:e.family,key:`${r}:${e.weight??``}:${e.style??``}:${i}`,weight:e.weight,style:e.style,ranges:e.ranges,data:()=>n(e.url,t).then(e=>e.arrayBuffer())}}function m(e){let t=[];for(let n of e.split(`,`)){let e=n.trim().replace(/^U\+/i,``);if(e)if(e.includes(`-`)){let[n,r]=e.split(`-`);n&&r&&t.push([parseInt(n,16),parseInt(r,16)])}else if(e.includes(`?`))t.push([parseInt(e.replace(/\?/g,`0`),16),parseInt(e.replace(/\?/g,`F`),16)]);else{let n=parseInt(e,16);t.push([n,n])}}return t}function h(e){let t=[],n=0;for(let r of e.matchAll(f)){let e=r[2];if(!e)continue;let i=e.match(/src:\s*url\(([^)]+)\)/)?.[1]?.replace(/['"]/g,``).trim(),a=e.match(/font-family:\s*['"]?([^'";]+)['"]?/)?.[1]?.trim();if(!i||!a)continue;let o=e.match(/unicode-range:\s*([^;]+)/)?.[1],s=e.match(/font-weight:\s*(\d+)(?:\s+(\d+))?/);t.push({family:a,subset:r[1]?.trim()||`subset-${n}`,url:i,weight:s&&!s[2]?Number(s[1]):void 0,style:e.match(/font-style:\s*([a-z]+)/i)?.[1],ranges:o?m(o):[]}),n+=1}return t}function g(e){let t=new Map;for(let n of e){let e=t.get(n.url)??new Set;e.add(n.weight),t.set(n.url,e)}let n=new Set,r=[];for(let i of e){if(n.has(i.url))continue;n.add(i.url);let e=(t.get(i.url)?.size??0)>1;r.push(e?{...i,weight:void 0}:i)}return r}function _(e){let t=new Set,n=e=>{for(let n of e)t.add(n.codePointAt(0))},r=e=>{e.type===`text`?n(e.text):e.type===`container`&&e.children?.forEach(r)};return typeof e==`string`?n(e):Array.isArray(e)?e.forEach(r):r(e),t}function v(e,t){if(e.length===0)return!0;for(let n of t)for(let[t,r]of e)if(n>=t&&n<=r)return!0;return!1}function y({fonts:e,source:t}){let n=_(t);return e.filter(e=>v(e.ranges??[],n))}function b(e){return{key:e,data:()=>n(e).then(e=>e.arrayBuffer())}}async function x(e){return e.families.length===0?[]:g(h(await d(l(e),e))).map(t=>p(t,e))}exports.collectCodepoints=_,exports.container=e.t,exports.em=e.n,exports.fetchOk=n,exports.fontFromUrl=b,exports.fr=e.r,exports.googleFonts=x,exports.image=e.i,exports.percentage=e.a,exports.prepareImages=s,exports.rem=e.o,exports.rgba=e.s,exports.style=e.c,exports.subsetFonts=y,exports.text=e.l,exports.vh=e.u,exports.vw=e.d;
package/dist/index.d.cts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { a as NodeMetadata, c as TextNode, i as NodeAttributes, n as ImageNode, o as ReactElementLike, r as Node, s as TextFit, t as ContainerNode } from "./types-xgX3CGse.cjs";
2
- import { C as extractResourceUrls, S as FetchResourcesOptions, T as fetchResources, _ as googleFonts, a as percentage, b as FetchLike, c as style, d as vw, f as FontSubset, g as fontFromUrl, h as collectCodepoints, i as image, l as text, m as GoogleFontsOptions, n as em, o as rem, p as GoogleFontFamily, r as fr, s as rgba, t as container, u as vh, v as pickFonts, w as fetchOk, x as FetchOptions, y as subsetFonts } from "./index-DoixwISc.cjs";
3
- export { ContainerNode, FetchLike, FetchOptions, FetchResourcesOptions, FontSubset, GoogleFontFamily, GoogleFontsOptions, ImageNode, Node, NodeAttributes, NodeMetadata, ReactElementLike, TextFit, TextNode, collectCodepoints, container, em, extractResourceUrls, fetchOk, fetchResources, fontFromUrl, fr, googleFonts, image, percentage, pickFonts, rem, rgba, style, subsetFonts, text, vh, vw };
2
+ import { C as PrepareImagesOptions, S as ImageFetchCache, T as prepareImages, _ as googleFonts, a as percentage, b as FetchOptions, c as style, d as vw, f as FontSubset, g as fontFromUrl, h as collectCodepoints, i as image, l as text, m as GoogleFontsOptions, n as em, o as rem, p as GoogleFontFamily, r as fr, s as rgba, t as container, u as vh, v as subsetFonts, w as fetchOk, x as FetchedImage, y as FetchLike } from "./index-ck-uGf94.cjs";
3
+ export { ContainerNode, FetchLike, FetchOptions, FetchedImage, FontSubset, GoogleFontFamily, GoogleFontsOptions, ImageFetchCache, ImageNode, Node, NodeAttributes, NodeMetadata, PrepareImagesOptions, ReactElementLike, TextFit, TextNode, collectCodepoints, container, em, fetchOk, fontFromUrl, fr, googleFonts, image, percentage, prepareImages, rem, rgba, style, subsetFonts, text, vh, vw };
package/dist/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { a as NodeMetadata, c as TextNode, i as NodeAttributes, n as ImageNode, o as ReactElementLike, r as Node, s as TextFit, t as ContainerNode } from "./types-xgX3CGse.mjs";
2
- import { C as extractResourceUrls, S as FetchResourcesOptions, T as fetchResources, _ as googleFonts, a as percentage, b as FetchLike, c as style, d as vw, f as FontSubset, g as fontFromUrl, h as collectCodepoints, i as image, l as text, m as GoogleFontsOptions, n as em, o as rem, p as GoogleFontFamily, r as fr, s as rgba, t as container, u as vh, v as pickFonts, w as fetchOk, x as FetchOptions, y as subsetFonts } from "./index-B1e5HbDk.mjs";
3
- export { ContainerNode, FetchLike, FetchOptions, FetchResourcesOptions, FontSubset, GoogleFontFamily, GoogleFontsOptions, ImageNode, Node, NodeAttributes, NodeMetadata, ReactElementLike, TextFit, TextNode, collectCodepoints, container, em, extractResourceUrls, fetchOk, fetchResources, fontFromUrl, fr, googleFonts, image, percentage, pickFonts, rem, rgba, style, subsetFonts, text, vh, vw };
2
+ import { C as PrepareImagesOptions, S as ImageFetchCache, T as prepareImages, _ as googleFonts, a as percentage, b as FetchOptions, c as style, d as vw, f as FontSubset, g as fontFromUrl, h as collectCodepoints, i as image, l as text, m as GoogleFontsOptions, n as em, o as rem, p as GoogleFontFamily, r as fr, s as rgba, t as container, u as vh, v as subsetFonts, w as fetchOk, x as FetchedImage, y as FetchLike } from "./index-DWhDPZAL.mjs";
3
+ export { ContainerNode, FetchLike, FetchOptions, FetchedImage, FontSubset, GoogleFontFamily, GoogleFontsOptions, ImageFetchCache, ImageNode, Node, NodeAttributes, NodeMetadata, PrepareImagesOptions, ReactElementLike, TextFit, TextNode, collectCodepoints, container, em, fetchOk, fontFromUrl, fr, googleFonts, image, percentage, prepareImages, rem, rgba, style, subsetFonts, text, vh, vw };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{a as e,c as t,d as n,i as r,l as i,n as a,o,r as s,s as c,t as l,u}from"./helpers-CVQCT1Rh.mjs";const d=/url\(\s*(['"]?)(.*?)\1\s*\)/g;function f(e){return e.startsWith(`https://`)||e.startsWith(`http://`)}function p(e,t){if(typeof e==`string`)for(let n of e.matchAll(d)){let e=n[2]?.trim();e&&f(e)&&t.add(e)}else if(Array.isArray(e))for(let n of e)p(n,t)}function m(e){let t=new Set,n=e=>{let r=e=>{e&&(p(e.backgroundImage,t),p(e.maskImage,t))};if(r(e.style),r(e.preset),p(e.tw,t),e.type===`image`){typeof e.src==`string`&&f(e.src)&&t.add(e.src);return}if(e.type===`container`)for(let t of e.children??[])n(t)};return n(e),[...t]}async function h(e,t={}){let n=t.fetch??globalThis.fetch,r=t.timeout===void 0?t.init?.signal:AbortSignal.timeout(t.timeout),i=await n(e,{...t.init,signal:r});if(!i.ok)throw Error(`HTTP ${i.status} ${i.statusText} fetching ${e}`);return i}async function g(e,t){let n=t?.throwOnError??!0,r=t?.timeout??5e3,i=[...new Set(e)].map(async e=>{if(t?.cache?.has(e)){let n=t.cache.get(e);if(n)return{src:e,data:n}}let n=await h(e,{fetch:t?.fetch,timeout:r}).then(e=>e.arrayBuffer());return t?.cache?.set(e,n),{src:e,data:n}});return n?Promise.all(i):(await Promise.allSettled(i)).filter(e=>e.status===`fulfilled`).map(e=>e.value)}function _(e,t,n,r){let i=new Map(r),a=n.includes(`italic`),o=a?n.includes(`normal`)?[0,1]:[1]:[void 0],s=[...a?[`ital`]:[],...i.keys(),`wght`].sort(),c=o.flatMap(e=>t.map(t=>s.map(n=>n===`ital`?String(e):n===`wght`?t:i.get(n)??``).join(`,`))).sort();return`${e}:${s.join(`,`)}@${c.join(`;`)}`}function v(e){let t=new URL(e.baseUrl??`https://fonts.googleapis.com/css2`);for(let n of e.families){if(typeof n==`string`){t.searchParams.append(`family`,_(n,[`400`],[`normal`],[]));continue}let e=n.weight??400,r=(Array.isArray(e)?[...e].sort((e,t)=>e-t):[e]).map(String),i=n.style??`normal`,a=(Array.isArray(i)?i:[i]).map(String),o=Object.entries(n.axes??{}).filter(([e])=>e!==`ital`&&e!==`wght`).map(([e,t])=>[e,String(t)]);t.searchParams.append(`family`,_(n.name,r,a,o))}return e.display&&t.searchParams.set(`display`,e.display),t.toString()}function y(e,t){return h(e,{...t,init:{headers:{"User-Agent":`Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36`}}}).then(e=>e.text())}async function b(e,t){let n=t.cache?.get(e);if(n!==void 0)return n;let r=await y(e,t);return t.cache?.set(e,r),r}const x=/(?:\/\*\s*([^*]+?)\s*\*\/\s*)?@font-face\s*\{([^}]*)\}/g;function S(e,t){let n=`${e.family} ${e.subset}`,r=e.ranges.map(([e,t])=>`${e}-${t}`).join(`,`);return{name:n,subsetOf:e.family,key:`${n}:${e.weight??``}:${e.style??``}:${r}`,weight:e.weight,style:e.style,ranges:e.ranges,data:()=>h(e.url,t).then(e=>e.arrayBuffer())}}function C(e){let t=[];for(let n of e.split(`,`)){let e=n.trim().replace(/^U\+/i,``);if(e)if(e.includes(`-`)){let[n,r]=e.split(`-`);n&&r&&t.push([parseInt(n,16),parseInt(r,16)])}else if(e.includes(`?`))t.push([parseInt(e.replace(/\?/g,`0`),16),parseInt(e.replace(/\?/g,`F`),16)]);else{let n=parseInt(e,16);t.push([n,n])}}return t}function w(e){let t=[],n=0;for(let r of e.matchAll(x)){let e=r[2];if(!e)continue;let i=e.match(/src:\s*url\(([^)]+)\)/)?.[1]?.replace(/['"]/g,``).trim(),a=e.match(/font-family:\s*['"]?([^'";]+)['"]?/)?.[1]?.trim();if(!i||!a)continue;let o=e.match(/unicode-range:\s*([^;]+)/)?.[1],s=e.match(/font-weight:\s*(\d+)(?:\s+(\d+))?/);t.push({family:a,subset:r[1]?.trim()||`subset-${n}`,url:i,weight:s&&!s[2]?Number(s[1]):void 0,style:e.match(/font-style:\s*([a-z]+)/i)?.[1],ranges:o?C(o):[]}),n+=1}return t}function T(e){let t=new Map;for(let n of e){let e=t.get(n.url)??new Set;e.add(n.weight),t.set(n.url,e)}let n=new Set,r=[];for(let i of e){if(n.has(i.url))continue;n.add(i.url);let e=(t.get(i.url)?.size??0)>1;r.push(e?{...i,weight:void 0}:i)}return r}function E(e){let t=new Set,n=e=>{for(let n of e)t.add(n.codePointAt(0))},r=e=>{e.type===`text`?n(e.text):e.type===`container`&&e.children?.forEach(r)};return typeof e==`string`?n(e):Array.isArray(e)?e.forEach(r):r(e),t}function D(e,t){if(e.length===0)return!0;for(let n of t)for(let[t,r]of e)if(n>=t&&n<=r)return!0;return!1}function O({fonts:e,source:t}){let n=E(t);return e.filter(e=>D(e.ranges??[],n))}function k(e){return{key:e,data:()=>h(e).then(e=>e.arrayBuffer())}}function A({fonts:e,source:t,subset:n}){return e&&n!==!1?O({fonts:e,source:t}):e}async function j(e){return e.families.length===0?[]:T(w(await b(v(e),e))).map(t=>S(t,e))}export{E as collectCodepoints,l as container,a as em,m as extractResourceUrls,h as fetchOk,g as fetchResources,k as fontFromUrl,s as fr,j as googleFonts,r as image,e as percentage,A as pickFonts,o as rem,c as rgba,t as style,O as subsetFonts,i as text,u as vh,n as vw};
1
+ import{a as e,c as t,d as n,i as r,l as i,n as a,o,r as s,s as c,t as l,u}from"./helpers-CVQCT1Rh.mjs";const d=/url\(\s*(['"]?)(.*?)\1\s*\)/g;async function f(e,t={}){let n=t.fetch??globalThis.fetch,r=t.timeout===void 0?void 0:AbortSignal.timeout(t.timeout),i=[t.signal,t.init?.signal,r].filter(e=>e!==void 0),a=i.length?AbortSignal.any(i):void 0,o=await n(e,{...t.init,signal:a});if(!o.ok)throw Error(`HTTP ${o.status} ${o.statusText} fetching ${e}`);return o}function p(e){return e.startsWith(`https://`)||e.startsWith(`http://`)}function m(e,t){if(typeof e==`string`)for(let n of e.matchAll(d)){let e=n[2]?.trim();e&&p(e)&&t.add(e)}else if(Array.isArray(e))for(let n of e)m(n,t)}function h(e){let t=new Set,n=e=>{let r=e=>{e&&(m(e.backgroundImage,t),m(e.maskImage,t))};if(r(e.style),r(e.preset),m(e.tw,t),e.type===`image`){typeof e.src==`string`&&p(e.src)&&t.add(e.src);return}if(e.type===`container`)for(let t of e.children??[])n(t)};return n(e),[...t]}function g(e,t,n){let r=n?.get(e);if(r)return r;let i=f(e,t).then(e=>e.arrayBuffer()).catch(t=>{throw n?.delete(e),t});return n?.set(e,i),i}async function _({node:e,sources:t=[],fetchCache:n,fetch:r,timeout:i=5e3,signal:a,throwOnError:o=!0}){let s=Array.isArray(e)?e:[e],c=new Map;for(let e of t)c.set(e.src,e);let l=[...new Set(s.flatMap(h))].filter(e=>!c.has(e)),u={fetch:r,timeout:i,signal:a},d=l.map(async e=>({src:e,data:await g(e,u,n)})),f=o?await Promise.all(d):(await Promise.allSettled(d)).filter(e=>e.status===`fulfilled`).map(e=>e.value);return[...c.values(),...f]}function v(e,t,n,r){let i=new Map(r),a=n.includes(`italic`),o=a?n.includes(`normal`)?[0,1]:[1]:[void 0],s=[...a?[`ital`]:[],...i.keys(),`wght`].sort(),c=o.flatMap(e=>t.map(t=>s.map(n=>n===`ital`?String(e):n===`wght`?t:i.get(n)??``).join(`,`))).sort();return`${e}:${s.join(`,`)}@${c.join(`;`)}`}function y(e){let t=new URL(e.baseUrl??`https://fonts.googleapis.com/css2`);for(let n of e.families){if(typeof n==`string`){t.searchParams.append(`family`,v(n,[`400`],[`normal`],[]));continue}let e=n.weight??400,r=(Array.isArray(e)?[...e].sort((e,t)=>e-t):[e]).map(String),i=n.style??`normal`,a=(Array.isArray(i)?i:[i]).map(String),o=Object.entries(n.axes??{}).filter(([e])=>e!==`ital`&&e!==`wght`).map(([e,t])=>[e,String(t)]);t.searchParams.append(`family`,v(n.name,r,a,o))}return e.display&&t.searchParams.set(`display`,e.display),t.toString()}function b(e,t){return f(e,{...t,init:{headers:{"User-Agent":`Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36`}}}).then(e=>e.text())}async function x(e,t){let n=t.cache?.get(e);if(n!==void 0)return n;let r=await b(e,t);return t.cache?.set(e,r),r}const S=/(?:\/\*\s*([^*]+?)\s*\*\/\s*)?@font-face\s*\{([^}]*)\}/g;function C(e,t){let n=`${e.family} ${e.subset}`,r=e.ranges.map(([e,t])=>`${e}-${t}`).join(`,`);return{name:n,subsetOf:e.family,key:`${n}:${e.weight??``}:${e.style??``}:${r}`,weight:e.weight,style:e.style,ranges:e.ranges,data:()=>f(e.url,t).then(e=>e.arrayBuffer())}}function w(e){let t=[];for(let n of e.split(`,`)){let e=n.trim().replace(/^U\+/i,``);if(e)if(e.includes(`-`)){let[n,r]=e.split(`-`);n&&r&&t.push([parseInt(n,16),parseInt(r,16)])}else if(e.includes(`?`))t.push([parseInt(e.replace(/\?/g,`0`),16),parseInt(e.replace(/\?/g,`F`),16)]);else{let n=parseInt(e,16);t.push([n,n])}}return t}function T(e){let t=[],n=0;for(let r of e.matchAll(S)){let e=r[2];if(!e)continue;let i=e.match(/src:\s*url\(([^)]+)\)/)?.[1]?.replace(/['"]/g,``).trim(),a=e.match(/font-family:\s*['"]?([^'";]+)['"]?/)?.[1]?.trim();if(!i||!a)continue;let o=e.match(/unicode-range:\s*([^;]+)/)?.[1],s=e.match(/font-weight:\s*(\d+)(?:\s+(\d+))?/);t.push({family:a,subset:r[1]?.trim()||`subset-${n}`,url:i,weight:s&&!s[2]?Number(s[1]):void 0,style:e.match(/font-style:\s*([a-z]+)/i)?.[1],ranges:o?w(o):[]}),n+=1}return t}function E(e){let t=new Map;for(let n of e){let e=t.get(n.url)??new Set;e.add(n.weight),t.set(n.url,e)}let n=new Set,r=[];for(let i of e){if(n.has(i.url))continue;n.add(i.url);let e=(t.get(i.url)?.size??0)>1;r.push(e?{...i,weight:void 0}:i)}return r}function D(e){let t=new Set,n=e=>{for(let n of e)t.add(n.codePointAt(0))},r=e=>{e.type===`text`?n(e.text):e.type===`container`&&e.children?.forEach(r)};return typeof e==`string`?n(e):Array.isArray(e)?e.forEach(r):r(e),t}function O(e,t){if(e.length===0)return!0;for(let n of t)for(let[t,r]of e)if(n>=t&&n<=r)return!0;return!1}function k({fonts:e,source:t}){let n=D(t);return e.filter(e=>O(e.ranges??[],n))}function A(e){return{key:e,data:()=>f(e).then(e=>e.arrayBuffer())}}async function j(e){return e.families.length===0?[]:E(T(await x(y(e),e))).map(t=>C(t,e))}export{D as collectCodepoints,l as container,a as em,f as fetchOk,A as fontFromUrl,s as fr,j as googleFonts,r as image,e as percentage,_ as prepareImages,o as rem,c as rgba,t as style,k as subsetFonts,i as text,u as vh,n as vw};
package/dist/jsx.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./helpers-4kGcvc-Q.cjs"),t=require("./markup-uM2dO3dn.cjs");function n(e){return typeof e==`string`||typeof e==`number`}function r(e){return e.replace(/&/g,`&amp;`).replace(/"/g,`&quot;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}function i(e){let n=[];for(let r in e)Object.hasOwn(e,r)&&n.push(`${t.n(r)}:${String(e[r]).trim()}`);return n.join(`;`)}const a=new Set(`stopColor.stopOpacity.strokeWidth.strokeDasharray.strokeDashoffset.strokeLinecap.strokeLinejoin.fillRule.clipRule.colorInterpolationFilters.floodColor.floodOpacity.accentHeight.alignmentBaseline.arabicForm.baselineShift.capHeight.clipPath.clipPathUnits.colorInterpolation.colorProfile.colorRendering.enableBackground.fillOpacity.fontFamily.fontSize.fontSizeAdjust.fontStretch.fontStyle.fontVariant.fontWeight.glyphName.glyphOrientationHorizontal.glyphOrientationVertical.horizAdvX.horizOriginX.imageRendering.letterSpacing.lightingColor.markerEnd.markerMid.markerStart.overlinePosition.overlineThickness.paintOrder.preserveAspectRatio.pointerEvents.shapeRendering.strokeMiterlimit.strokeOpacity.textAnchor.textDecoration.textRendering.transformOrigin.underlinePosition.underlineThickness.unicodeBidi.unicodeRange.unitsPerEm.vectorEffect.vertAdvY.vertOriginX.vertOriginY.vAlphabetic.vHanging.vIdeographic.vMathematical.wordSpacing.writingMode`.split(`.`));function o(e,n){if(e===`children`||n==null)return;let o;if(o=e===`className`?`class`:a.has(e)?t.n(e):e,typeof n==`boolean`)return`${o}="${String(n)}"`;if(e===`style`&&typeof n==`object`){let e=i(n);if(e)return`style="${r(e)}"`}return`${o}="${r(String(n))}"`}function s(e,t,n){let r=!1;for(let n in e){if(!Object.hasOwn(e,n))continue;let i=o(n,e[n]);i!==void 0&&(t.push(` `,i),n===`xmlns`&&(r=!0))}n&&!r&&t.push(` xmlns="http://www.w3.org/2000/svg"`)}const c=(e,n,r)=>{let i=e.props||{};if(t.r(e.type)){l(e.type(e.props),n,!1);return}if(typeof e.type==`symbol`||typeof e.type!=`string`)return;n.push(`<`,e.type),s(i,n,r&&e.type===`svg`);let a=i.children;n.push(`>`),l(a,n,!1),n.push(`</`,e.type,`>`)};function l(e,r,i){if(!(e==null||e===!1)){if(n(e)){r.push(String(e));return}if(Array.isArray(e)){for(let t of e)l(t,r,!1);return}t.l(e)&&c(e,r,i)}}function u(e){let t=[];return l(e,t,!0),t.join(``)}function d(){return{nodes:[],stylesheets:[]}}const f=[/Invalid hook call\./,/Cannot read properties of null \(reading 'use[A-Z][A-Za-z]+'\)/,/null is not an object \(evaluating 'dispatcher\.use[A-Z][A-Za-z]+'\)/];let p,m;async function h(n,r){let i={defaultStyles:_(r),presets:t.d(r?.defaultStyles),tailwindClassesProperty:r?.tailwindClassesProperty??`tw`},a=await g(n,i).catch(async e=>{if(!y(e))throw e;return await O(n,i)||g(n,i)}),o=a.nodes,s;return s=o.length===0?e.t({}):o.length===1&&o[0]!==void 0?o[0]:e.t({children:o,style:{width:e.a(100),height:e.a(100)}}),{node:s,stylesheets:a.stylesheets}}async function g(n,r){return n==null||n===!1?d():n instanceof Promise?g(await n,r):typeof n==`object`&&Symbol.iterator in n?B(n,r):t.l(n)?await N(n,r):{nodes:[e.l({text:String(n),preset:r.presets?.span})],stylesheets:[]}}function _(e){return e&&`defaultStyles`in e?e.defaultStyles??t.f:t.f}function v(e){return!t.l(e)||typeof e.type!=`object`||e.type===null||!(`$$typeof`in e.type)?!1:e.type.$$typeof===Symbol.for(`react.context`)||e.type.$$typeof===Symbol.for(`react.provider`)}function y(e){return e instanceof Error?f.some(t=>t.test(e.message)):!1}async function b(e){let t=console.error;console.error=(...e)=>{let[n]=e;typeof n==`string`&&f.some(e=>e.test(n))||t(...e)};try{return await e()}finally{console.error=t}}async function x(e,t,n){return b(()=>g(e(t),n))}function S(e,n){if(!(typeof e.type!=`object`||e.type===null)){if(t.o(e.type)&&`render`in e.type){let t=e.type;return x(e=>t.render(e,null),e.props,n)}if(t.c(e.type)&&`type`in e.type){let r=e.type.type;return t.r(r)?x(r,e.props,n):N({...e,type:r},n)}}}function C(e){if(typeof e.props==`object`&&e.props!==null&&`children`in e.props)return e.props.children}function w(e){return typeof e==`object`&&!!e&&`createElement`in e&&typeof e.createElement==`function`}function T(e){return typeof e==`object`&&!!e&&`renderToStaticMarkup`in e&&typeof e.renderToStaticMarkup==`function`}async function E(){return m??=import(`react`).then(e=>{let t=e.default??e;return w(t)?t:null}).catch(()=>null),m}async function D(){return p??=import(`react-dom/server`).then(e=>{let t=e.default??e;return T(t)?t:null}).catch(()=>null),p}async function O(e,n){let[r,i]=await Promise.all([E(),D()]);return!r||!i?null:t.t(i.renderToStaticMarkup(r.createElement(r.Fragment??void 0,null,e)),{defaultStyles:n.defaultStyles,tailwindClassesProperty:n.tailwindClassesProperty})}function k(e){if(!t.l(e))return;let n=C(e);if(typeof n==`string`)return n;if(typeof n==`number`)return String(n);if(Array.isArray(n)||typeof n==`object`&&n&&Symbol.iterator in n)return M(n);if(t.l(n)&&t.s(n))return k(n)}function A(e){let t=[];for(let n of e){let e=j(n);if(e===void 0)return;t.push(e)}return t.join(``)}function j(e){if(typeof e==`string`)return e;if(typeof e==`number`)return String(e);if(e==null||typeof e==`boolean`||typeof e==`symbol`)return``;if(typeof e==`object`&&Symbol.iterator in e)return A(e);if(!t.l(e))return;if(t.s(e))return j(C(e));let n=C(e);return n===void 0?``:typeof n==`object`&&n&&Symbol.iterator in n?A(n):j(n)}function M(e){let n=[];for(let r of e){if(t.l(r))return;if(typeof r==`string`){n.push(r);continue}if(typeof r==`number`){n.push(String(r));continue}return}return n.join(``)}async function N(n,r){if(v(n))return await O(n,r)||z(n,r);if(t.r(n.type))return x(n.type,n.props,r);let i=S(n,r);if(i!==void 0)return i;if(t.s(n))return z(n,r);if(t.i(n,`style`)){let e=j(C(n));return{nodes:[],stylesheets:e&&e.length>0?[e]:[]}}if(typeof n.type!=`string`||t.a(n.type))return d();let a=R(n,r);if(t.i(n,`br`))return{nodes:[e.l({text:`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./helpers-4kGcvc-Q.cjs"),t=require("./markup-uM2dO3dn.cjs");function n(e){return typeof e==`string`||typeof e==`number`}function r(e){return e.replace(/&/g,`&amp;`).replace(/"/g,`&quot;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}function i(e){let n=[];for(let r in e)Object.hasOwn(e,r)&&n.push(`${t.n(r)}:${String(e[r]).trim()}`);return n.join(`;`)}const a=new Set(`stopColor.stopOpacity.strokeWidth.strokeDasharray.strokeDashoffset.strokeLinecap.strokeLinejoin.fillRule.clipRule.colorInterpolationFilters.floodColor.floodOpacity.accentHeight.alignmentBaseline.arabicForm.baselineShift.capHeight.clipPath.clipPathUnits.colorInterpolation.colorProfile.colorRendering.enableBackground.fillOpacity.fontFamily.fontSize.fontSizeAdjust.fontStretch.fontStyle.fontVariant.fontWeight.glyphName.glyphOrientationHorizontal.glyphOrientationVertical.horizAdvX.horizOriginX.imageRendering.letterSpacing.lightingColor.markerEnd.markerMid.markerStart.overlinePosition.overlineThickness.paintOrder.preserveAspectRatio.pointerEvents.shapeRendering.strokeMiterlimit.strokeOpacity.textAnchor.textDecoration.textRendering.transformOrigin.underlinePosition.underlineThickness.unicodeBidi.unicodeRange.unitsPerEm.vectorEffect.vertAdvY.vertOriginX.vertOriginY.vAlphabetic.vHanging.vIdeographic.vMathematical.wordSpacing.writingMode`.split(`.`));function o(e,n){if(e===`children`||n==null)return;let o;if(o=e===`className`?`class`:a.has(e)?t.n(e):e,typeof n==`boolean`)return`${o}="${String(n)}"`;if(e===`style`&&typeof n==`object`){let e=i(n);if(e)return`style="${r(e)}"`}return`${o}="${r(String(n))}"`}function s(e,t,n){let r=!1;for(let n in e){if(!Object.hasOwn(e,n))continue;let i=o(n,e[n]);i!==void 0&&(t.push(` `,i),n===`xmlns`&&(r=!0))}n&&!r&&t.push(` xmlns="http://www.w3.org/2000/svg"`)}const c=(e,n,r)=>{let i=e.props||{};if(t.r(e.type)){l(e.type(e.props),n,!1);return}if(typeof e.type==`symbol`||typeof e.type!=`string`)return;n.push(`<`,e.type),s(i,n,r&&e.type===`svg`);let a=i.children;n.push(`>`),l(a,n,!1),n.push(`</`,e.type,`>`)};function l(e,r,i){if(!(e==null||e===!1)){if(n(e)){r.push(String(e));return}if(Array.isArray(e)){for(let t of e)l(t,r,!1);return}t.l(e)&&c(e,r,i)}}function u(e){let t=[];return l(e,t,!0),t.join(``)}function d(){return{nodes:[],stylesheets:[]}}const f=[/Invalid hook call\./,/Cannot read properties of null \(reading 'use[A-Z][A-Za-z]+'\)/,/null is not an object \(evaluating 'dispatcher\.use[A-Z][A-Za-z]+'\)/];let p,m;async function h(n,r){let i={defaultStyles:_(r),presets:t.d(r?.defaultStyles),tailwindClassesProperty:r?.tailwindClassesProperty??`tw`},a=await g(n,i).catch(async e=>{if(!y(e))throw e;return await O(n,i)||g(n,i)}),o=a.nodes,s;return s=o.length===0?e.t({}):o.length===1&&o[0]!==void 0?o[0]:e.t({children:o,style:{width:e.a(100),height:e.a(100)}}),{node:s,stylesheets:a.stylesheets}}async function g(n,r){return n==null||n===!1?d():n instanceof Promise?g(await n,r):typeof n==`object`&&Symbol.iterator in n?B(n,r):t.l(n)?await N(n,r):{nodes:[e.l({text:String(n),preset:r.presets?.span})],stylesheets:[]}}function _(e){return e&&`defaultStyles`in e?e.defaultStyles??t.f:t.f}function v(e){return!t.l(e)||typeof e.type!=`object`||e.type===null||!(`$$typeof`in e.type)?!1:e.type.$$typeof===Symbol.for(`react.context`)||e.type.$$typeof===Symbol.for(`react.provider`)}function y(e){return e instanceof Error?f.some(t=>t.test(e.message)):!1}async function b(e){let t=console.error;console.error=(...e)=>{let[n]=e;typeof n==`string`&&f.some(e=>e.test(n))||t(...e)};try{return await e()}finally{console.error=t}}async function x(e,t,n){return b(()=>g(e(t),n))}function S(e,n){if(!(typeof e.type!=`object`||e.type===null)){if(t.o(e.type)&&`render`in e.type){let t=e.type;return x(e=>t.render(e,null),e.props,n)}if(t.c(e.type)&&`type`in e.type){let r=e.type.type;return t.r(r)?x(r,e.props,n):N({...e,type:r},n)}}}function C(e){if(typeof e.props==`object`&&e.props!==null&&`children`in e.props)return e.props.children}function w(e){return typeof e==`object`&&!!e&&`createElement`in e&&typeof e.createElement==`function`}function T(e){return typeof e==`object`&&!!e&&`renderToStaticMarkup`in e&&typeof e.renderToStaticMarkup==`function`}async function E(){return m??=import(`react`).then(e=>{let t=e.default??e;return w(t)?t:null}).catch(()=>null),m}async function D(){return p??=import(`react-dom/server`).then(e=>{let t=e.default??e;return T(t)?t:null}).catch(()=>null),p}async function O(e,n){let[r,i]=await Promise.all([E(),D()]);return!r||!i?null:t.t(i.renderToStaticMarkup(r.createElement(r.Fragment??void 0,null,e)),{defaultStyles:n.defaultStyles,tailwindClassesProperty:n.tailwindClassesProperty})}function k(e){if(!t.l(e))return;let n=C(e);if(typeof n==`string`)return n;if(typeof n==`number`)return String(n);if(Array.isArray(n)||typeof n==`object`&&n&&Symbol.iterator in n)return M(n);if(t.l(n)&&t.s(n))return k(n)}function A(e){let t=[];for(let n of e){let e=j(n);if(e===void 0)return;t.push(e)}return t.join(``)}function j(e){if(typeof e==`string`)return e;if(typeof e==`number`)return String(e);if(e==null||typeof e==`boolean`||typeof e==`symbol`)return``;if(typeof e==`object`&&Symbol.iterator in e)return A(e);if(!t.l(e))return;if(t.s(e))return j(C(e));let n=C(e);return n===void 0?``:typeof n==`object`&&n&&Symbol.iterator in n?A(n):j(n)}function M(e){let n=[],r=!1;for(let i of e){if(t.l(i))return;if(typeof i==`string`){r=!0,n.push(i);continue}if(typeof i==`number`){r=!0,n.push(String(i));continue}return}if(r)return n.join(``)}async function N(n,r){if(v(n))return await O(n,r)||z(n,r);if(t.r(n.type))return x(n.type,n.props,r);let i=S(n,r);if(i!==void 0)return i;if(t.s(n))return z(n,r);if(t.i(n,`style`)){let e=j(C(n));return{nodes:[],stylesheets:e&&e.length>0?[e]:[]}}if(typeof n.type!=`string`||t.a(n.type))return d();let a=R(n,r);if(t.i(n,`br`))return{nodes:[e.l({text:`
2
2
  `,preset:r.presets?.span,...a})],stylesheets:[]};if(t.i(n,`img`))return{nodes:[P(n,r)],stylesheets:[]};if(t.i(n,`svg`))return{nodes:[F(n,r)],stylesheets:[]};let o=k(n);if(o!==void 0)return{nodes:[e.l({text:o,...a})],stylesheets:[]};let s=await z(n,r);return{nodes:[e.t({children:s.nodes,...a})],stylesheets:s.stylesheets}}function P(t,n){if(!t.props.src)throw Error(`Image element must have a 'src' prop.`);let r=R(t,n),i=t.props.width===void 0?void 0:Number(t.props.width),a=t.props.height===void 0?void 0:Number(t.props.height);return e.i({src:t.props.src,width:i,height:a,...r})}function F(t,n){let r=R(t,n);return e.i({src:u(t),width:t.props.width===void 0?void 0:Number(t.props.width),height:t.props.height===void 0?void 0:Number(t.props.height),...r})}function I(e,t){let n=t.presets,r=n&&typeof e.type==`string`&&e.type in n?n[e.type]:void 0,i=typeof e.props==`object`&&e.props!==null&&`style`in e.props&&typeof e.props.style==`object`&&e.props.style!==null?e.props.style:void 0;if(!i)return{preset:r};for(let e in i)if(Object.hasOwn(i,e))return{preset:r,style:i};return{preset:r}}function L(e,t){let n=t.tailwindClassesProperty;if(typeof e.props!=`object`||e.props===null||!(n in e.props))return;let r=e.props[n];if(typeof r==`string`)return r}function R(e,n){let r=e.props,{preset:i,style:a}=I(e,n),o=L(e,n),s=t.u(r,n.tailwindClassesProperty);return{tagName:typeof e.type==`string`?e.type:void 0,className:r.className??r.class,id:r.id,dir:r.dir,lang:r.lang,attributes:s,tw:o,style:a,preset:i}}function z(e,t){let n=C(e);return n===void 0?Promise.resolve(d()):g(n,t)}async function B(e,t){let n=[],r=new Set,i=0;for(let a of e){let e=i;i+=1;let o=g(a,t).then(t=>{n[e]=t}).finally(()=>r.delete(o));r.add(o),r.size>=8&&await Promise.race(r)}await Promise.all(r);let a=[],o=[];for(let e of n)e&&(a.push(...e.nodes),o.push(...e.stylesheets));return{nodes:a,stylesheets:o}}exports.defaultStylePresets=t.f,exports.fromJsx=h;
package/dist/jsx.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{a as i,c as a,d as o,f as s,i as c,l,n as u,o as d,r as f,s as p,t as m,u as h}from"./markup-D58RlLsR.mjs";function g(e){return typeof e==`string`||typeof e==`number`}function _(e){return e.replace(/&/g,`&amp;`).replace(/"/g,`&quot;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}function v(e){let t=[];for(let n in e)Object.hasOwn(e,n)&&t.push(`${u(n)}:${String(e[n]).trim()}`);return t.join(`;`)}const y=new Set(`stopColor.stopOpacity.strokeWidth.strokeDasharray.strokeDashoffset.strokeLinecap.strokeLinejoin.fillRule.clipRule.colorInterpolationFilters.floodColor.floodOpacity.accentHeight.alignmentBaseline.arabicForm.baselineShift.capHeight.clipPath.clipPathUnits.colorInterpolation.colorProfile.colorRendering.enableBackground.fillOpacity.fontFamily.fontSize.fontSizeAdjust.fontStretch.fontStyle.fontVariant.fontWeight.glyphName.glyphOrientationHorizontal.glyphOrientationVertical.horizAdvX.horizOriginX.imageRendering.letterSpacing.lightingColor.markerEnd.markerMid.markerStart.overlinePosition.overlineThickness.paintOrder.preserveAspectRatio.pointerEvents.shapeRendering.strokeMiterlimit.strokeOpacity.textAnchor.textDecoration.textRendering.transformOrigin.underlinePosition.underlineThickness.unicodeBidi.unicodeRange.unitsPerEm.vectorEffect.vertAdvY.vertOriginX.vertOriginY.vAlphabetic.vHanging.vIdeographic.vMathematical.wordSpacing.writingMode`.split(`.`));function b(e,t){if(e===`children`||t==null)return;let n;if(n=e===`className`?`class`:y.has(e)?u(e):e,typeof t==`boolean`)return`${n}="${String(t)}"`;if(e===`style`&&typeof t==`object`){let e=v(t);if(e)return`style="${_(e)}"`}return`${n}="${_(String(t))}"`}function x(e,t,n){let r=!1;for(let n in e){if(!Object.hasOwn(e,n))continue;let i=b(n,e[n]);i!==void 0&&(t.push(` `,i),n===`xmlns`&&(r=!0))}n&&!r&&t.push(` xmlns="http://www.w3.org/2000/svg"`)}const S=(e,t,n)=>{let r=e.props||{};if(f(e.type)){C(e.type(e.props),t,!1);return}if(typeof e.type==`symbol`||typeof e.type!=`string`)return;t.push(`<`,e.type),x(r,t,n&&e.type===`svg`);let i=r.children;t.push(`>`),C(i,t,!1),t.push(`</`,e.type,`>`)};function C(e,t,n){if(!(e==null||e===!1)){if(g(e)){t.push(String(e));return}if(Array.isArray(e)){for(let n of e)C(n,t,!1);return}l(e)&&S(e,t,n)}}function w(e){let t=[];return C(e,t,!0),t.join(``)}function T(){return{nodes:[],stylesheets:[]}}const E=[/Invalid hook call\./,/Cannot read properties of null \(reading 'use[A-Z][A-Za-z]+'\)/,/null is not an object \(evaluating 'dispatcher\.use[A-Z][A-Za-z]+'\)/];let D,O;async function k(t,n){let i={defaultStyles:j(n),presets:o(n?.defaultStyles),tailwindClassesProperty:n?.tailwindClassesProperty??`tw`},a=await A(t,i).catch(async e=>{if(!N(e))throw e;return await H(t,i)||A(t,i)}),s=a.nodes,c;return c=s.length===0?r({}):s.length===1&&s[0]!==void 0?s[0]:r({children:s,style:{width:e(100),height:e(100)}}),{node:c,stylesheets:a.stylesheets}}async function A(e,t){return e==null||e===!1?T():e instanceof Promise?A(await e,t):typeof e==`object`&&Symbol.iterator in e?ee(e,t):l(e)?await q(e,t):{nodes:[n({text:String(e),preset:t.presets?.span})],stylesheets:[]}}function j(e){return e&&`defaultStyles`in e?e.defaultStyles??s:s}function M(e){return!l(e)||typeof e.type!=`object`||e.type===null||!(`$$typeof`in e.type)?!1:e.type.$$typeof===Symbol.for(`react.context`)||e.type.$$typeof===Symbol.for(`react.provider`)}function N(e){return e instanceof Error?E.some(t=>t.test(e.message)):!1}async function P(e){let t=console.error;console.error=(...e)=>{let[n]=e;typeof n==`string`&&E.some(e=>e.test(n))||t(...e)};try{return await e()}finally{console.error=t}}async function F(e,t,n){return P(()=>A(e(t),n))}function I(e,t){if(!(typeof e.type!=`object`||e.type===null)){if(d(e.type)&&`render`in e.type){let n=e.type;return F(e=>n.render(e,null),e.props,t)}if(a(e.type)&&`type`in e.type){let n=e.type.type;return f(n)?F(n,e.props,t):q({...e,type:n},t)}}}function L(e){if(typeof e.props==`object`&&e.props!==null&&`children`in e.props)return e.props.children}function R(e){return typeof e==`object`&&!!e&&`createElement`in e&&typeof e.createElement==`function`}function z(e){return typeof e==`object`&&!!e&&`renderToStaticMarkup`in e&&typeof e.renderToStaticMarkup==`function`}async function B(){return O??=import(`react`).then(e=>{let t=e.default??e;return R(t)?t:null}).catch(()=>null),O}async function V(){return D??=import(`react-dom/server`).then(e=>{let t=e.default??e;return z(t)?t:null}).catch(()=>null),D}async function H(e,t){let[n,r]=await Promise.all([B(),V()]);return!n||!r?null:m(r.renderToStaticMarkup(n.createElement(n.Fragment??void 0,null,e)),{defaultStyles:t.defaultStyles,tailwindClassesProperty:t.tailwindClassesProperty})}function U(e){if(!l(e))return;let t=L(e);if(typeof t==`string`)return t;if(typeof t==`number`)return String(t);if(Array.isArray(t)||typeof t==`object`&&t&&Symbol.iterator in t)return K(t);if(l(t)&&p(t))return U(t)}function W(e){let t=[];for(let n of e){let e=G(n);if(e===void 0)return;t.push(e)}return t.join(``)}function G(e){if(typeof e==`string`)return e;if(typeof e==`number`)return String(e);if(e==null||typeof e==`boolean`||typeof e==`symbol`)return``;if(typeof e==`object`&&Symbol.iterator in e)return W(e);if(!l(e))return;if(p(e))return G(L(e));let t=L(e);return t===void 0?``:typeof t==`object`&&t&&Symbol.iterator in t?W(t):G(t)}function K(e){let t=[];for(let n of e){if(l(n))return;if(typeof n==`string`){t.push(n);continue}if(typeof n==`number`){t.push(String(n));continue}return}return t.join(``)}async function q(e,t){if(M(e))return await H(e,t)||$(e,t);if(f(e.type))return F(e.type,e.props,t);let a=I(e,t);if(a!==void 0)return a;if(p(e))return $(e,t);if(c(e,`style`)){let t=G(L(e));return{nodes:[],stylesheets:t&&t.length>0?[t]:[]}}if(typeof e.type!=`string`||i(e.type))return T();let o=Q(e,t);if(c(e,`br`))return{nodes:[n({text:`
1
+ import{a as e,i as t,l as n,t as r}from"./helpers-CVQCT1Rh.mjs";import{a as i,c as a,d as o,f as s,i as c,l,n as u,o as d,r as f,s as p,t as m,u as h}from"./markup-D58RlLsR.mjs";function g(e){return typeof e==`string`||typeof e==`number`}function _(e){return e.replace(/&/g,`&amp;`).replace(/"/g,`&quot;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}function v(e){let t=[];for(let n in e)Object.hasOwn(e,n)&&t.push(`${u(n)}:${String(e[n]).trim()}`);return t.join(`;`)}const y=new Set(`stopColor.stopOpacity.strokeWidth.strokeDasharray.strokeDashoffset.strokeLinecap.strokeLinejoin.fillRule.clipRule.colorInterpolationFilters.floodColor.floodOpacity.accentHeight.alignmentBaseline.arabicForm.baselineShift.capHeight.clipPath.clipPathUnits.colorInterpolation.colorProfile.colorRendering.enableBackground.fillOpacity.fontFamily.fontSize.fontSizeAdjust.fontStretch.fontStyle.fontVariant.fontWeight.glyphName.glyphOrientationHorizontal.glyphOrientationVertical.horizAdvX.horizOriginX.imageRendering.letterSpacing.lightingColor.markerEnd.markerMid.markerStart.overlinePosition.overlineThickness.paintOrder.preserveAspectRatio.pointerEvents.shapeRendering.strokeMiterlimit.strokeOpacity.textAnchor.textDecoration.textRendering.transformOrigin.underlinePosition.underlineThickness.unicodeBidi.unicodeRange.unitsPerEm.vectorEffect.vertAdvY.vertOriginX.vertOriginY.vAlphabetic.vHanging.vIdeographic.vMathematical.wordSpacing.writingMode`.split(`.`));function b(e,t){if(e===`children`||t==null)return;let n;if(n=e===`className`?`class`:y.has(e)?u(e):e,typeof t==`boolean`)return`${n}="${String(t)}"`;if(e===`style`&&typeof t==`object`){let e=v(t);if(e)return`style="${_(e)}"`}return`${n}="${_(String(t))}"`}function x(e,t,n){let r=!1;for(let n in e){if(!Object.hasOwn(e,n))continue;let i=b(n,e[n]);i!==void 0&&(t.push(` `,i),n===`xmlns`&&(r=!0))}n&&!r&&t.push(` xmlns="http://www.w3.org/2000/svg"`)}const S=(e,t,n)=>{let r=e.props||{};if(f(e.type)){C(e.type(e.props),t,!1);return}if(typeof e.type==`symbol`||typeof e.type!=`string`)return;t.push(`<`,e.type),x(r,t,n&&e.type===`svg`);let i=r.children;t.push(`>`),C(i,t,!1),t.push(`</`,e.type,`>`)};function C(e,t,n){if(!(e==null||e===!1)){if(g(e)){t.push(String(e));return}if(Array.isArray(e)){for(let n of e)C(n,t,!1);return}l(e)&&S(e,t,n)}}function w(e){let t=[];return C(e,t,!0),t.join(``)}function T(){return{nodes:[],stylesheets:[]}}const E=[/Invalid hook call\./,/Cannot read properties of null \(reading 'use[A-Z][A-Za-z]+'\)/,/null is not an object \(evaluating 'dispatcher\.use[A-Z][A-Za-z]+'\)/];let D,O;async function k(t,n){let i={defaultStyles:j(n),presets:o(n?.defaultStyles),tailwindClassesProperty:n?.tailwindClassesProperty??`tw`},a=await A(t,i).catch(async e=>{if(!N(e))throw e;return await H(t,i)||A(t,i)}),s=a.nodes,c;return c=s.length===0?r({}):s.length===1&&s[0]!==void 0?s[0]:r({children:s,style:{width:e(100),height:e(100)}}),{node:c,stylesheets:a.stylesheets}}async function A(e,t){return e==null||e===!1?T():e instanceof Promise?A(await e,t):typeof e==`object`&&Symbol.iterator in e?ee(e,t):l(e)?await q(e,t):{nodes:[n({text:String(e),preset:t.presets?.span})],stylesheets:[]}}function j(e){return e&&`defaultStyles`in e?e.defaultStyles??s:s}function M(e){return!l(e)||typeof e.type!=`object`||e.type===null||!(`$$typeof`in e.type)?!1:e.type.$$typeof===Symbol.for(`react.context`)||e.type.$$typeof===Symbol.for(`react.provider`)}function N(e){return e instanceof Error?E.some(t=>t.test(e.message)):!1}async function P(e){let t=console.error;console.error=(...e)=>{let[n]=e;typeof n==`string`&&E.some(e=>e.test(n))||t(...e)};try{return await e()}finally{console.error=t}}async function F(e,t,n){return P(()=>A(e(t),n))}function I(e,t){if(!(typeof e.type!=`object`||e.type===null)){if(d(e.type)&&`render`in e.type){let n=e.type;return F(e=>n.render(e,null),e.props,t)}if(a(e.type)&&`type`in e.type){let n=e.type.type;return f(n)?F(n,e.props,t):q({...e,type:n},t)}}}function L(e){if(typeof e.props==`object`&&e.props!==null&&`children`in e.props)return e.props.children}function R(e){return typeof e==`object`&&!!e&&`createElement`in e&&typeof e.createElement==`function`}function z(e){return typeof e==`object`&&!!e&&`renderToStaticMarkup`in e&&typeof e.renderToStaticMarkup==`function`}async function B(){return O??=import(`react`).then(e=>{let t=e.default??e;return R(t)?t:null}).catch(()=>null),O}async function V(){return D??=import(`react-dom/server`).then(e=>{let t=e.default??e;return z(t)?t:null}).catch(()=>null),D}async function H(e,t){let[n,r]=await Promise.all([B(),V()]);return!n||!r?null:m(r.renderToStaticMarkup(n.createElement(n.Fragment??void 0,null,e)),{defaultStyles:t.defaultStyles,tailwindClassesProperty:t.tailwindClassesProperty})}function U(e){if(!l(e))return;let t=L(e);if(typeof t==`string`)return t;if(typeof t==`number`)return String(t);if(Array.isArray(t)||typeof t==`object`&&t&&Symbol.iterator in t)return K(t);if(l(t)&&p(t))return U(t)}function W(e){let t=[];for(let n of e){let e=G(n);if(e===void 0)return;t.push(e)}return t.join(``)}function G(e){if(typeof e==`string`)return e;if(typeof e==`number`)return String(e);if(e==null||typeof e==`boolean`||typeof e==`symbol`)return``;if(typeof e==`object`&&Symbol.iterator in e)return W(e);if(!l(e))return;if(p(e))return G(L(e));let t=L(e);return t===void 0?``:typeof t==`object`&&t&&Symbol.iterator in t?W(t):G(t)}function K(e){let t=[],n=!1;for(let r of e){if(l(r))return;if(typeof r==`string`){n=!0,t.push(r);continue}if(typeof r==`number`){n=!0,t.push(String(r));continue}return}if(n)return t.join(``)}async function q(e,t){if(M(e))return await H(e,t)||$(e,t);if(f(e.type))return F(e.type,e.props,t);let a=I(e,t);if(a!==void 0)return a;if(p(e))return $(e,t);if(c(e,`style`)){let t=G(L(e));return{nodes:[],stylesheets:t&&t.length>0?[t]:[]}}if(typeof e.type!=`string`||i(e.type))return T();let o=Q(e,t);if(c(e,`br`))return{nodes:[n({text:`
2
2
  `,preset:t.presets?.span,...o})],stylesheets:[]};if(c(e,`img`))return{nodes:[J(e,t)],stylesheets:[]};if(c(e,`svg`))return{nodes:[Y(e,t)],stylesheets:[]};let s=U(e);if(s!==void 0)return{nodes:[n({text:s,...o})],stylesheets:[]};let l=await $(e,t);return{nodes:[r({children:l.nodes,...o})],stylesheets:l.stylesheets}}function J(e,n){if(!e.props.src)throw Error(`Image element must have a 'src' prop.`);let r=Q(e,n),i=e.props.width===void 0?void 0:Number(e.props.width),a=e.props.height===void 0?void 0:Number(e.props.height);return t({src:e.props.src,width:i,height:a,...r})}function Y(e,n){let r=Q(e,n);return t({src:w(e),width:e.props.width===void 0?void 0:Number(e.props.width),height:e.props.height===void 0?void 0:Number(e.props.height),...r})}function X(e,t){let n=t.presets,r=n&&typeof e.type==`string`&&e.type in n?n[e.type]:void 0,i=typeof e.props==`object`&&e.props!==null&&`style`in e.props&&typeof e.props.style==`object`&&e.props.style!==null?e.props.style:void 0;if(!i)return{preset:r};for(let e in i)if(Object.hasOwn(i,e))return{preset:r,style:i};return{preset:r}}function Z(e,t){let n=t.tailwindClassesProperty;if(typeof e.props!=`object`||e.props===null||!(n in e.props))return;let r=e.props[n];if(typeof r==`string`)return r}function Q(e,t){let n=e.props,{preset:r,style:i}=X(e,t),a=Z(e,t),o=h(n,t.tailwindClassesProperty);return{tagName:typeof e.type==`string`?e.type:void 0,className:n.className??n.class,id:n.id,dir:n.dir,lang:n.lang,attributes:o,tw:a,style:i,preset:r}}function $(e,t){let n=L(e);return n===void 0?Promise.resolve(T()):A(n,t)}async function ee(e,t){let n=[],r=new Set,i=0;for(let a of e){let e=i;i+=1;let o=A(a,t).then(t=>{n[e]=t}).finally(()=>r.delete(o));r.add(o),r.size>=8&&await Promise.race(r)}await Promise.all(r);let a=[],o=[];for(let e of n)e&&(a.push(...e.nodes),o.push(...e.stylesheets));return{nodes:a,stylesheets:o}}export{s as defaultStylePresets,k as fromJsx};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@takumi-rs/helpers",
3
- "version": "2.0.0-rc.3",
4
- "description": "Utility helpers for converting JSX/HTML to Takumi node trees and handling resources.",
3
+ "version": "2.0.0-rc.4",
4
+ "description": "Utility helpers for converting JSX/HTML to Takumi node trees, loading fonts, and processing emoji.",
5
5
  "keywords": [
6
6
  "css",
7
7
  "emoji",