@takumi-rs/helpers 2.13.5 → 2.13.6

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/emoji.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { c as Node } from "./types-BWYDTgEO.cjs";
1
+ import { c as Node } from "./types-XYUVkGQq.cjs";
2
2
  //#region src/emoji.d.ts
3
3
  type EmojiType = "twemoji" | "blobmoji" | "noto" | "openmoji" | "fluent" | "fluentFlat";
4
4
  declare function extractEmojis(node: Node, emojiType: EmojiType): Node;
package/dist/emoji.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { c as Node } from "./types-BWYDTgEO.mjs";
1
+ import { c as Node } from "./types-XYUVkGQq.mjs";
2
2
  //#region src/emoji.d.ts
3
3
  type EmojiType = "twemoji" | "blobmoji" | "noto" | "openmoji" | "fluent" | "fluentFlat";
4
4
  declare function extractEmojis(node: Node, emojiType: EmojiType): Node;
@@ -0,0 +1 @@
1
+ var e=class{signal;constructor(e,t){let n=e.timeout??3e4,r=[e.signal,t,n<=0?void 0:AbortSignal.timeout(n)].filter(e=>e!=null);this.signal=r.length?AbortSignal.any(r):void 0}waitFor(e){let t=this.signal;return t?new Promise((n,r)=>{function i(){t?.removeEventListener(`abort`,i),r(t?.reason)}t.addEventListener(`abort`,i,{once:!0}),e.then(e=>{t.removeEventListener(`abort`,i),n(e)},e=>{t.removeEventListener(`abort`,i),r(e)}),t.aborted&&i()}):e}};const t=new Set([301,302,303,307,308]),n=new Set([408,429,500,502,503,504]);async function r(e,t={}){return new i(e,t).send()}var i=class r{url;allowUrl;fetchImpl;init;constructor(t,n){if(n.allowUrl&&!n.allowUrl(t))throw Error(`URL blocked by allowUrl policy: ${t}`);this.url=t,this.allowUrl=n.allowUrl,this.fetchImpl=n.fetch??globalThis.fetch,this.init={...n.init,signal:new e(n,n.init?.signal).signal}}async send(){let e=this.allowUrl?await this.followRedirects(this.allowUrl):await this.attempt(this.url,this.init);if(!e.ok)throw Error(`HTTP ${e.status} ${e.statusText} fetching ${this.url}`);return e}async attempt(e,t){let r=t.method?.toUpperCase()??`GET`,i=r===`GET`||r===`HEAD`;for(let r=0;;r++){t.signal?.throwIfAborted();let a=100*2**r;try{let o=await this.fetchImpl.call(void 0,e,t);if(t.signal?.throwIfAborted(),!i||r===2||!n.has(o.status))return o;let s=o.headers.get(`retry-after`);if(s!==null){let e=Number(s),t=Number.isFinite(e)?e*1e3:Date.parse(s)-Date.now();Number.isFinite(t)&&(a=Math.max(a,t))}if(a>1e3)return o;o.body?.cancel().catch(()=>{})}catch(e){if(t.signal?.throwIfAborted(),!i||r===2||!(e instanceof Error)||e.name!==`TypeError`&&e.name!==`TimeoutError`)throw e}await this.wait(a)}}wait(e){let t=this.init.signal;return t?.throwIfAborted(),new Promise((n,r)=>{let i=setTimeout(()=>{t?.removeEventListener(`abort`,a),n()},e);function a(){clearTimeout(i),r(t?.reason)}t?.addEventListener(`abort`,a,{once:!0})})}async followRedirects(e){let n=this.url,i={...this.init,headers:new Headers(this.init.headers),redirect:`manual`};for(let a=0;a<5;a++){let a=await this.attempt(n,i),o=a.headers.get(`location`);if(!t.has(a.status)||o===null)return a;await a.body?.cancel().catch(()=>{});let s=new URL(o,n);if(!e(s.href))throw Error(`URL blocked by allowUrl policy: ${s.href}`);if(s.protocol!==`https:`&&s.protocol!==`http:`||s.username||s.password)throw Error(`Invalid redirect URL: ${s.href}`);i=r.redirectInit(i,a.status,n,s),n=s.href}throw Error(`Too many redirects fetching ${this.url}`)}static redirectInit(e,t,n,r){if(t!==303&&e.body instanceof ReadableStream)throw Error(`Cannot replay a streamed request body after a redirect`);let i=new Headers(e.headers),a=e.method?.toUpperCase()??`GET`,o=(t===301||t===302)&&a===`POST`||t===303&&a!==`GET`&&a!==`HEAD`;if(o)for(let e of[`content-encoding`,`content-language`,`content-location`,`content-type`,`content-length`])i.delete(e);if(new URL(n).origin!==r.origin)for(let e of[`authorization`,`proxy-authorization`,`cookie`,`cookie2`])i.delete(e);return{...e,headers:i,method:o?`GET`:e.method,body:o?void 0:e.body}}};async function a(e,t){let n=Number(e.headers.get(`content-length`));if(Number.isFinite(n)&&n>t)throw Error(`Response exceeds ${t} bytes (content-length ${n})`);let r=e.body;if(!r)return e.arrayBuffer();let i=r.getReader(),a=[],o=0;for(;;){let{done:e,value:n}=await i.read();if(e)break;if(o+=n.byteLength,o>t)throw await i.cancel().catch(()=>{}),Error(`Response exceeds ${t} bytes`);a.push(n)}let s=new Uint8Array(o),c=0;for(let e of a)s.set(e,c),c+=e.byteLength;return s.buffer}const o=2097152,s=1048576;var c=class e{static byFetch=new WeakMap;entries=new Map;bytes=0;static forFetch(t){let n=this.byFetch.get(t);return n||(n=new e,this.byFetch.set(t,n)),n}get(e){let t=this.entries.get(e);return t&&(this.entries.delete(e),this.entries.set(e,t)),t?.pending}set(e,t){this.delete(e);let n={pending:t,bytes:e.length*2};this.entries.set(e,n),this.bytes+=n.bytes,this.trim(),t.then(t=>{this.entries.get(e)===n&&(n.bytes+=t.length*2,this.bytes+=t.length*2,n.bytes>s&&this.delete(e),this.trim())},()=>{this.entries.get(e)===n&&this.delete(e)})}delete(e){let t=this.entries.get(e);t&&(this.bytes-=t.bytes,this.entries.delete(e))}trim(){for(let e of this.entries.keys()){if(this.entries.size<=64&&this.bytes<=s)break;this.delete(e)}}static read(e,t){return r(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=>a(e,t.maxBytes??o)).then(e=>new TextDecoder().decode(e))}static load(e,t){if(t.signal?.throwIfAborted(),t.signal||t.allowUrl)return this.read(e,t);let n=t.cache??this.forFetch(t.fetch??globalThis.fetch),r=n.get(e);if(r)return r.then(e=>{let n=t.maxBytes??o;if(new TextEncoder().encode(e).byteLength>n)throw Error(`Response exceeds ${n} bytes`);return e});let i=this.read(e,t);return n.set(e,i),t.cache&&i.catch(()=>{n.get(e)===i&&n.delete(e)}),i}};function l(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 u(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`,l(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`,l(n.name,r,a,o))}return e.display&&t.searchParams.set(`display`,e.display),t.toString()}const d=/(?:\/\*\s*([^*]+?)\s*\*\/\s*)?@font-face\s*\{([^}]*)\}/g;function f(e,t,n){let i=`${e.family} ${e.subset}`,o=e.ranges.map(([e,t])=>`${e}-${t}`).join(`,`);return{name:i,subsetOf:e.family,subsetRank:p(e.ranges),key:`${i}:${e.weight??``}:${e.style??``}:${o}:${n??``}`,weight:e.weight,style:e.style,ranges:e.ranges,generic:n,data:()=>r(e.url,t).then(e=>a(e,t.maxBytes??33554432))}}function p(e){return e.length===0?4294967295:Math.min(...e.map(([e])=>e))}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(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?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=>{typeof e==`string`?n(e):e.type===`text`?n(e.text):e.type===`container`&&e.children?.forEach(r)};return 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,t={}){return{key:e,data:()=>r(e,t).then(e=>a(e,t.maxBytes??33554432))}}async function x(e){if(Array.isArray(e)&&(e={families:e}),e.families.length===0)return[];let t=await c.load(u(e),e),n=new Map(e.families.map((e,t)=>[typeof e==`string`?e:e.name,t])),r=new Map(e.families.flatMap(e=>typeof e==`string`||!e.generic?[]:[[e.name,e.generic]]));return g(h(t)).sort((e,t)=>(n.get(e.family)??0)-(n.get(t.family)??0)).map(t=>f(t,e,r.get(t.family)))}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return 33554432}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return`•◦■▪▸◂▾ 0123456789.-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`}});
@@ -1,4 +1,4 @@
1
- import { c as Node } from "./types-BWYDTgEO.mjs";
1
+ import { c as Node } from "./types-XYUVkGQq.cjs";
2
2
  //#region src/google-fonts-catalog.d.ts
3
3
  interface GoogleFontShapes {
4
4
  S0: {
@@ -917,13 +917,13 @@ interface GoogleFontShapeFamilies {
917
917
  S151: "Zen Old Mincho";
918
918
  }
919
919
  //#endregion
920
- //#region src/utils.d.ts
920
+ //#region src/fetch.d.ts
921
921
  declare const defaultMaxFetchBytes: number;
922
922
  type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
923
923
  type FetchOptions = {
924
924
  /** Custom fetch implementation. @default globalThis.fetch */
925
925
  fetch?: FetchLike;
926
- /** Abort the request after this many milliseconds; `0` or negative disables it. @default 30000 */
926
+ /** Total request timeout, including retries; `0` or negative disables it. @default 30000 */
927
927
  timeout?: number;
928
928
  /** Caller abort signal, combined with the timeout. */
929
929
  signal?: AbortSignal;
@@ -938,40 +938,6 @@ declare function fetchOk(url: string, options?: FetchOptions & {
938
938
  }): Promise<Response>;
939
939
  /** Reads a response body, rejecting once it exceeds `maxBytes` (by content-length or streamed size). */
940
940
  declare function readBodyLimited(response: Response, maxBytes: number): Promise<ArrayBuffer>;
941
- /**
942
- * A cache of image fetches keyed by URL. Sharing one across renders deduplicates concurrent
943
- * requests for the same URL (single-flight) and reuses their bytes. Any object with `Map`-like
944
- * `get`/`set`/`delete` works, so LRU/TTL policies can be plugged in.
945
- */
946
- interface ImageFetchCache {
947
- get(url: string): Promise<ArrayBuffer> | undefined;
948
- set(url: string, data: Promise<ArrayBuffer>): unknown;
949
- delete(url: string): unknown;
950
- }
951
- /** A fetched image entry: its source URL and raw bytes. */
952
- interface FetchedImage {
953
- src: string;
954
- data: ArrayBuffer;
955
- }
956
- type PrepareImagesOptions<T extends {
957
- src: string;
958
- } = FetchedImage> = FetchOptions & {
959
- /** The node tree(s) whose remote images to fetch. */
960
- node: Node | Node[];
961
- /** Pre-fetched entries; their URLs are not re-fetched. */
962
- sources?: T[];
963
- /** Single-flight byte cache shared across renders. */
964
- fetchCache?: ImageFetchCache;
965
- /** Throw on any fetch failure; if `false`, failed URLs are dropped. @default true */
966
- throwOnError?: boolean;
967
- };
968
- /**
969
- * Collects every remote image a node tree references, fetches the ones not already in `sources`,
970
- * and returns them as entries ready to hand to a renderer.
971
- */
972
- declare function prepareImages<T extends {
973
- src: string;
974
- } = FetchedImage>({ node, sources, fetchCache, fetch, timeout, signal, maxBytes, allowUrl, throwOnError }: PrepareImagesOptions<T>): Promise<(T | FetchedImage)[]>;
975
941
  //#endregion
976
942
  //#region src/fonts.d.ts
977
943
  type FontStyle = "normal" | "italic";
@@ -1009,12 +975,7 @@ type GoogleFontsOptions = FetchOptions & {
1009
975
  families: GoogleFontFamily[];
1010
976
  /** `font-display` strategy passed through to the CSS request. */
1011
977
  display?: "auto" | "block" | "swap" | "fallback" | "optional";
1012
- /**
1013
- * Cache for the Google Fonts CSS, keyed by request URL, so the metadata is fetched once across
1014
- * renders (e.g. a playground re-rendering on each edit). Holds the in-flight promise, so
1015
- * concurrent calls share one request; failures evict themselves. Defaults to a process-wide
1016
- * cache; pass your own `Map` to scope it, or a fresh one per call to opt out.
1017
- */
978
+ /** CSS promise cache; defaults to a bounded cache per fetch implementation. Signals and URL policies bypass caching. */
1018
979
  cache?: Pick<Map<string, Promise<string>>, "get" | "set" | "delete">;
1019
980
  /**
1020
981
  * css2 base URL. Defaults to Google Fonts; point it at an API-compatible mirror like
@@ -1086,4 +1047,4 @@ declare function fontFromUrl(url: string, options?: FetchOptions): {
1086
1047
  */
1087
1048
  declare function googleFonts(options: GoogleFontsOptions | GoogleFontFamily[]): Promise<FontSubset[]>;
1088
1049
  //#endregion
1089
- export { fetchOk as _, GoogleFontsOptions as a, fontFromUrl as c, FetchLike as d, FetchOptions as f, defaultMaxFetchBytes as g, PrepareImagesOptions as h, GoogleFontFamily as i, googleFonts as l, ImageFetchCache as m, FontSubset as n, LIST_MARKER_CHARACTERS as o, FetchedImage as p, GenericFontFamily as r, collectCodepoints as s, CodepointSource as t, subsetFonts as u, prepareImages as v, readBodyLimited as y };
1050
+ export { GoogleFontsOptions as a, fontFromUrl as c, FetchLike as d, FetchOptions as f, readBodyLimited as h, GoogleFontFamily as i, googleFonts as l, fetchOk as m, FontSubset as n, LIST_MARKER_CHARACTERS as o, defaultMaxFetchBytes as p, GenericFontFamily as r, collectCodepoints as s, CodepointSource as t, subsetFonts as u };
@@ -0,0 +1 @@
1
+ var e=class{signal;constructor(e,t){let n=e.timeout??3e4,r=[e.signal,t,n<=0?void 0:AbortSignal.timeout(n)].filter(e=>e!=null);this.signal=r.length?AbortSignal.any(r):void 0}waitFor(e){let t=this.signal;return t?new Promise((n,r)=>{function i(){t?.removeEventListener(`abort`,i),r(t?.reason)}t.addEventListener(`abort`,i,{once:!0}),e.then(e=>{t.removeEventListener(`abort`,i),n(e)},e=>{t.removeEventListener(`abort`,i),r(e)}),t.aborted&&i()}):e}};const t=new Set([301,302,303,307,308]),n=new Set([408,429,500,502,503,504]),r=33554432;async function i(e,t={}){return new a(e,t).send()}var a=class r{url;allowUrl;fetchImpl;init;constructor(t,n){if(n.allowUrl&&!n.allowUrl(t))throw Error(`URL blocked by allowUrl policy: ${t}`);this.url=t,this.allowUrl=n.allowUrl,this.fetchImpl=n.fetch??globalThis.fetch,this.init={...n.init,signal:new e(n,n.init?.signal).signal}}async send(){let e=this.allowUrl?await this.followRedirects(this.allowUrl):await this.attempt(this.url,this.init);if(!e.ok)throw Error(`HTTP ${e.status} ${e.statusText} fetching ${this.url}`);return e}async attempt(e,t){let r=t.method?.toUpperCase()??`GET`,i=r===`GET`||r===`HEAD`;for(let r=0;;r++){t.signal?.throwIfAborted();let a=100*2**r;try{let o=await this.fetchImpl.call(void 0,e,t);if(t.signal?.throwIfAborted(),!i||r===2||!n.has(o.status))return o;let s=o.headers.get(`retry-after`);if(s!==null){let e=Number(s),t=Number.isFinite(e)?e*1e3:Date.parse(s)-Date.now();Number.isFinite(t)&&(a=Math.max(a,t))}if(a>1e3)return o;o.body?.cancel().catch(()=>{})}catch(e){if(t.signal?.throwIfAborted(),!i||r===2||!(e instanceof Error)||e.name!==`TypeError`&&e.name!==`TimeoutError`)throw e}await this.wait(a)}}wait(e){let t=this.init.signal;return t?.throwIfAborted(),new Promise((n,r)=>{let i=setTimeout(()=>{t?.removeEventListener(`abort`,a),n()},e);function a(){clearTimeout(i),r(t?.reason)}t?.addEventListener(`abort`,a,{once:!0})})}async followRedirects(e){let n=this.url,i={...this.init,headers:new Headers(this.init.headers),redirect:`manual`};for(let a=0;a<5;a++){let a=await this.attempt(n,i),o=a.headers.get(`location`);if(!t.has(a.status)||o===null)return a;await a.body?.cancel().catch(()=>{});let s=new URL(o,n);if(!e(s.href))throw Error(`URL blocked by allowUrl policy: ${s.href}`);if(s.protocol!==`https:`&&s.protocol!==`http:`||s.username||s.password)throw Error(`Invalid redirect URL: ${s.href}`);i=r.redirectInit(i,a.status,n,s),n=s.href}throw Error(`Too many redirects fetching ${this.url}`)}static redirectInit(e,t,n,r){if(t!==303&&e.body instanceof ReadableStream)throw Error(`Cannot replay a streamed request body after a redirect`);let i=new Headers(e.headers),a=e.method?.toUpperCase()??`GET`,o=(t===301||t===302)&&a===`POST`||t===303&&a!==`GET`&&a!==`HEAD`;if(o)for(let e of[`content-encoding`,`content-language`,`content-location`,`content-type`,`content-length`])i.delete(e);if(new URL(n).origin!==r.origin)for(let e of[`authorization`,`proxy-authorization`,`cookie`,`cookie2`])i.delete(e);return{...e,headers:i,method:o?`GET`:e.method,body:o?void 0:e.body}}};async function o(e,t){let n=Number(e.headers.get(`content-length`));if(Number.isFinite(n)&&n>t)throw Error(`Response exceeds ${t} bytes (content-length ${n})`);let r=e.body;if(!r)return e.arrayBuffer();let i=r.getReader(),a=[],o=0;for(;;){let{done:e,value:n}=await i.read();if(e)break;if(o+=n.byteLength,o>t)throw await i.cancel().catch(()=>{}),Error(`Response exceeds ${t} bytes`);a.push(n)}let s=new Uint8Array(o),c=0;for(let e of a)s.set(e,c),c+=e.byteLength;return s.buffer}const s=2097152,c=1048576;var l=class e{static byFetch=new WeakMap;entries=new Map;bytes=0;static forFetch(t){let n=this.byFetch.get(t);return n||(n=new e,this.byFetch.set(t,n)),n}get(e){let t=this.entries.get(e);return t&&(this.entries.delete(e),this.entries.set(e,t)),t?.pending}set(e,t){this.delete(e);let n={pending:t,bytes:e.length*2};this.entries.set(e,n),this.bytes+=n.bytes,this.trim(),t.then(t=>{this.entries.get(e)===n&&(n.bytes+=t.length*2,this.bytes+=t.length*2,n.bytes>c&&this.delete(e),this.trim())},()=>{this.entries.get(e)===n&&this.delete(e)})}delete(e){let t=this.entries.get(e);t&&(this.bytes-=t.bytes,this.entries.delete(e))}trim(){for(let e of this.entries.keys()){if(this.entries.size<=64&&this.bytes<=c)break;this.delete(e)}}static read(e,t){return i(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=>o(e,t.maxBytes??s)).then(e=>new TextDecoder().decode(e))}static load(e,t){if(t.signal?.throwIfAborted(),t.signal||t.allowUrl)return this.read(e,t);let n=t.cache??this.forFetch(t.fetch??globalThis.fetch),r=n.get(e);if(r)return r.then(e=>{let n=t.maxBytes??s;if(new TextEncoder().encode(e).byteLength>n)throw Error(`Response exceeds ${n} bytes`);return e});let i=this.read(e,t);return n.set(e,i),t.cache&&i.catch(()=>{n.get(e)===i&&n.delete(e)}),i}};function u(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 d(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`,u(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`,u(n.name,r,a,o))}return e.display&&t.searchParams.set(`display`,e.display),t.toString()}const f=/(?:\/\*\s*([^*]+?)\s*\*\/\s*)?@font-face\s*\{([^}]*)\}/g;function p(e,t,n){let r=`${e.family} ${e.subset}`,a=e.ranges.map(([e,t])=>`${e}-${t}`).join(`,`);return{name:r,subsetOf:e.family,subsetRank:m(e.ranges),key:`${r}:${e.weight??``}:${e.style??``}:${a}:${n??``}`,weight:e.weight,style:e.style,ranges:e.ranges,generic:n,data:()=>i(e.url,t).then(e=>o(e,t.maxBytes??33554432))}}function m(e){return e.length===0?4294967295:Math.min(...e.map(([e])=>e))}function h(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 g(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?h(o):[]}),n+=1}return t}function _(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}const v=`•◦■▪▸◂▾ 0123456789.-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`;function y(e){let t=new Set,n=e=>{for(let n of e)t.add(n.codePointAt(0))},r=e=>{typeof e==`string`?n(e):e.type===`text`?n(e.text):e.type===`container`&&e.children?.forEach(r)};return Array.isArray(e)?e.forEach(r):r(e),t}function b(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 x({fonts:e,source:t}){let n=y(t);return e.filter(e=>b(e.ranges??[],n))}function S(e,t={}){return{key:e,data:()=>i(e,t).then(e=>o(e,t.maxBytes??33554432))}}async function C(e){if(Array.isArray(e)&&(e={families:e}),e.families.length===0)return[];let t=await l.load(d(e),e),n=new Map(e.families.map((e,t)=>[typeof e==`string`?e:e.name,t])),r=new Map(e.families.flatMap(e=>typeof e==`string`||!e.generic?[]:[[e.name,e.generic]]));return _(g(t)).sort((e,t)=>(n.get(e.family)??0)-(n.get(t.family)??0)).map(t=>p(t,e,r.get(t.family)))}export{x as a,o as c,C as i,e as l,y as n,r as o,S as r,i as s,v as t};
@@ -1,4 +1,4 @@
1
- import { c as Node } from "./types-BWYDTgEO.cjs";
1
+ import { c as Node } from "./types-XYUVkGQq.mjs";
2
2
  //#region src/google-fonts-catalog.d.ts
3
3
  interface GoogleFontShapes {
4
4
  S0: {
@@ -917,13 +917,13 @@ interface GoogleFontShapeFamilies {
917
917
  S151: "Zen Old Mincho";
918
918
  }
919
919
  //#endregion
920
- //#region src/utils.d.ts
920
+ //#region src/fetch.d.ts
921
921
  declare const defaultMaxFetchBytes: number;
922
922
  type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
923
923
  type FetchOptions = {
924
924
  /** Custom fetch implementation. @default globalThis.fetch */
925
925
  fetch?: FetchLike;
926
- /** Abort the request after this many milliseconds; `0` or negative disables it. @default 30000 */
926
+ /** Total request timeout, including retries; `0` or negative disables it. @default 30000 */
927
927
  timeout?: number;
928
928
  /** Caller abort signal, combined with the timeout. */
929
929
  signal?: AbortSignal;
@@ -938,40 +938,6 @@ declare function fetchOk(url: string, options?: FetchOptions & {
938
938
  }): Promise<Response>;
939
939
  /** Reads a response body, rejecting once it exceeds `maxBytes` (by content-length or streamed size). */
940
940
  declare function readBodyLimited(response: Response, maxBytes: number): Promise<ArrayBuffer>;
941
- /**
942
- * A cache of image fetches keyed by URL. Sharing one across renders deduplicates concurrent
943
- * requests for the same URL (single-flight) and reuses their bytes. Any object with `Map`-like
944
- * `get`/`set`/`delete` works, so LRU/TTL policies can be plugged in.
945
- */
946
- interface ImageFetchCache {
947
- get(url: string): Promise<ArrayBuffer> | undefined;
948
- set(url: string, data: Promise<ArrayBuffer>): unknown;
949
- delete(url: string): unknown;
950
- }
951
- /** A fetched image entry: its source URL and raw bytes. */
952
- interface FetchedImage {
953
- src: string;
954
- data: ArrayBuffer;
955
- }
956
- type PrepareImagesOptions<T extends {
957
- src: string;
958
- } = FetchedImage> = FetchOptions & {
959
- /** The node tree(s) whose remote images to fetch. */
960
- node: Node | Node[];
961
- /** Pre-fetched entries; their URLs are not re-fetched. */
962
- sources?: T[];
963
- /** Single-flight byte cache shared across renders. */
964
- fetchCache?: ImageFetchCache;
965
- /** Throw on any fetch failure; if `false`, failed URLs are dropped. @default true */
966
- throwOnError?: boolean;
967
- };
968
- /**
969
- * Collects every remote image a node tree references, fetches the ones not already in `sources`,
970
- * and returns them as entries ready to hand to a renderer.
971
- */
972
- declare function prepareImages<T extends {
973
- src: string;
974
- } = FetchedImage>({ node, sources, fetchCache, fetch, timeout, signal, maxBytes, allowUrl, throwOnError }: PrepareImagesOptions<T>): Promise<(T | FetchedImage)[]>;
975
941
  //#endregion
976
942
  //#region src/fonts.d.ts
977
943
  type FontStyle = "normal" | "italic";
@@ -1009,12 +975,7 @@ type GoogleFontsOptions = FetchOptions & {
1009
975
  families: GoogleFontFamily[];
1010
976
  /** `font-display` strategy passed through to the CSS request. */
1011
977
  display?: "auto" | "block" | "swap" | "fallback" | "optional";
1012
- /**
1013
- * Cache for the Google Fonts CSS, keyed by request URL, so the metadata is fetched once across
1014
- * renders (e.g. a playground re-rendering on each edit). Holds the in-flight promise, so
1015
- * concurrent calls share one request; failures evict themselves. Defaults to a process-wide
1016
- * cache; pass your own `Map` to scope it, or a fresh one per call to opt out.
1017
- */
978
+ /** CSS promise cache; defaults to a bounded cache per fetch implementation. Signals and URL policies bypass caching. */
1018
979
  cache?: Pick<Map<string, Promise<string>>, "get" | "set" | "delete">;
1019
980
  /**
1020
981
  * css2 base URL. Defaults to Google Fonts; point it at an API-compatible mirror like
@@ -1086,4 +1047,4 @@ declare function fontFromUrl(url: string, options?: FetchOptions): {
1086
1047
  */
1087
1048
  declare function googleFonts(options: GoogleFontsOptions | GoogleFontFamily[]): Promise<FontSubset[]>;
1088
1049
  //#endregion
1089
- export { fetchOk as _, GoogleFontsOptions as a, fontFromUrl as c, FetchLike as d, FetchOptions as f, defaultMaxFetchBytes as g, PrepareImagesOptions as h, GoogleFontFamily as i, googleFonts as l, ImageFetchCache as m, FontSubset as n, LIST_MARKER_CHARACTERS as o, FetchedImage as p, GenericFontFamily as r, collectCodepoints as s, CodepointSource as t, subsetFonts as u, prepareImages as v, readBodyLimited as y };
1050
+ export { GoogleFontsOptions as a, fontFromUrl as c, FetchLike as d, FetchOptions as f, readBodyLimited as h, GoogleFontFamily as i, googleFonts as l, fetchOk as m, FontSubset as n, LIST_MARKER_CHARACTERS as o, defaultMaxFetchBytes as p, GenericFontFamily as r, collectCodepoints as s, CodepointSource as t, subsetFonts as u };
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-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={"&":`&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:[],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:`
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={"&":`&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):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
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;
package/dist/html.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { c as Node } from "./types-BWYDTgEO.cjs";
1
+ import { c as Node } from "./types-XYUVkGQq.cjs";
2
2
  //#region src/html/index.d.ts
3
3
  interface FromHtmlResult {
4
4
  node: Node;
package/dist/html.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { c as Node } from "./types-BWYDTgEO.mjs";
1
+ import { c as Node } from "./types-XYUVkGQq.mjs";
2
2
  //#region src/html/index.d.ts
3
3
  interface FromHtmlResult {
4
4
  node: Node;
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{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={"&":`&amp;`,"<":`&lt;`,">":`&gt;`};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}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:`
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={"&":`&amp;`,"<":`&lt;`,">":`&gt;`};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
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};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./fonts-D-2FIgft.cjs"),t=require("./helpers-4kGcvc-Q.cjs");exports.LIST_MARKER_CHARACTERS=e.t,exports.collectCodepoints=e.n,exports.container=t.t,exports.defaultMaxFetchBytes=e.o,exports.em=t.n,exports.fetchOk=e.s,exports.fontFromUrl=e.r,exports.fr=t.r,exports.googleFonts=e.i,exports.image=t.i,exports.percentage=t.a,exports.prepareImages=e.c,exports.readBodyLimited=e.l,exports.rem=t.o,exports.rgba=t.s,exports.style=t.c,exports.subsetFonts=e.a,exports.text=t.l,exports.vh=t.u,exports.vw=t.d;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./fonts-B-pwvIqE.cjs"),t=require("./helpers-4kGcvc-Q.cjs"),n=/url\(\s*(['"]?)(.*?)\1\s*\)/g;function r(e){return e.startsWith(`https://`)||e.startsWith(`http://`)}function i(e,t){if(typeof e==`string`)for(let i of e.matchAll(n)){let e=i[2]?.trim();e&&r(e)&&t.add(e)}else if(Array.isArray(e))for(let n of e)i(n,t)}function a(e){let t=new Set,n=e=>{let a=e=>{e&&(i(e.backgroundImage,t),i(e.maskImage,t),i(e.listStyleImage,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(t,n,r){let i=n.maxBytes??33554432,{allowUrl:a}=n,o=r?.get(t);if(o)return new e.l(n).waitFor(o).then(e=>{if(a&&!a(t))throw Error(`URL blocked by allowUrl policy: ${t}`);if(e.byteLength>i)throw Error(`Response exceeds ${i} bytes`);return e});let s=e.s(t,n).then(t=>e.c(t,i)).catch(e=>{throw r?.delete(t),e});return r?.set(t,s),s}async function s({node:e,sources:t=[],fetchCache:n,fetch:r,timeout:i,signal:s,maxBytes:c,allowUrl:l,throwOnError:u=!0}){let d=Array.isArray(e)?e:[e],f=new Map;for(let e of t)f.set(e.src,e);let p=[...new Set(d.flatMap(a))].filter(e=>!f.has(e)),m={fetch:r,timeout:i,signal:s,maxBytes:c,allowUrl:l},h=p.map(async e=>({src:e,data:await o(e,m,n)})),g=u?await Promise.all(h):(await Promise.allSettled(h)).filter(e=>e.status===`fulfilled`).map(e=>e.value);return[...f.values(),...g]}exports.LIST_MARKER_CHARACTERS=e.t,exports.collectCodepoints=e.n,exports.container=t.t,exports.defaultMaxFetchBytes=e.o,exports.em=t.n,exports.fetchOk=e.s,exports.fontFromUrl=e.r,exports.fr=t.r,exports.googleFonts=e.i,exports.image=t.i,exports.percentage=t.a,exports.prepareImages=s,exports.readBodyLimited=e.c,exports.rem=t.o,exports.rgba=t.s,exports.style=t.c,exports.subsetFonts=e.a,exports.text=t.l,exports.vh=t.u,exports.vw=t.d;
package/dist/index.d.cts CHANGED
@@ -1,12 +1,11 @@
1
- import { a as ImageNode, c as Node, d as ReactElementLike, f as RgbaImage, g as TextNode, h as TextFit, i as Declarations, l as NodeAttributes, m as SupportsRule, n as ContainerNode, o as LayerRule, p as StyleRule, r as CssInput, s as MediaRule, t as AnimationRule, u as NodeMetadata } from "./types-BWYDTgEO.cjs";
2
- import { _ as fetchOk, a as GoogleFontsOptions, c as fontFromUrl, d as FetchLike, f as FetchOptions, g as defaultMaxFetchBytes, h as PrepareImagesOptions, i as GoogleFontFamily, l as googleFonts, m as ImageFetchCache, n as FontSubset, o as LIST_MARKER_CHARACTERS, p as FetchedImage, r as GenericFontFamily, s as collectCodepoints, t as CodepointSource, u as subsetFonts, v as prepareImages, y as readBodyLimited } from "./fonts-DJzerTBP.cjs";
3
- import { CSSProperties } from "react";
1
+ import { a as ImageNode, c as Node, d as ReactElementLike, f as RgbaImage, g as TextNode, h as TextFit, i as Declarations, l as NodeAttributes, m as SupportsRule, n as ContainerNode, o as LayerRule, p as StyleRule, r as CssInput, s as MediaRule, t as AnimationRule, u as NodeMetadata } from "./types-XYUVkGQq.cjs";
2
+ import { a as GoogleFontsOptions, c as fontFromUrl, d as FetchLike, f as FetchOptions, h as readBodyLimited, i as GoogleFontFamily, l as googleFonts, m as fetchOk, n as FontSubset, o as LIST_MARKER_CHARACTERS, p as defaultMaxFetchBytes, r as GenericFontFamily, s as collectCodepoints, t as CodepointSource, u as subsetFonts } from "./fonts-BrUiG8am.cjs";
4
3
  //#region src/helpers.d.ts
5
4
  declare function container(props: Omit<ContainerNode, "type">): ContainerNode;
6
- declare function text(text: string, style?: CSSProperties): TextNode;
5
+ declare function text(text: string, style?: Declarations): TextNode;
7
6
  declare function text(props: Omit<TextNode, "type">): TextNode;
8
7
  declare function image(props: Omit<ImageNode, "type">): ImageNode;
9
- declare function style(style: CSSProperties): CSSProperties;
8
+ declare function style(style: Declarations): import("react").CSSProperties;
10
9
  declare function percentage(percentage: number): `${number}%`;
11
10
  declare function vw(vw: number): `${number}vw`;
12
11
  declare function vh(vh: number): `${number}vh`;
@@ -15,4 +14,40 @@ declare function rem(rem: number): `${number}rem`;
15
14
  declare function fr(fr: number): `${number}fr`;
16
15
  declare function rgba(r: number, g: number, b: number, a?: number): `rgb(${number} ${number} ${number} / ${number})`;
17
16
  //#endregion
17
+ //#region src/images.d.ts
18
+ /**
19
+ * A cache of image fetches keyed by URL. Sharing one across renders deduplicates concurrent
20
+ * requests for the same URL (single-flight) and reuses their bytes. Any object with `Map`-like
21
+ * `get`/`set`/`delete` works, so LRU/TTL policies can be plugged in.
22
+ */
23
+ interface ImageFetchCache {
24
+ get(url: string): Promise<ArrayBuffer> | undefined;
25
+ set(url: string, data: Promise<ArrayBuffer>): unknown;
26
+ delete(url: string): unknown;
27
+ }
28
+ /** A fetched image entry: its source URL and raw bytes. */
29
+ interface FetchedImage {
30
+ src: string;
31
+ data: ArrayBuffer;
32
+ }
33
+ type PrepareImagesOptions<T extends {
34
+ src: string;
35
+ } = FetchedImage> = FetchOptions & {
36
+ /** The node tree(s) whose remote images to fetch. */
37
+ node: Node | Node[];
38
+ /** Pre-fetched entries; their URLs are not re-fetched. */
39
+ sources?: T[];
40
+ /** Single-flight byte cache shared across renders. */
41
+ fetchCache?: ImageFetchCache;
42
+ /** Throw on any fetch failure; if `false`, failed URLs are dropped. @default true */
43
+ throwOnError?: boolean;
44
+ };
45
+ /**
46
+ * Collects every remote image a node tree references, fetches the ones not already in `sources`,
47
+ * and returns them as entries ready to hand to a renderer.
48
+ */
49
+ declare function prepareImages<T extends {
50
+ src: string;
51
+ } = FetchedImage>({ node, sources, fetchCache, fetch, timeout, signal, maxBytes, allowUrl, throwOnError }: PrepareImagesOptions<T>): Promise<(T | FetchedImage)[]>;
52
+ //#endregion
18
53
  export { AnimationRule, CodepointSource, ContainerNode, CssInput, Declarations, FetchLike, FetchOptions, FetchedImage, FontSubset, GenericFontFamily, GoogleFontFamily, GoogleFontsOptions, ImageFetchCache, ImageNode, LIST_MARKER_CHARACTERS, LayerRule, MediaRule, Node, NodeAttributes, NodeMetadata, PrepareImagesOptions, ReactElementLike, RgbaImage, StyleRule, SupportsRule, TextFit, TextNode, collectCodepoints, container, defaultMaxFetchBytes, em, fetchOk, fontFromUrl, fr, googleFonts, image, percentage, prepareImages, readBodyLimited, rem, rgba, style, subsetFonts, text, vh, vw };
package/dist/index.d.mts CHANGED
@@ -1,12 +1,11 @@
1
- import { a as ImageNode, c as Node, d as ReactElementLike, f as RgbaImage, g as TextNode, h as TextFit, i as Declarations, l as NodeAttributes, m as SupportsRule, n as ContainerNode, o as LayerRule, p as StyleRule, r as CssInput, s as MediaRule, t as AnimationRule, u as NodeMetadata } from "./types-BWYDTgEO.mjs";
2
- import { _ as fetchOk, a as GoogleFontsOptions, c as fontFromUrl, d as FetchLike, f as FetchOptions, g as defaultMaxFetchBytes, h as PrepareImagesOptions, i as GoogleFontFamily, l as googleFonts, m as ImageFetchCache, n as FontSubset, o as LIST_MARKER_CHARACTERS, p as FetchedImage, r as GenericFontFamily, s as collectCodepoints, t as CodepointSource, u as subsetFonts, v as prepareImages, y as readBodyLimited } from "./fonts-BV8jtksq.mjs";
3
- import { CSSProperties } from "react";
1
+ import { a as ImageNode, c as Node, d as ReactElementLike, f as RgbaImage, g as TextNode, h as TextFit, i as Declarations, l as NodeAttributes, m as SupportsRule, n as ContainerNode, o as LayerRule, p as StyleRule, r as CssInput, s as MediaRule, t as AnimationRule, u as NodeMetadata } from "./types-XYUVkGQq.mjs";
2
+ import { a as GoogleFontsOptions, c as fontFromUrl, d as FetchLike, f as FetchOptions, h as readBodyLimited, i as GoogleFontFamily, l as googleFonts, m as fetchOk, n as FontSubset, o as LIST_MARKER_CHARACTERS, p as defaultMaxFetchBytes, r as GenericFontFamily, s as collectCodepoints, t as CodepointSource, u as subsetFonts } from "./fonts-Du-K60HL.mjs";
4
3
  //#region src/helpers.d.ts
5
4
  declare function container(props: Omit<ContainerNode, "type">): ContainerNode;
6
- declare function text(text: string, style?: CSSProperties): TextNode;
5
+ declare function text(text: string, style?: Declarations): TextNode;
7
6
  declare function text(props: Omit<TextNode, "type">): TextNode;
8
7
  declare function image(props: Omit<ImageNode, "type">): ImageNode;
9
- declare function style(style: CSSProperties): CSSProperties;
8
+ declare function style(style: Declarations): import("react").CSSProperties;
10
9
  declare function percentage(percentage: number): `${number}%`;
11
10
  declare function vw(vw: number): `${number}vw`;
12
11
  declare function vh(vh: number): `${number}vh`;
@@ -15,4 +14,40 @@ declare function rem(rem: number): `${number}rem`;
15
14
  declare function fr(fr: number): `${number}fr`;
16
15
  declare function rgba(r: number, g: number, b: number, a?: number): `rgb(${number} ${number} ${number} / ${number})`;
17
16
  //#endregion
17
+ //#region src/images.d.ts
18
+ /**
19
+ * A cache of image fetches keyed by URL. Sharing one across renders deduplicates concurrent
20
+ * requests for the same URL (single-flight) and reuses their bytes. Any object with `Map`-like
21
+ * `get`/`set`/`delete` works, so LRU/TTL policies can be plugged in.
22
+ */
23
+ interface ImageFetchCache {
24
+ get(url: string): Promise<ArrayBuffer> | undefined;
25
+ set(url: string, data: Promise<ArrayBuffer>): unknown;
26
+ delete(url: string): unknown;
27
+ }
28
+ /** A fetched image entry: its source URL and raw bytes. */
29
+ interface FetchedImage {
30
+ src: string;
31
+ data: ArrayBuffer;
32
+ }
33
+ type PrepareImagesOptions<T extends {
34
+ src: string;
35
+ } = FetchedImage> = FetchOptions & {
36
+ /** The node tree(s) whose remote images to fetch. */
37
+ node: Node | Node[];
38
+ /** Pre-fetched entries; their URLs are not re-fetched. */
39
+ sources?: T[];
40
+ /** Single-flight byte cache shared across renders. */
41
+ fetchCache?: ImageFetchCache;
42
+ /** Throw on any fetch failure; if `false`, failed URLs are dropped. @default true */
43
+ throwOnError?: boolean;
44
+ };
45
+ /**
46
+ * Collects every remote image a node tree references, fetches the ones not already in `sources`,
47
+ * and returns them as entries ready to hand to a renderer.
48
+ */
49
+ declare function prepareImages<T extends {
50
+ src: string;
51
+ } = FetchedImage>({ node, sources, fetchCache, fetch, timeout, signal, maxBytes, allowUrl, throwOnError }: PrepareImagesOptions<T>): Promise<(T | FetchedImage)[]>;
52
+ //#endregion
18
53
  export { AnimationRule, CodepointSource, ContainerNode, CssInput, Declarations, FetchLike, FetchOptions, FetchedImage, FontSubset, GenericFontFamily, GoogleFontFamily, GoogleFontsOptions, ImageFetchCache, ImageNode, LIST_MARKER_CHARACTERS, LayerRule, MediaRule, Node, NodeAttributes, NodeMetadata, PrepareImagesOptions, ReactElementLike, RgbaImage, StyleRule, SupportsRule, TextFit, TextNode, collectCodepoints, container, defaultMaxFetchBytes, em, fetchOk, fontFromUrl, fr, googleFonts, image, percentage, prepareImages, readBodyLimited, rem, rgba, style, subsetFonts, text, vh, vw };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{a as e,c as t,i as n,l as r,n as i,o as a,r as o,s,t as c}from"./fonts-RWAcijal.mjs";import{a as l,c as u,d,i as f,l as p,n as m,o as h,r as g,s as _,t as v,u as y}from"./helpers-CVQCT1Rh.mjs";export{c as LIST_MARKER_CHARACTERS,i as collectCodepoints,v as container,a as defaultMaxFetchBytes,m as em,s as fetchOk,o as fontFromUrl,g as fr,n as googleFonts,f as image,l as percentage,t as prepareImages,r as readBodyLimited,h as rem,_ as rgba,u as style,e as subsetFonts,p as text,y as vh,d as vw};
1
+ import{a as e,c as t,i as n,l as r,n as i,o as a,r as o,s,t as c}from"./fonts-CBLz8Mte.mjs";import{a as l,c as u,d,i as f,l as p,n as m,o as h,r as g,s as _,t as v,u as y}from"./helpers-CVQCT1Rh.mjs";const b=/url\(\s*(['"]?)(.*?)\1\s*\)/g;function x(e){return e.startsWith(`https://`)||e.startsWith(`http://`)}function S(e,t){if(typeof e==`string`)for(let n of e.matchAll(b)){let e=n[2]?.trim();e&&x(e)&&t.add(e)}else if(Array.isArray(e))for(let n of e)S(n,t)}function C(e){let t=new Set,n=e=>{let r=e=>{e&&(S(e.backgroundImage,t),S(e.maskImage,t),S(e.listStyleImage,t))};if(r(e.style),r(e.preset),S(e.tw,t),e.type===`image`){typeof e.src==`string`&&x(e.src)&&t.add(e.src);return}if(e.type===`container`)for(let t of e.children??[])n(t)};return n(e),[...t]}function w(e,n,i){let a=n.maxBytes??33554432,{allowUrl:o}=n,c=i?.get(e);if(c)return new r(n).waitFor(c).then(t=>{if(o&&!o(e))throw Error(`URL blocked by allowUrl policy: ${e}`);if(t.byteLength>a)throw Error(`Response exceeds ${a} bytes`);return t});let l=s(e,n).then(e=>t(e,a)).catch(t=>{throw i?.delete(e),t});return i?.set(e,l),l}async function T({node:e,sources:t=[],fetchCache:n,fetch:r,timeout:i,signal:a,maxBytes:o,allowUrl: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(C))].filter(e=>!u.has(e)),f={fetch:r,timeout:i,signal:a,maxBytes:o,allowUrl:s},p=d.map(async e=>({src:e,data:await w(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]}export{c as LIST_MARKER_CHARACTERS,i as collectCodepoints,v as container,a as defaultMaxFetchBytes,m as em,s as fetchOk,o as fontFromUrl,g as fr,n as googleFonts,f as image,l as percentage,T as prepareImages,t as readBodyLimited,h as rem,_ as rgba,u as style,e as subsetFonts,p as text,y as vh,d as vw};
package/dist/jsx.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");let n;function r(e,t){return typeof e==`object`&&e&&t in e?e[t]:void 0}function i(e){return typeof e==`object`&&!!e&&`then`in e&&typeof e.then==`function`}function a(e){let t=r(e,`__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE`);if(typeof t==`object`&&t&&`H`in t){let e=t;return{get:()=>e.H,set:t=>{e.H=t}}}let n=r(r(e,`__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED`),`ReactCurrentDispatcher`);if(typeof n==`object`&&n&&`current`in n){let e=n;return{get:()=>e.current,set:t=>{e.current=t}}}return null}function o(){return n??=import(`react`).then(e=>a(e.default??e)).catch(()=>null),n}function s(e,t){return e.contexts.has(t)?e.contexts.get(t):r(t,`_currentValue`)}const c=()=>{};function l(e,t){let n=t=>s(e,t),r=0;return{readContext:n,useContext:n,use:e=>{if(i(e)){if(e.status===`fulfilled`)return e.value;throw e.status===`rejected`?e.reason:e}return n(e)},useState:e=>[typeof e==`function`?e():e,c],useReducer:(e,t,n)=>[n?n(t):t,c],useMemo:e=>e(),useCallback:e=>e,useRef:e=>({current:e}),useEffect:c,useLayoutEffect:c,useInsertionEffect:c,useImperativeHandle:c,useDebugValue:c,useDeferredValue:e=>e,useTransition:()=>[!1,c],useOptimistic:e=>[e,c],useActionState:(e,t)=>[t,c,!1],useSyncExternalStore:(e,t,n)=>(n??t)(),useId:()=>`:t${t}-${r++}:`,useCacheRefresh:()=>c,useHostTransitionStatus:()=>({pending:!1,data:null,method:null,action:null})}}async function u(e,t,n){let r=await o();if(!r)return e(t);let a=n.ids.current++;for(let o=0;;o++){let s=r.get();r.set(l(n,a));let c;try{return e(t)}catch(e){c=e}finally{r.set(s)}if(!i(c)||o>=64)throw c;await d(c)}}async function d(e){try{e.value=await e,e.status=`fulfilled`}catch(t){e.reason=t,e.status=`rejected`}}function f(e){return typeof e==`string`||typeof e==`number`}function p(e){return e.replace(/&/g,`&amp;`).replace(/"/g,`&quot;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}function m(e){let n=[];for(let r in e)Object.hasOwn(e,r)&&n.push(`${t.t(r)}:${String(e[r]).trim()}`);return n.join(`;`)}const h=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 g(e,n){if(e===`children`||n==null)return;let r;if(r=e===`className`?`class`:h.has(e)?t.t(e):e,typeof n==`boolean`)return`${r}="${String(n)}"`;if(e===`style`&&typeof n==`object`){let e=m(n);if(e)return`style="${p(e)}"`}return`${r}="${p(String(n))}"`}function _(e,t,n){let r=!1;for(let n in e){if(!Object.hasOwn(e,n))continue;let i=g(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 v=(e,n,r)=>{let i=e.props||{};if(t.n(e.type)){y(e.type(e.props),n,!1);return}if(typeof e.type==`symbol`){y(i.children,n,!1);return}if(t.a(e.type)){y(e.type.render(e.props,null),n,!1);return}if(t.s(e.type)){v({...e,type:e.type.type},n,r);return}if(typeof e.type!=`string`)return;n.push(`<`,e.type),_(i,n,r&&e.type===`svg`);let a=i.children;n.push(`>`),y(a,n,!1),n.push(`</`,e.type,`>`)};function y(e,n,r){if(e!=null&&e!==!1){if(f(e)){n.push(String(e));return}if(Array.isArray(e)){for(let t of e)y(t,n,!1);return}t.c(e)&&v(e,n,r)}}function b(e){let t=[];return y(e,t,!0),t.join(``)}function x({width:e,height:t,data:n,premultiplied:r,...i}){return{type:`img`,props:{...i,src:{width:e,height:t,data:n,premultiplied:r}},key:null}}function S(){return{nodes:[],css:[]}}async function C(n,r){let i=await w(n,{defaultStyles:T(r),presets:t.f(r?.defaultStyles),tailwindClassesProperty:r?.tailwindClassesProperty??`tw`,contexts:new Map,ids:{current:0}}),a=i.nodes,o;o=a.length===0?e.t({}):a.length===1&&a[0]!==void 0?a[0]:e.t({children:a,style:{display:`block`,width:e.a(100),height:e.a(100)}});let s=i.css,c={node:o,css:s,get stylesheets(){return t.u(),s}};return t.l(c),c}async function w(n,r){return n==null||n===!1?S():n instanceof Promise?w(await n,r):typeof n==`object`&&Symbol.iterator in n?K(n,r):t.c(n)?await z(n,r):{nodes:[e.l({text:String(n),preset:r.presets?.span})],css:[]}}function T(e){return e&&`defaultStyles`in e?e.defaultStyles??t.p:t.p}const E=Symbol.for(`react.context`),D=Symbol.for(`react.provider`),O=Symbol.for(`react.consumer`);function k(e,t){let n=e.type;if(typeof n!=`object`||!n)return;let i=r(n,`$$typeof`);if(i===D)return A(e,r(n,`_context`),t);if(i===O)return j(e,r(n,`_context`)??n,t);if(i===E)return typeof P(e)==`function`?j(e,n,t):A(e,n,t)}function A(e,t,n){let i=new Map(n.contexts);return i.set(t,r(e.props,`value`)),G(e,{...n,contexts:i})}function j(e,n,r){let i=P(e);return t.n(i)?w(i(s(r,n)),r):G(e,r)}async function M(e,t,n){return w(await u(e,t,n),n)}function N(e,n){if(t.a(e.type)){let{render:t}=e.type;return M(e=>t(e,null),e.props,n)}if(t.s(e.type)){let r=e.type.type;return t.n(r)?M(r,e.props,n):z({...e,type:r},n)}}function P(e){if(typeof e.props==`object`&&e.props!==null&&`children`in e.props)return e.props.children}function F(e){if(!t.c(e))return;let n=P(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 R(n);if(t.c(n)&&t.o(n))return F(n)}function I(e){let t=[];for(let n of e){let e=L(n);if(e===void 0)return;t.push(e)}return t.join(``)}function L(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 I(e);if(!t.c(e))return;if(t.o(e))return L(P(e));let n=P(e);return n===void 0?``:typeof n==`object`&&n&&Symbol.iterator in n?I(n):L(n)}function R(e){let n=[],r=!1;for(let i of e){if(t.c(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 z(n,r){let i=k(n,r);if(i!==void 0)return i;if(t.n(n.type))return M(n.type,n.props,r);let a=N(n,r);if(a!==void 0)return a;if(t.o(n))return G(n,r);if(t.r(n,`style`)){let e=L(P(n));return{nodes:[],css:e&&e.length>0?[e]:[]}}if(t.r(n,`head`))return{nodes:[],css:(await G(n,r)).css};if(typeof n.type!=`string`||t.i(n.type))return S();let o=W(n,r);if(t.r(n,`br`))return{nodes:[e.l({text:`
2
- `,preset:r.presets?.br,...o})],css:[]};if(t.r(n,`img`))return{nodes:[B(n,r)],css:[]};if(t.r(n,`svg`))return{nodes:[V(n,r)],css:[]};let s=F(n);if(s!==void 0)return{nodes:[e.l({text:s,...o})],css:[]};let c=await G(n,r);return{nodes:[e.t({children:c.nodes,...o})],css:c.css}}function B(t,n){if(!t.props.src)throw Error(`Image element must have a 'src' prop.`);let r=W(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 V(t,n){let r=W(t,n),i=b(t),a=t.props.width===void 0?void 0:Number(t.props.width),o=t.props.height===void 0?void 0:Number(t.props.height);return e.i({src:i,width:a,height:o,...r})}function H(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 U(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 W(e,n){let r=e.props,{preset:i,style:a}=H(e,n),o=U(e,n),s=t.d(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 G(e,t){let n=P(e);return n===void 0?Promise.resolve(S()):w(n,t)}async function K(e,t){let n=[],r=new Set,i=0;for(let a of e){let e=i;i+=1;let o=w(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.css));return{nodes:a,css:o}}exports.Bitmap=x,exports.defaultStylePresets=t.p,exports.fromJsx=C;
2
+ `,preset:r.presets?.br,...o})],css:[]};if(t.r(n,`img`))return{nodes:[B(n,r)],css:[]};if(t.r(n,`svg`))return{nodes:[V(n,r)],css:[]};let s=F(n);if(s!==void 0)return{nodes:[e.l({text:s,...o})],css:[]};let c=await G(n,r);return{nodes:[e.t({children:c.nodes,...o})],css:c.css}}function B(t,n){if(!t.props.src)throw Error(`Image element must have a 'src' prop.`);let r=W(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 V(t,n){let r=W(t,n),i=b(t),a=t.props.width===void 0?void 0:Number(t.props.width),o=t.props.height===void 0?void 0:Number(t.props.height);return e.i({src:i,width:a,height:o,...r})}function H(e,t,n){let r=n.presets,i=r&&e!==void 0&&e in r?r[e]:void 0;if(typeof t!=`object`||!t)return{preset:i};for(let e in t)if(Object.hasOwn(t,e))return{preset:i,style:t};return{preset:i}}function U(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 W(e,n){let r=e.props,i=typeof e.type==`string`?e.type:void 0,{preset:a,style:o}=H(i,r.style,n),s=U(e,n),c=t.d(r,n.tailwindClassesProperty);return{tagName:i,className:r.className??r.class,id:r.id,dir:r.dir,lang:r.lang,attributes:c,tw:s,style:o,preset:a}}function G(e,t){let n=P(e);return n===void 0?Promise.resolve(S()):w(n,t)}async function K(e,t){let n=[],r=new Set,i=0;for(let a of e){let e=i;i+=1;let o=w(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.css));return{nodes:a,css:o}}exports.Bitmap=x,exports.defaultStylePresets=t.p,exports.fromJsx=C;
package/dist/jsx.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { c as Node, d as ReactElementLike, f as RgbaImage } from "./types-BWYDTgEO.cjs";
1
+ import { c as Node, d as ReactElementLike, f as RgbaImage, i as Declarations } from "./types-XYUVkGQq.cjs";
2
2
  import { CSSProperties, ComponentProps, JSX, ReactElement, ReactNode } from "react";
3
3
  //#region src/jsx/style-presets.d.ts
4
4
  declare const defaultStylePresets: Partial<Record<keyof JSX.IntrinsicElements, CSSProperties>>;
@@ -8,7 +8,7 @@ type HtmlProps = {
8
8
  className?: string;
9
9
  class?: string;
10
10
  id?: string;
11
- style?: string | CSSProperties;
11
+ style?: string | Declarations;
12
12
  dir?: string;
13
13
  lang?: string;
14
14
  [key: string]: unknown;
package/dist/jsx.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { c as Node, d as ReactElementLike, f as RgbaImage } from "./types-BWYDTgEO.mjs";
1
+ import { c as Node, d as ReactElementLike, f as RgbaImage, i as Declarations } from "./types-XYUVkGQq.mjs";
2
2
  import { CSSProperties, ComponentProps, JSX, ReactElement, ReactNode } from "react";
3
3
  //#region src/jsx/style-presets.d.ts
4
4
  declare const defaultStylePresets: Partial<Record<keyof JSX.IntrinsicElements, CSSProperties>>;
@@ -8,7 +8,7 @@ type HtmlProps = {
8
8
  className?: string;
9
9
  class?: string;
10
10
  id?: string;
11
- style?: string | CSSProperties;
11
+ style?: string | Declarations;
12
12
  dir?: string;
13
13
  lang?: string;
14
14
  [key: string]: unknown;
package/dist/jsx.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{a as i,c as a,d as o,f as s,i as c,l,n as u,o as d,p as f,r as p,s as m,t as h,u as g}from"./utils-4GQubbLq.mjs";let _;function v(e,t){return typeof e==`object`&&e&&t in e?e[t]:void 0}function y(e){return typeof e==`object`&&!!e&&`then`in e&&typeof e.then==`function`}function ee(e){let t=v(e,`__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE`);if(typeof t==`object`&&t&&`H`in t){let e=t;return{get:()=>e.H,set:t=>{e.H=t}}}let n=v(v(e,`__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED`),`ReactCurrentDispatcher`);if(typeof n==`object`&&n&&`current`in n){let e=n;return{get:()=>e.current,set:t=>{e.current=t}}}return null}function b(){return _??=import(`react`).then(e=>ee(e.default??e)).catch(()=>null),_}function x(e,t){return e.contexts.has(t)?e.contexts.get(t):v(t,`_currentValue`)}const S=()=>{};function C(e,t){let n=t=>x(e,t),r=0;return{readContext:n,useContext:n,use:e=>{if(y(e)){if(e.status===`fulfilled`)return e.value;throw e.status===`rejected`?e.reason:e}return n(e)},useState:e=>[typeof e==`function`?e():e,S],useReducer:(e,t,n)=>[n?n(t):t,S],useMemo:e=>e(),useCallback:e=>e,useRef:e=>({current:e}),useEffect:S,useLayoutEffect:S,useInsertionEffect:S,useImperativeHandle:S,useDebugValue:S,useDeferredValue:e=>e,useTransition:()=>[!1,S],useOptimistic:e=>[e,S],useActionState:(e,t)=>[t,S,!1],useSyncExternalStore:(e,t,n)=>(n??t)(),useId:()=>`:t${t}-${r++}:`,useCacheRefresh:()=>S,useHostTransitionStatus:()=>({pending:!1,data:null,method:null,action:null})}}async function w(e,t,n){let r=await b();if(!r)return e(t);let i=n.ids.current++;for(let a=0;;a++){let o=r.get();r.set(C(n,i));let s;try{return e(t)}catch(e){s=e}finally{r.set(o)}if(!y(s)||a>=64)throw s;await T(s)}}async function T(e){try{e.value=await e,e.status=`fulfilled`}catch(t){e.reason=t,e.status=`rejected`}}function E(e){return typeof e==`string`||typeof e==`number`}function D(e){return e.replace(/&/g,`&amp;`).replace(/"/g,`&quot;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}function O(e){let t=[];for(let n in e)Object.hasOwn(e,n)&&t.push(`${h(n)}:${String(e[n]).trim()}`);return t.join(`;`)}const k=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 A(e,t){if(e===`children`||t==null)return;let n;if(n=e===`className`?`class`:k.has(e)?h(e):e,typeof t==`boolean`)return`${n}="${String(t)}"`;if(e===`style`&&typeof t==`object`){let e=O(t);if(e)return`style="${D(e)}"`}return`${n}="${D(String(t))}"`}function j(e,t,n){let r=!1;for(let n in e){if(!Object.hasOwn(e,n))continue;let i=A(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 M=(e,t,n)=>{let r=e.props||{};if(u(e.type)){N(e.type(e.props),t,!1);return}if(typeof e.type==`symbol`){N(r.children,t,!1);return}if(i(e.type)){N(e.type.render(e.props,null),t,!1);return}if(m(e.type)){M({...e,type:e.type.type},t,n);return}if(typeof e.type!=`string`)return;t.push(`<`,e.type),j(r,t,n&&e.type===`svg`);let a=r.children;t.push(`>`),N(a,t,!1),t.push(`</`,e.type,`>`)};function N(e,t,n){if(e!=null&&e!==!1){if(E(e)){t.push(String(e));return}if(Array.isArray(e)){for(let n of e)N(n,t,!1);return}a(e)&&M(e,t,n)}}function te(e){let t=[];return N(e,t,!0),t.join(``)}function ne({width:e,height:t,data:n,premultiplied:r,...i}){return{type:`img`,props:{...i,src:{width:e,height:t,data:n,premultiplied:r}},key:null}}function P(){return{nodes:[],css:[]}}async function F(t,n){let i=await I(t,{defaultStyles:L(n),presets:s(n?.defaultStyles),tailwindClassesProperty:n?.tailwindClassesProperty??`tw`,contexts:new Map,ids:{current:0}}),a=i.nodes,o;o=a.length===0?r({}):a.length===1&&a[0]!==void 0?a[0]:r({children:a,style:{display:`block`,width:e(100),height:e(100)}});let c=i.css,u={node:o,css:c,get stylesheets(){return g(),c}};return l(u),u}async function I(e,t){return e==null||e===!1?P():e instanceof Promise?I(await e,t):typeof e==`object`&&Symbol.iterator in e?se(e,t):a(e)?await Z(e,t):{nodes:[n({text:String(e),preset:t.presets?.span})],css:[]}}function L(e){return e&&`defaultStyles`in e?e.defaultStyles??f:f}const R=Symbol.for(`react.context`),z=Symbol.for(`react.provider`),B=Symbol.for(`react.consumer`);function V(e,t){let n=e.type;if(typeof n!=`object`||!n)return;let r=v(n,`$$typeof`);if(r===z)return H(e,v(n,`_context`),t);if(r===B)return U(e,v(n,`_context`)??n,t);if(r===R)return typeof K(e)==`function`?U(e,n,t):H(e,n,t)}function H(e,t,n){let r=new Map(n.contexts);return r.set(t,v(e.props,`value`)),$(e,{...n,contexts:r})}function U(e,t,n){let r=K(e);return u(r)?I(r(x(n,t)),n):$(e,n)}async function W(e,t,n){return I(await w(e,t,n),n)}function G(e,t){if(i(e.type)){let{render:n}=e.type;return W(e=>n(e,null),e.props,t)}if(m(e.type)){let n=e.type.type;return u(n)?W(n,e.props,t):Z({...e,type:n},t)}}function K(e){if(typeof e.props==`object`&&e.props!==null&&`children`in e.props)return e.props.children}function q(e){if(!a(e))return;let t=K(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 X(t);if(a(t)&&d(t))return q(t)}function J(e){let t=[];for(let n of e){let e=Y(n);if(e===void 0)return;t.push(e)}return t.join(``)}function Y(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 J(e);if(!a(e))return;if(d(e))return Y(K(e));let t=K(e);return t===void 0?``:typeof t==`object`&&t&&Symbol.iterator in t?J(t):Y(t)}function X(e){let t=[],n=!1;for(let r of e){if(a(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 Z(e,t){let i=V(e,t);if(i!==void 0)return i;if(u(e.type))return W(e.type,e.props,t);let a=G(e,t);if(a!==void 0)return a;if(d(e))return $(e,t);if(p(e,`style`)){let t=Y(K(e));return{nodes:[],css:t&&t.length>0?[t]:[]}}if(p(e,`head`))return{nodes:[],css:(await $(e,t)).css};if(typeof e.type!=`string`||c(e.type))return P();let o=Q(e,t);if(p(e,`br`))return{nodes:[n({text:`
2
- `,preset:t.presets?.br,...o})],css:[]};if(p(e,`img`))return{nodes:[re(e,t)],css:[]};if(p(e,`svg`))return{nodes:[ie(e,t)],css:[]};let s=q(e);if(s!==void 0)return{nodes:[n({text:s,...o})],css:[]};let l=await $(e,t);return{nodes:[r({children:l.nodes,...o})],css:l.css}}function re(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 ie(e,n){let r=Q(e,n),i=te(e),a=e.props.width===void 0?void 0:Number(e.props.width),o=e.props.height===void 0?void 0:Number(e.props.height);return t({src:i,width:a,height:o,...r})}function ae(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 oe(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}=ae(e,t),a=oe(e,t),s=o(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:s,tw:a,style:i,preset:r}}function $(e,t){let n=K(e);return n===void 0?Promise.resolve(P()):I(n,t)}async function se(e,t){let n=[],r=new Set,i=0;for(let a of e){let e=i;i+=1;let o=I(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.css));return{nodes:a,css:o}}export{ne as Bitmap,f as defaultStylePresets,F as fromJsx};
2
+ `,preset:t.presets?.br,...o})],css:[]};if(p(e,`img`))return{nodes:[re(e,t)],css:[]};if(p(e,`svg`))return{nodes:[ie(e,t)],css:[]};let s=q(e);if(s!==void 0)return{nodes:[n({text:s,...o})],css:[]};let l=await $(e,t);return{nodes:[r({children:l.nodes,...o})],css:l.css}}function re(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 ie(e,n){let r=Q(e,n),i=te(e),a=e.props.width===void 0?void 0:Number(e.props.width),o=e.props.height===void 0?void 0:Number(e.props.height);return t({src:i,width:a,height:o,...r})}function ae(e,t,n){let r=n.presets,i=r&&e!==void 0&&e in r?r[e]:void 0;if(typeof t!=`object`||!t)return{preset:i};for(let e in t)if(Object.hasOwn(t,e))return{preset:i,style:t};return{preset:i}}function oe(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,r=typeof e.type==`string`?e.type:void 0,{preset:i,style:a}=ae(r,n.style,t),s=oe(e,t),c=o(n,t.tailwindClassesProperty);return{tagName:r,className:n.className??n.class,id:n.id,dir:n.dir,lang:n.lang,attributes:c,tw:s,style:a,preset:i}}function $(e,t){let n=K(e);return n===void 0?Promise.resolve(P()):I(n,t)}async function se(e,t){let n=[],r=new Set,i=0;for(let a of e){let e=i;i+=1;let o=I(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.css));return{nodes:a,css:o}}export{ne as Bitmap,f as defaultStylePresets,F as fromJsx};
package/dist/renderer.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./fonts-D-2FIgft.cjs");function t(e){return e instanceof Uint8Array||e instanceof ArrayBuffer||typeof Buffer<`u`&&Buffer.isBuffer(e)}function n(e){return e instanceof ArrayBuffer?new Uint8Array(e):e}function r(e){return t(e)?e:typeof e.data==`function`?e.data():e.data}function i(e){return t(e)?e:`key`in e&&e.key?e.key:typeof e.data==`function`?`${e.name??``}:${e.weight??``}:${e.style??``}`:e.data}async function a(e){let{sources:t=[],cache:r}=Array.isArray(e)?{sources:e}:e,i=new Map;for(let e of t)i.set(e.src,e);return Promise.all([...i.values()].map(async({src:e,data:t,cache:i})=>({src:e,data:n(typeof t==`function`?await t():t),cache:i??r})))}var o=class{registerInner;byKey=new Map;byData=new WeakMap;constructor(e){this.registerInner=e}getFont(e){return typeof e==`string`?this.byKey.get(e):this.byData.get(e)}setFont(e,t){typeof e==`string`?this.byKey.set(e,t):this.byData.set(e,t)}deleteFont(e){typeof e==`string`?this.byKey.delete(e):this.byData.delete(e)}async register(a){let o=typeof a==`string`?e.r(a):a,s=i(o),c=this.getFont(s);if(c)return c;let l=r(o),u=Promise.resolve(l).then(e=>{let r=n(e);return this.registerInner(t(o)?r:{...o,data:r})}).catch(e=>{throw this.deleteFont(s),e});return this.setFont(s,u),u}async prepareFonts(e){if(!e)return;let t=await Promise.all(e.map(e=>this.register(e)));return[...new Set(t.flat().map(e=>e.name))]}async resolveResources(e,t,n){let r=await this.prepareFonts(e);return{images:t?await a(t):void 0,fontFamilies:n??r}}};async function s(t,n,r){let{fonts:i,fontFamilies:a,signal:o,images:s,...c}=n;o?.throwIfAborted();let l=await i,u=await t.resolveResources(l&&e.a({fonts:l,source:[...Array.isArray(r)?r:[r],`•◦■▪▸◂▾ 0123456789.-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`]}),s,a);return o?.throwIfAborted(),{options:{...c,...u},signal:o}}exports.FontRegistry=o,exports.prepareRenderInput=s,exports.resolveImageLoaders=a;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./fonts-B-pwvIqE.cjs");function t(e){return e instanceof Uint8Array||e instanceof ArrayBuffer||typeof Buffer<`u`&&Buffer.isBuffer(e)}function n(e){return e instanceof ArrayBuffer?new Uint8Array(e):e}function r(e){return t(e)?e:typeof e.data==`function`?e.data():e.data}function i(e){return t(e)?e:`key`in e&&e.key?e.key:typeof e.data==`function`?`${e.name??``}:${e.weight??``}:${e.style??``}`:e.data}async function a(e){let{sources:t=[],cache:r}=Array.isArray(e)?{sources:e}:e,i=new Map;for(let e of t)i.set(e.src,e);return Promise.all([...i.values()].map(async({src:e,data:t,cache:i})=>({src:e,data:n(typeof t==`function`?await t():t),cache:i??r})))}var o=class{registerInner;byKey=new Map;byData=new WeakMap;constructor(e){this.registerInner=e}getFont(e){return typeof e==`string`?this.byKey.get(e):this.byData.get(e)}setFont(e,t){typeof e==`string`?this.byKey.set(e,t):this.byData.set(e,t)}deleteFont(e){typeof e==`string`?this.byKey.delete(e):this.byData.delete(e)}async register(a){let o=typeof a==`string`?e.r(a):a,s=i(o),c=this.getFont(s);if(c)return c;let l=r(o),u=Promise.resolve(l).then(e=>{let r=n(e);return this.registerInner(t(o)?r:{...o,data:r})}).catch(e=>{throw this.deleteFont(s),e});return this.setFont(s,u),u}async prepareFonts(e){if(!e)return;let t=await Promise.all(e.map(e=>this.register(e)));return[...new Set(t.flat().map(e=>e.name))]}async resolveResources(e,t,n){let r=await this.prepareFonts(e);return{images:t?await a(t):void 0,fontFamilies:n??r}}};async function s(t,n,r){let{fonts:i,fontFamilies:a,signal:o,images:s,...c}=n;o?.throwIfAborted();let l=await i,u=await t.resolveResources(l&&e.a({fonts:l,source:[...Array.isArray(r)?r:[r],`•◦■▪▸◂▾ 0123456789.-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`]}),s,a);return o?.throwIfAborted(),{options:{...c,...u},signal:o}}exports.FontRegistry=o,exports.prepareRenderInput=s,exports.resolveImageLoaders=a;
@@ -1,4 +1,4 @@
1
- import { r as GenericFontFamily, t as CodepointSource } from "./fonts-DJzerTBP.cjs";
1
+ import { r as GenericFontFamily, t as CodepointSource } from "./fonts-BrUiG8am.cjs";
2
2
  //#region src/renderer.d.ts
3
3
  /**
4
4
  * Shared wrapper primitives for the `@takumi-rs/core` (napi) and `@takumi-rs/wasm` renderer
@@ -1,4 +1,4 @@
1
- import { r as GenericFontFamily, t as CodepointSource } from "./fonts-BV8jtksq.mjs";
1
+ import { r as GenericFontFamily, t as CodepointSource } from "./fonts-Du-K60HL.mjs";
2
2
  //#region src/renderer.d.ts
3
3
  /**
4
4
  * Shared wrapper primitives for the `@takumi-rs/core` (napi) and `@takumi-rs/wasm` renderer
package/dist/renderer.mjs CHANGED
@@ -1 +1 @@
1
- import{a as e,r as t}from"./fonts-RWAcijal.mjs";function n(e){return e instanceof Uint8Array||e instanceof ArrayBuffer||typeof Buffer<`u`&&Buffer.isBuffer(e)}function r(e){return e instanceof ArrayBuffer?new Uint8Array(e):e}function i(e){return n(e)?e:typeof e.data==`function`?e.data():e.data}function a(e){return n(e)?e:`key`in e&&e.key?e.key:typeof e.data==`function`?`${e.name??``}:${e.weight??``}:${e.style??``}`:e.data}async function o(e){let{sources:t=[],cache:n}=Array.isArray(e)?{sources:e}:e,i=new Map;for(let e of t)i.set(e.src,e);return Promise.all([...i.values()].map(async({src:e,data:t,cache:i})=>({src:e,data:r(typeof t==`function`?await t():t),cache:i??n})))}var s=class{registerInner;byKey=new Map;byData=new WeakMap;constructor(e){this.registerInner=e}getFont(e){return typeof e==`string`?this.byKey.get(e):this.byData.get(e)}setFont(e,t){typeof e==`string`?this.byKey.set(e,t):this.byData.set(e,t)}deleteFont(e){typeof e==`string`?this.byKey.delete(e):this.byData.delete(e)}async register(e){let o=typeof e==`string`?t(e):e,s=a(o),c=this.getFont(s);if(c)return c;let l=i(o),u=Promise.resolve(l).then(e=>{let t=r(e);return this.registerInner(n(o)?t:{...o,data:t})}).catch(e=>{throw this.deleteFont(s),e});return this.setFont(s,u),u}async prepareFonts(e){if(!e)return;let t=await Promise.all(e.map(e=>this.register(e)));return[...new Set(t.flat().map(e=>e.name))]}async resolveResources(e,t,n){let r=await this.prepareFonts(e);return{images:t?await o(t):void 0,fontFamilies:n??r}}};async function c(t,n,r){let{fonts:i,fontFamilies:a,signal:o,images:s,...c}=n;o?.throwIfAborted();let l=await i,u=await t.resolveResources(l&&e({fonts:l,source:[...Array.isArray(r)?r:[r],`•◦■▪▸◂▾ 0123456789.-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`]}),s,a);return o?.throwIfAborted(),{options:{...c,...u},signal:o}}export{s as FontRegistry,c as prepareRenderInput,o as resolveImageLoaders};
1
+ import{a as e,r as t}from"./fonts-CBLz8Mte.mjs";function n(e){return e instanceof Uint8Array||e instanceof ArrayBuffer||typeof Buffer<`u`&&Buffer.isBuffer(e)}function r(e){return e instanceof ArrayBuffer?new Uint8Array(e):e}function i(e){return n(e)?e:typeof e.data==`function`?e.data():e.data}function a(e){return n(e)?e:`key`in e&&e.key?e.key:typeof e.data==`function`?`${e.name??``}:${e.weight??``}:${e.style??``}`:e.data}async function o(e){let{sources:t=[],cache:n}=Array.isArray(e)?{sources:e}:e,i=new Map;for(let e of t)i.set(e.src,e);return Promise.all([...i.values()].map(async({src:e,data:t,cache:i})=>({src:e,data:r(typeof t==`function`?await t():t),cache:i??n})))}var s=class{registerInner;byKey=new Map;byData=new WeakMap;constructor(e){this.registerInner=e}getFont(e){return typeof e==`string`?this.byKey.get(e):this.byData.get(e)}setFont(e,t){typeof e==`string`?this.byKey.set(e,t):this.byData.set(e,t)}deleteFont(e){typeof e==`string`?this.byKey.delete(e):this.byData.delete(e)}async register(e){let o=typeof e==`string`?t(e):e,s=a(o),c=this.getFont(s);if(c)return c;let l=i(o),u=Promise.resolve(l).then(e=>{let t=r(e);return this.registerInner(n(o)?t:{...o,data:t})}).catch(e=>{throw this.deleteFont(s),e});return this.setFont(s,u),u}async prepareFonts(e){if(!e)return;let t=await Promise.all(e.map(e=>this.register(e)));return[...new Set(t.flat().map(e=>e.name))]}async resolveResources(e,t,n){let r=await this.prepareFonts(e);return{images:t?await o(t):void 0,fontFamilies:n??r}}};async function c(t,n,r){let{fonts:i,fontFamilies:a,signal:o,images:s,...c}=n;o?.throwIfAborted();let l=await i,u=await t.resolveResources(l&&e({fonts:l,source:[...Array.isArray(r)?r:[r],`•◦■▪▸◂▾ 0123456789.-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`]}),s,a);return o?.throwIfAborted(),{options:{...c,...u},signal:o}}export{s as FontRegistry,c as prepareRenderInput,o as resolveImageLoaders};
@@ -7,15 +7,13 @@ import { CSSProperties } from "react";
7
7
  */
8
8
  type TextFit = "none" | "grow" | "shrink" | "consistent" | "per-line" | "per-line-all" | `${number}%` | (string & {});
9
9
  declare module "react" {
10
- interface CSSProperties {
10
+ interface CSSProperties extends Record<`--${string}`, string | number | undefined> {
11
11
  textFit?: TextFit;
12
12
  }
13
13
  }
14
14
  type NodeAttributes = Record<string, string>;
15
15
  /** A declaration block, with custom properties allowed. */
16
- type Declarations = CSSProperties & {
17
- [key: `--${string}`]: string | number;
18
- };
16
+ type Declarations = CSSProperties;
19
17
  /** A style rule written as an object. */
20
18
  type StyleRule = {
21
19
  selector: string;
@@ -64,8 +62,8 @@ type NodeMetadata = {
64
62
  lang?: string;
65
63
  attributes?: NodeAttributes;
66
64
  tw?: string;
67
- style?: CSSProperties;
68
- preset?: CSSProperties;
65
+ style?: Declarations;
66
+ preset?: Declarations;
69
67
  };
70
68
  type Node = ContainerNode | TextNode | ImageNode;
71
69
  type ContainerNode = NodeMetadata & {
@@ -7,15 +7,13 @@ import { CSSProperties } from "react";
7
7
  */
8
8
  type TextFit = "none" | "grow" | "shrink" | "consistent" | "per-line" | "per-line-all" | `${number}%` | (string & {});
9
9
  declare module "react" {
10
- interface CSSProperties {
10
+ interface CSSProperties extends Record<`--${string}`, string | number | undefined> {
11
11
  textFit?: TextFit;
12
12
  }
13
13
  }
14
14
  type NodeAttributes = Record<string, string>;
15
15
  /** A declaration block, with custom properties allowed. */
16
- type Declarations = CSSProperties & {
17
- [key: `--${string}`]: string | number;
18
- };
16
+ type Declarations = CSSProperties;
19
17
  /** A style rule written as an object. */
20
18
  type StyleRule = {
21
19
  selector: string;
@@ -64,8 +62,8 @@ type NodeMetadata = {
64
62
  lang?: string;
65
63
  attributes?: NodeAttributes;
66
64
  tw?: string;
67
- style?: CSSProperties;
68
- preset?: CSSProperties;
65
+ style?: Declarations;
66
+ preset?: Declarations;
69
67
  };
70
68
  type Node = ContainerNode | TextNode | ImageNode;
71
69
  type ContainerNode = NodeMetadata & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takumi-rs/helpers",
3
- "version": "2.13.5",
3
+ "version": "2.13.6",
4
4
  "description": "Convert JSX and HTML to Takumi node trees. Load fonts and emoji.",
5
5
  "keywords": [
6
6
  "emoji",
@@ -91,7 +91,7 @@
91
91
  "provenance": true
92
92
  },
93
93
  "scripts": {
94
- "build": "tsdown",
94
+ "build": "tsdown --config-loader unrun",
95
95
  "publish-lint": "attw --pack . && publint --strict ."
96
96
  },
97
97
  "devDependencies": {
@@ -1 +0,0 @@
1
- const e=/url\(\s*(['"]?)(.*?)\1\s*\)/g;async function t(e,t={}){if(t.allowUrl&&!t.allowUrl(e))throw Error(`URL blocked by allowUrl policy: ${e}`);let r=t.fetch??globalThis.fetch,i=t.timeout??3e4,a=i<=0?void 0:AbortSignal.timeout(i),o=[t.signal,t.init?.signal,a].filter(e=>e!==void 0),s=o.length?AbortSignal.any(o):void 0,c={...t.init,signal:s},l=t.allowUrl?await n(e,t.allowUrl,r,c):await r(e,c);if(!l.ok)throw Error(`HTTP ${l.status} ${l.statusText} fetching ${e}`);return l}async function n(e,t,n,r){let i=e;for(let e=0;e<5;e++){let e=await n(i,{...r,redirect:`manual`}),a=e.headers.get(`location`);if(e.status<300||e.status>=400||!a)return e;if(await e.body?.cancel().catch(()=>{}),i=new URL(a,i).toString(),!t(i))throw Error(`URL blocked by allowUrl policy: ${i}`)}throw Error(`Too many redirects fetching ${e}`)}async function r(e,t){let n=Number(e.headers.get(`content-length`));if(Number.isFinite(n)&&n>t)throw Error(`Response exceeds ${t} bytes (content-length ${n})`);let r=e.body;if(!r)return e.arrayBuffer();let i=r.getReader(),a=[],o=0;for(;;){let{done:e,value:n}=await i.read();if(e)break;if(o+=n.byteLength,o>t)throw await i.cancel().catch(()=>{}),Error(`Response exceeds ${t} bytes`);a.push(n)}let s=new Uint8Array(o),c=0;for(let e of a)s.set(e,c),c+=e.byteLength;return s.buffer}function i(e){return e.startsWith(`https://`)||e.startsWith(`http://`)}function a(t,n){if(typeof t==`string`)for(let r of t.matchAll(e)){let e=r[2]?.trim();e&&i(e)&&n.add(e)}else if(Array.isArray(t))for(let e of t)a(e,n)}function o(e){let t=new Set,n=e=>{let r=e=>{e&&(a(e.backgroundImage,t),a(e.maskImage,t),a(e.listStyleImage,t))};if(r(e.style),r(e.preset),a(e.tw,t),e.type===`image`){typeof e.src==`string`&&i(e.src)&&t.add(e.src);return}if(e.type===`container`)for(let t of e.children??[])n(t)};return n(e),[...t]}function s(e,n,i){let a=n.maxBytes??33554432,{allowUrl:o}=n,s=i?.get(e);if(s)return s.then(t=>{if(o&&!o(e))throw Error(`URL blocked by allowUrl policy: ${e}`);if(t.byteLength>a)throw Error(`Response exceeds ${a} bytes`);return t});let c=t(e,n).then(e=>r(e,a)).catch(t=>{throw i?.delete(e),t});return i?.set(e,c),c}async function c({node:e,sources:t=[],fetchCache:n,fetch:r,timeout:i,signal:a,maxBytes:c,allowUrl:l,throwOnError:u=!0}){let d=Array.isArray(e)?e:[e],f=new Map;for(let e of t)f.set(e.src,e);let p=[...new Set(d.flatMap(o))].filter(e=>!f.has(e)),m={fetch:r,timeout:i,signal:a,maxBytes:c,allowUrl:l},h=p.map(async e=>({src:e,data:await s(e,m,n)})),g=u?await Promise.all(h):(await Promise.allSettled(h)).filter(e=>e.status===`fulfilled`).map(e=>e.value);return[...f.values(),...g]}const l=new Map;function u(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 d(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`,u(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`,u(n.name,r,a,o))}return e.display&&t.searchParams.set(`display`,e.display),t.toString()}function f(e,n){return t(e,{...n,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=>r(e,n.maxBytes??2097152)).then(e=>new TextDecoder().decode(e))}function p(e,t){let n=t.cache??l,r=n.get(e);if(r)return r;let i=f(e,t);return n.set(e,i),i.catch(()=>n.delete(e)),i}const m=/(?:\/\*\s*([^*]+?)\s*\*\/\s*)?@font-face\s*\{([^}]*)\}/g;function h(e,n,i){let a=`${e.family} ${e.subset}`,o=e.ranges.map(([e,t])=>`${e}-${t}`).join(`,`);return{name:a,subsetOf:e.family,subsetRank:g(e.ranges),key:`${a}:${e.weight??``}:${e.style??``}:${o}:${i??``}`,weight:e.weight,style:e.style,ranges:e.ranges,generic:i,data:()=>t(e.url,n).then(e=>r(e,n.maxBytes??33554432))}}function g(e){return e.length===0?4294967295:Math.min(...e.map(([e])=>e))}function _(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 v(e){let t=[],n=0;for(let r of e.matchAll(m)){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?_(o):[]}),n+=1}return t}function y(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 b(e){let t=new Set,n=e=>{for(let n of e)t.add(n.codePointAt(0))},r=e=>{typeof e==`string`?n(e):e.type===`text`?n(e.text):e.type===`container`&&e.children?.forEach(r)};return Array.isArray(e)?e.forEach(r):r(e),t}function x(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 S({fonts:e,source:t}){let n=b(t);return e.filter(e=>x(e.ranges??[],n))}function C(e,n={}){return{key:e,data:()=>t(e,n).then(e=>r(e,n.maxBytes??33554432))}}async function w(e){if(Array.isArray(e)&&(e={families:e}),e.families.length===0)return[];let t=await p(d(e),e),n=new Map(e.families.map((e,t)=>[typeof e==`string`?e:e.name,t])),r=new Map(e.families.flatMap(e=>typeof e==`string`||!e.generic?[]:[[e.name,e.generic]]));return y(v(t)).sort((e,t)=>(n.get(e.family)??0)-(n.get(t.family)??0)).map(t=>h(t,e,r.get(t.family)))}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return 33554432}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return`•◦■▪▸◂▾ 0123456789.-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`}});
@@ -1 +0,0 @@
1
- const e=33554432,t=/url\(\s*(['"]?)(.*?)\1\s*\)/g;async function n(e,t={}){if(t.allowUrl&&!t.allowUrl(e))throw Error(`URL blocked by allowUrl policy: ${e}`);let n=t.fetch??globalThis.fetch,i=t.timeout??3e4,a=i<=0?void 0:AbortSignal.timeout(i),o=[t.signal,t.init?.signal,a].filter(e=>e!==void 0),s=o.length?AbortSignal.any(o):void 0,c={...t.init,signal:s},l=t.allowUrl?await r(e,t.allowUrl,n,c):await n(e,c);if(!l.ok)throw Error(`HTTP ${l.status} ${l.statusText} fetching ${e}`);return l}async function r(e,t,n,r){let i=e;for(let e=0;e<5;e++){let e=await n(i,{...r,redirect:`manual`}),a=e.headers.get(`location`);if(e.status<300||e.status>=400||!a)return e;if(await e.body?.cancel().catch(()=>{}),i=new URL(a,i).toString(),!t(i))throw Error(`URL blocked by allowUrl policy: ${i}`)}throw Error(`Too many redirects fetching ${e}`)}async function i(e,t){let n=Number(e.headers.get(`content-length`));if(Number.isFinite(n)&&n>t)throw Error(`Response exceeds ${t} bytes (content-length ${n})`);let r=e.body;if(!r)return e.arrayBuffer();let i=r.getReader(),a=[],o=0;for(;;){let{done:e,value:n}=await i.read();if(e)break;if(o+=n.byteLength,o>t)throw await i.cancel().catch(()=>{}),Error(`Response exceeds ${t} bytes`);a.push(n)}let s=new Uint8Array(o),c=0;for(let e of a)s.set(e,c),c+=e.byteLength;return s.buffer}function a(e){return e.startsWith(`https://`)||e.startsWith(`http://`)}function o(e,n){if(typeof e==`string`)for(let r of e.matchAll(t)){let e=r[2]?.trim();e&&a(e)&&n.add(e)}else if(Array.isArray(e))for(let t of e)o(t,n)}function s(e){let t=new Set,n=e=>{let r=e=>{e&&(o(e.backgroundImage,t),o(e.maskImage,t),o(e.listStyleImage,t))};if(r(e.style),r(e.preset),o(e.tw,t),e.type===`image`){typeof e.src==`string`&&a(e.src)&&t.add(e.src);return}if(e.type===`container`)for(let t of e.children??[])n(t)};return n(e),[...t]}function c(e,t,r){let a=t.maxBytes??33554432,{allowUrl:o}=t,s=r?.get(e);if(s)return s.then(t=>{if(o&&!o(e))throw Error(`URL blocked by allowUrl policy: ${e}`);if(t.byteLength>a)throw Error(`Response exceeds ${a} bytes`);return t});let c=n(e,t).then(e=>i(e,a)).catch(t=>{throw r?.delete(e),t});return r?.set(e,c),c}async function l({node:e,sources:t=[],fetchCache:n,fetch:r,timeout:i,signal:a,maxBytes:o,allowUrl:l,throwOnError:u=!0}){let d=Array.isArray(e)?e:[e],f=new Map;for(let e of t)f.set(e.src,e);let p=[...new Set(d.flatMap(s))].filter(e=>!f.has(e)),m={fetch:r,timeout:i,signal:a,maxBytes:o,allowUrl:l},h=p.map(async e=>({src:e,data:await c(e,m,n)})),g=u?await Promise.all(h):(await Promise.allSettled(h)).filter(e=>e.status===`fulfilled`).map(e=>e.value);return[...f.values(),...g]}const u=new Map;function d(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 f(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`,d(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`,d(n.name,r,a,o))}return e.display&&t.searchParams.set(`display`,e.display),t.toString()}function p(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=>i(e,t.maxBytes??2097152)).then(e=>new TextDecoder().decode(e))}function m(e,t){let n=t.cache??u,r=n.get(e);if(r)return r;let i=p(e,t);return n.set(e,i),i.catch(()=>n.delete(e)),i}const h=/(?:\/\*\s*([^*]+?)\s*\*\/\s*)?@font-face\s*\{([^}]*)\}/g;function g(e,t,r){let a=`${e.family} ${e.subset}`,o=e.ranges.map(([e,t])=>`${e}-${t}`).join(`,`);return{name:a,subsetOf:e.family,subsetRank:_(e.ranges),key:`${a}:${e.weight??``}:${e.style??``}:${o}:${r??``}`,weight:e.weight,style:e.style,ranges:e.ranges,generic:r,data:()=>n(e.url,t).then(e=>i(e,t.maxBytes??33554432))}}function _(e){return e.length===0?4294967295:Math.min(...e.map(([e])=>e))}function v(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 y(e){let t=[],n=0;for(let r of e.matchAll(h)){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?v(o):[]}),n+=1}return t}function b(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}const x=`•◦■▪▸◂▾ 0123456789.-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`;function S(e){let t=new Set,n=e=>{for(let n of e)t.add(n.codePointAt(0))},r=e=>{typeof e==`string`?n(e):e.type===`text`?n(e.text):e.type===`container`&&e.children?.forEach(r)};return Array.isArray(e)?e.forEach(r):r(e),t}function C(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 w({fonts:e,source:t}){let n=S(t);return e.filter(e=>C(e.ranges??[],n))}function T(e,t={}){return{key:e,data:()=>n(e,t).then(e=>i(e,t.maxBytes??33554432))}}async function E(e){if(Array.isArray(e)&&(e={families:e}),e.families.length===0)return[];let t=await m(f(e),e),n=new Map(e.families.map((e,t)=>[typeof e==`string`?e:e.name,t])),r=new Map(e.families.flatMap(e=>typeof e==`string`||!e.generic?[]:[[e.name,e.generic]]));return b(y(t)).sort((e,t)=>(n.get(e.family)??0)-(n.get(t.family)??0)).map(t=>g(t,e,r.get(t.family)))}export{w as a,l as c,E as i,i as l,S as n,e as o,T as r,n as s,x as t};