@takumi-rs/helpers 2.1.2 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- const e=32*1024*1024,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,r=t.timeout??5e3,i=r<=0?void 0:AbortSignal.timeout(r),a=[t.signal,t.init?.signal,i].filter(e=>e!==void 0),o=a.length?AbortSignal.any(a):void 0,s=await n(e,{...t.init,signal:o});if(!s.ok)throw Error(`HTTP ${s.status} ${s.statusText} fetching ${e}`);return s}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(e,n){if(typeof e==`string`)for(let r of e.matchAll(t)){let e=r[2]?.trim();e&&i(e)&&n.add(e)}else if(Array.isArray(e))for(let t of e)a(t,n)}function o(e){let t=new Set,n=e=>{let r=e=>{e&&(a(e.backgroundImage,t),a(e.maskImage,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,t,i){let a=i?.get(e);if(a)return a;let o=n(e,t).then(e=>r(e,t.maxBytes??33554432)).catch(t=>{throw i?.delete(e),t});return i?.set(e,o),o}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,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=>r(e,t.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,t){let i=`${e.family} ${e.subset}`,a=e.ranges.map(([e,t])=>`${e}-${t}`).join(`,`);return{name:i,subsetOf:e.family,key:`${i}:${e.weight??``}:${e.style??``}:${a}`,weight:e.weight,style:e.style,ranges:e.ranges,data:()=>n(e.url,t).then(e=>r(e,t.maxBytes??33554432))}}function g(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 _(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?g(o):[]}),n+=1}return t}function v(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 y(e){let t=new Set,n=e=>{for(let n of e)t.add(n.codePointAt(0))},r=e=>{e.type===`text`?n(e.text):e.type===`container`&&e.children?.forEach(r)};return typeof e==`string`?n(e):Array.isArray(e)?e.forEach(r):r(e),t}function 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:()=>n(e,t).then(e=>r(e,t.maxBytes??33554432))}}async function C(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]));return v(_(t)).sort((e,t)=>(n.get(e.family)??0)-(n.get(t.family)??0)).map(t=>h(t,e))}export{e as a,r as c,x as i,S as n,n as o,C as r,c as s,y as t};
1
+ const e=32*1024*1024,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,r=t.timeout??5e3,i=r<=0?void 0:AbortSignal.timeout(r),a=[t.signal,t.init?.signal,i].filter(e=>e!==void 0),o=a.length?AbortSignal.any(a):void 0,s=await n(e,{...t.init,signal:o});if(!s.ok)throw Error(`HTTP ${s.status} ${s.statusText} fetching ${e}`);return s}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(e,n){if(typeof e==`string`)for(let r of e.matchAll(t)){let e=r[2]?.trim();e&&i(e)&&n.add(e)}else if(Array.isArray(e))for(let t of e)a(t,n)}function o(e){let t=new Set,n=e=>{let r=e=>{e&&(a(e.backgroundImage,t),a(e.maskImage,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,t,i){let a=i?.get(e);if(a)return a;let o=n(e,t).then(e=>r(e,t.maxBytes??33554432)).catch(t=>{throw i?.delete(e),t});return i?.set(e,o),o}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,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=>r(e,t.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,t,i){let a=`${e.family} ${e.subset}`,o=e.ranges.map(([e,t])=>`${e}-${t}`).join(`,`);return{name:a,subsetOf:e.family,key:`${a}:${e.weight??``}:${e.style??``}:${o}:${i??``}`,weight:e.weight,style:e.style,ranges:e.ranges,generic:i,data:()=>n(e.url,t).then(e=>r(e,t.maxBytes??33554432))}}function g(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 _(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?g(o):[]}),n+=1}return t}function v(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 y(e){let t=new Set,n=e=>{for(let n of e)t.add(n.codePointAt(0))},r=e=>{e.type===`text`?n(e.text):e.type===`container`&&e.children?.forEach(r)};return typeof e==`string`?n(e):Array.isArray(e)?e.forEach(r):r(e),t}function 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:()=>n(e,t).then(e=>r(e,t.maxBytes??33554432))}}async function C(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 v(_(t)).sort((e,t)=>(n.get(e.family)??0)-(n.get(t.family)??0)).map(t=>h(t,e,r.get(t.family)))}export{e as a,r as c,x as i,S as n,n as o,C as r,c as s,y as t};
@@ -1,5 +1,4 @@
1
- import { c as TextNode, n as ImageNode, r as Node, t as ContainerNode } from "./types-BwfCrcx3.cjs";
2
- import { CSSProperties } from "react";
1
+ import { r as Node } from "./types-BwfCrcx3.mjs";
3
2
  //#region src/google-fonts-catalog.d.ts
4
3
  interface GoogleFontShapes {
5
4
  S0: {
@@ -976,6 +975,8 @@ declare function prepareImages<T extends {
976
975
  //#endregion
977
976
  //#region src/fonts.d.ts
978
977
  type FontStyle = "normal" | "italic";
978
+ /** CSS generic family keywords a font can claim. */
979
+ type GenericFontFamily = "serif" | "sans-serif" | "monospace" | "cursive" | "fantasy" | "system-ui" | "ui-serif" | "ui-sans-serif" | "ui-monospace" | "ui-rounded" | "emoji" | "math" | "fangsong";
979
980
  type WeightRange = `${number}..${number}`;
980
981
  type AxisValue = number | WeightRange;
981
982
  type KnownGoogleFontFamily = { [S in keyof GoogleFontShapes]: {
@@ -986,6 +987,8 @@ type KnownGoogleFontFamily = { [S in keyof GoogleFontShapes]: {
986
987
  style?: GoogleFontShapes[S]["style"] | GoogleFontShapes[S]["style"][];
987
988
  /** Variable axes to vary, each at a value or `"min..max"` range, e.g. `{ opsz: "14..32" }`. */
988
989
  axes?: [GoogleFontShapes[S]["axis"]] extends [never] ? never : Partial<Record<GoogleFontShapes[S]["axis"], AxisValue>>;
990
+ /** CSS generic family the loaded subsets claim, e.g. `"monospace"`. */
991
+ generic?: GenericFontFamily;
989
992
  }; }[keyof GoogleFontShapes];
990
993
  type GoogleFontName = GoogleFontShapeFamilies[keyof GoogleFontShapeFamilies];
991
994
  /**
@@ -998,6 +1001,8 @@ type GoogleFontFamily = GoogleFontName | (string & {}) | KnownGoogleFontFamily |
998
1001
  weight?: number | number[] | WeightRange;
999
1002
  style?: FontStyle | FontStyle[];
1000
1003
  axes?: Record<string, AxisValue>;
1004
+ /** CSS generic family the loaded subsets claim, e.g. `"monospace"`. */
1005
+ generic?: GenericFontFamily;
1001
1006
  };
1002
1007
  type GoogleFontsOptions = FetchOptions & {
1003
1008
  /** The families to load, each as a name or a name plus its weight/style axis. */
@@ -1029,6 +1034,8 @@ type FontSubset = {
1029
1034
  style?: string;
1030
1035
  /** Inclusive codepoint ranges this subset covers; empty covers everything. */
1031
1036
  ranges: [number, number][];
1037
+ /** CSS generic family the subset claims, from the family's `generic` option. */
1038
+ generic?: GenericFontFamily;
1032
1039
  /** Fetches the subset bytes. The renderer skips files it has already loaded. */
1033
1040
  data: () => Promise<ArrayBuffer>;
1034
1041
  };
@@ -1065,18 +1072,4 @@ declare function fontFromUrl(url: string, options?: FetchOptions): {
1065
1072
  */
1066
1073
  declare function googleFonts(options: GoogleFontsOptions | GoogleFontFamily[]): Promise<FontSubset[]>;
1067
1074
  //#endregion
1068
- //#region src/helpers.d.ts
1069
- declare function container(props: Omit<ContainerNode, "type">): ContainerNode;
1070
- declare function text(text: string, style?: CSSProperties): TextNode;
1071
- declare function text(props: Omit<TextNode, "type">): TextNode;
1072
- declare function image(props: Omit<ImageNode, "type">): ImageNode;
1073
- declare function style(style: CSSProperties): CSSProperties;
1074
- declare function percentage(percentage: number): `${number}%`;
1075
- declare function vw(vw: number): `${number}vw`;
1076
- declare function vh(vh: number): `${number}vh`;
1077
- declare function em(em: number): `${number}em`;
1078
- declare function rem(rem: number): `${number}rem`;
1079
- declare function fr(fr: number): `${number}fr`;
1080
- declare function rgba(r: number, g: number, b: number, a?: number): `rgb(${number} ${number} ${number} / ${number})`;
1081
- //#endregion
1082
- export { PrepareImagesOptions as C, readBodyLimited as D, prepareImages as E, ImageFetchCache as S, fetchOk as T, googleFonts as _, percentage as a, FetchOptions as b, style as c, vw as d, FontSubset as f, fontFromUrl as g, collectCodepoints as h, image as i, text as l, GoogleFontsOptions as m, em as n, rem as o, GoogleFontFamily as p, fr as r, rgba as s, container as t, vh as u, subsetFonts as v, defaultMaxFetchBytes as w, FetchedImage as x, FetchLike as y };
1075
+ export { readBodyLimited as _, collectCodepoints as a, subsetFonts as c, FetchedImage as d, ImageFetchCache as f, prepareImages as g, fetchOk as h, GoogleFontsOptions as i, FetchLike as l, defaultMaxFetchBytes as m, GenericFontFamily as n, fontFromUrl as o, PrepareImagesOptions as p, GoogleFontFamily as r, googleFonts as s, FontSubset as t, FetchOptions as u };
@@ -1,5 +1,4 @@
1
- import { c as TextNode, n as ImageNode, r as Node, t as ContainerNode } from "./types-BwfCrcx3.mjs";
2
- import { CSSProperties } from "react";
1
+ import { r as Node } from "./types-BwfCrcx3.cjs";
3
2
  //#region src/google-fonts-catalog.d.ts
4
3
  interface GoogleFontShapes {
5
4
  S0: {
@@ -976,6 +975,8 @@ declare function prepareImages<T extends {
976
975
  //#endregion
977
976
  //#region src/fonts.d.ts
978
977
  type FontStyle = "normal" | "italic";
978
+ /** CSS generic family keywords a font can claim. */
979
+ type GenericFontFamily = "serif" | "sans-serif" | "monospace" | "cursive" | "fantasy" | "system-ui" | "ui-serif" | "ui-sans-serif" | "ui-monospace" | "ui-rounded" | "emoji" | "math" | "fangsong";
979
980
  type WeightRange = `${number}..${number}`;
980
981
  type AxisValue = number | WeightRange;
981
982
  type KnownGoogleFontFamily = { [S in keyof GoogleFontShapes]: {
@@ -986,6 +987,8 @@ type KnownGoogleFontFamily = { [S in keyof GoogleFontShapes]: {
986
987
  style?: GoogleFontShapes[S]["style"] | GoogleFontShapes[S]["style"][];
987
988
  /** Variable axes to vary, each at a value or `"min..max"` range, e.g. `{ opsz: "14..32" }`. */
988
989
  axes?: [GoogleFontShapes[S]["axis"]] extends [never] ? never : Partial<Record<GoogleFontShapes[S]["axis"], AxisValue>>;
990
+ /** CSS generic family the loaded subsets claim, e.g. `"monospace"`. */
991
+ generic?: GenericFontFamily;
989
992
  }; }[keyof GoogleFontShapes];
990
993
  type GoogleFontName = GoogleFontShapeFamilies[keyof GoogleFontShapeFamilies];
991
994
  /**
@@ -998,6 +1001,8 @@ type GoogleFontFamily = GoogleFontName | (string & {}) | KnownGoogleFontFamily |
998
1001
  weight?: number | number[] | WeightRange;
999
1002
  style?: FontStyle | FontStyle[];
1000
1003
  axes?: Record<string, AxisValue>;
1004
+ /** CSS generic family the loaded subsets claim, e.g. `"monospace"`. */
1005
+ generic?: GenericFontFamily;
1001
1006
  };
1002
1007
  type GoogleFontsOptions = FetchOptions & {
1003
1008
  /** The families to load, each as a name or a name plus its weight/style axis. */
@@ -1029,6 +1034,8 @@ type FontSubset = {
1029
1034
  style?: string;
1030
1035
  /** Inclusive codepoint ranges this subset covers; empty covers everything. */
1031
1036
  ranges: [number, number][];
1037
+ /** CSS generic family the subset claims, from the family's `generic` option. */
1038
+ generic?: GenericFontFamily;
1032
1039
  /** Fetches the subset bytes. The renderer skips files it has already loaded. */
1033
1040
  data: () => Promise<ArrayBuffer>;
1034
1041
  };
@@ -1065,18 +1072,4 @@ declare function fontFromUrl(url: string, options?: FetchOptions): {
1065
1072
  */
1066
1073
  declare function googleFonts(options: GoogleFontsOptions | GoogleFontFamily[]): Promise<FontSubset[]>;
1067
1074
  //#endregion
1068
- //#region src/helpers.d.ts
1069
- declare function container(props: Omit<ContainerNode, "type">): ContainerNode;
1070
- declare function text(text: string, style?: CSSProperties): TextNode;
1071
- declare function text(props: Omit<TextNode, "type">): TextNode;
1072
- declare function image(props: Omit<ImageNode, "type">): ImageNode;
1073
- declare function style(style: CSSProperties): CSSProperties;
1074
- declare function percentage(percentage: number): `${number}%`;
1075
- declare function vw(vw: number): `${number}vw`;
1076
- declare function vh(vh: number): `${number}vh`;
1077
- declare function em(em: number): `${number}em`;
1078
- declare function rem(rem: number): `${number}rem`;
1079
- declare function fr(fr: number): `${number}fr`;
1080
- declare function rgba(r: number, g: number, b: number, a?: number): `rgb(${number} ${number} ${number} / ${number})`;
1081
- //#endregion
1082
- export { PrepareImagesOptions as C, readBodyLimited as D, prepareImages as E, ImageFetchCache as S, fetchOk as T, googleFonts as _, percentage as a, FetchOptions as b, style as c, vw as d, FontSubset as f, fontFromUrl as g, collectCodepoints as h, image as i, text as l, GoogleFontsOptions as m, em as n, rem as o, GoogleFontFamily as p, fr as r, rgba as s, container as t, vh as u, subsetFonts as v, defaultMaxFetchBytes as w, FetchedImage as x, FetchLike as y };
1075
+ export { readBodyLimited as _, collectCodepoints as a, subsetFonts as c, FetchedImage as d, ImageFetchCache as f, prepareImages as g, fetchOk as h, GoogleFontsOptions as i, FetchLike as l, defaultMaxFetchBytes as m, GenericFontFamily as n, fontFromUrl as o, PrepareImagesOptions as p, GoogleFontFamily as r, googleFonts as s, FontSubset as t, FetchOptions as u };
@@ -1 +1 @@
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 n=t.fetch??globalThis.fetch,r=t.timeout??5e3,i=r<=0?void 0:AbortSignal.timeout(r),a=[t.signal,t.init?.signal,i].filter(e=>e!==void 0),o=a.length?AbortSignal.any(a):void 0,s=await n(e,{...t.init,signal:o});if(!s.ok)throw Error(`HTTP ${s.status} ${s.statusText} fetching ${e}`);return s}async function n(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 r(e){return e.startsWith(`https://`)||e.startsWith(`http://`)}function i(t,n){if(typeof t==`string`)for(let i of t.matchAll(e)){let e=i[2]?.trim();e&&r(e)&&n.add(e)}else if(Array.isArray(t))for(let e of t)i(e,n)}function a(e){let t=new Set,n=e=>{let a=e=>{e&&(i(e.backgroundImage,t),i(e.maskImage,t))};if(a(e.style),a(e.preset),i(e.tw,t),e.type===`image`){typeof e.src==`string`&&r(e.src)&&t.add(e.src);return}if(e.type===`container`)for(let t of e.children??[])n(t)};return n(e),[...t]}function o(e,r,i){let a=i?.get(e);if(a)return a;let o=t(e,r).then(e=>n(e,r.maxBytes??33554432)).catch(t=>{throw i?.delete(e),t});return i?.set(e,o),o}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]}const c=new Map;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()}function d(e,r){return t(e,{...r,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=>n(e,r.maxBytes??2097152)).then(e=>new TextDecoder().decode(e))}function f(e,t){let n=t.cache??c,r=n.get(e);if(r)return r;let i=d(e,t);return n.set(e,i),i.catch(()=>n.delete(e)),i}const p=/(?:\/\*\s*([^*]+?)\s*\*\/\s*)?@font-face\s*\{([^}]*)\}/g;function m(e,r){let i=`${e.family} ${e.subset}`,a=e.ranges.map(([e,t])=>`${e}-${t}`).join(`,`);return{name:i,subsetOf:e.family,key:`${i}:${e.weight??``}:${e.style??``}:${a}`,weight:e.weight,style:e.style,ranges:e.ranges,data:()=>t(e.url,r).then(e=>n(e,r.maxBytes??33554432))}}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(p)){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}function v(e){let t=new Set,n=e=>{for(let n of e)t.add(n.codePointAt(0))},r=e=>{e.type===`text`?n(e.text):e.type===`container`&&e.children?.forEach(r)};return typeof e==`string`?n(e):Array.isArray(e)?e.forEach(r):r(e),t}function y(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 b({fonts:e,source:t}){let n=v(t);return e.filter(e=>y(e.ranges??[],n))}function x(e,r={}){return{key:e,data:()=>t(e,r).then(e=>n(e,r.maxBytes??33554432))}}async function S(e){if(Array.isArray(e)&&(e={families:e}),e.families.length===0)return[];let t=await f(u(e),e),n=new Map(e.families.map((e,t)=>[typeof e==`string`?e:e.name,t]));return _(g(t)).sort((e,t)=>(n.get(e.family)??0)-(n.get(t.family)??0)).map(t=>m(t,e))}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return 33554432}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return v}});
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 n=t.fetch??globalThis.fetch,r=t.timeout??5e3,i=r<=0?void 0:AbortSignal.timeout(r),a=[t.signal,t.init?.signal,i].filter(e=>e!==void 0),o=a.length?AbortSignal.any(a):void 0,s=await n(e,{...t.init,signal:o});if(!s.ok)throw Error(`HTTP ${s.status} ${s.statusText} fetching ${e}`);return s}async function n(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 r(e){return e.startsWith(`https://`)||e.startsWith(`http://`)}function i(t,n){if(typeof t==`string`)for(let i of t.matchAll(e)){let e=i[2]?.trim();e&&r(e)&&n.add(e)}else if(Array.isArray(t))for(let e of t)i(e,n)}function a(e){let t=new Set,n=e=>{let a=e=>{e&&(i(e.backgroundImage,t),i(e.maskImage,t))};if(a(e.style),a(e.preset),i(e.tw,t),e.type===`image`){typeof e.src==`string`&&r(e.src)&&t.add(e.src);return}if(e.type===`container`)for(let t of e.children??[])n(t)};return n(e),[...t]}function o(e,r,i){let a=i?.get(e);if(a)return a;let o=t(e,r).then(e=>n(e,r.maxBytes??33554432)).catch(t=>{throw i?.delete(e),t});return i?.set(e,o),o}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]}const c=new Map;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()}function d(e,r){return t(e,{...r,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=>n(e,r.maxBytes??2097152)).then(e=>new TextDecoder().decode(e))}function f(e,t){let n=t.cache??c,r=n.get(e);if(r)return r;let i=d(e,t);return n.set(e,i),i.catch(()=>n.delete(e)),i}const p=/(?:\/\*\s*([^*]+?)\s*\*\/\s*)?@font-face\s*\{([^}]*)\}/g;function m(e,r,i){let a=`${e.family} ${e.subset}`,o=e.ranges.map(([e,t])=>`${e}-${t}`).join(`,`);return{name:a,subsetOf:e.family,key:`${a}:${e.weight??``}:${e.style??``}:${o}:${i??``}`,weight:e.weight,style:e.style,ranges:e.ranges,generic:i,data:()=>t(e.url,r).then(e=>n(e,r.maxBytes??33554432))}}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(p)){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}function v(e){let t=new Set,n=e=>{for(let n of e)t.add(n.codePointAt(0))},r=e=>{e.type===`text`?n(e.text):e.type===`container`&&e.children?.forEach(r)};return typeof e==`string`?n(e):Array.isArray(e)?e.forEach(r):r(e),t}function y(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 b({fonts:e,source:t}){let n=v(t);return e.filter(e=>y(e.ranges??[],n))}function x(e,r={}){return{key:e,data:()=>t(e,r).then(e=>n(e,r.maxBytes??33554432))}}async function S(e){if(Array.isArray(e)&&(e={families:e}),e.families.length===0)return[];let t=await f(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(t)).sort((e,t)=>(n.get(e.family)??0)-(n.get(t.family)??0)).map(t=>m(t,e,r.get(t.family)))}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return 33554432}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return v}});
package/dist/html.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { r as Node } from "./types-BwfCrcx3.cjs";
2
- import "./index-BKo0H_Ng.cjs";
2
+ import "./index.cjs";
3
3
  //#region src/html/index.d.ts
4
4
  declare function fromHtml(html: string): {
5
5
  node: Node;
package/dist/html.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { r as Node } from "./types-BwfCrcx3.mjs";
2
- import "./index-CeiZbRFM.mjs";
2
+ import "./index.mjs";
3
3
  //#region src/html/index.d.ts
4
4
  declare function fromHtml(html: string): {
5
5
  node: Node;
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./fonts-uO6HxxV0.cjs"),t=require("./helpers-4kGcvc-Q.cjs");exports.collectCodepoints=e.t,exports.container=t.t,exports.defaultMaxFetchBytes=e.a,exports.em=t.n,exports.fetchOk=e.o,exports.fontFromUrl=e.n,exports.fr=t.r,exports.googleFonts=e.r,exports.image=t.i,exports.percentage=t.a,exports.prepareImages=e.s,exports.readBodyLimited=e.c,exports.rem=t.o,exports.rgba=t.s,exports.style=t.c,exports.subsetFonts=e.i,exports.text=t.l,exports.vh=t.u,exports.vw=t.d;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./fonts-D8OaJ4MQ.cjs"),t=require("./helpers-4kGcvc-Q.cjs");exports.collectCodepoints=e.t,exports.container=t.t,exports.defaultMaxFetchBytes=e.a,exports.em=t.n,exports.fetchOk=e.o,exports.fontFromUrl=e.n,exports.fr=t.r,exports.googleFonts=e.r,exports.image=t.i,exports.percentage=t.a,exports.prepareImages=e.s,exports.readBodyLimited=e.c,exports.rem=t.o,exports.rgba=t.s,exports.style=t.c,exports.subsetFonts=e.i,exports.text=t.l,exports.vh=t.u,exports.vw=t.d;
package/dist/index.d.cts CHANGED
@@ -1,3 +1,18 @@
1
1
  import { a as NodeMetadata, c as TextNode, i as NodeAttributes, n as ImageNode, o as ReactElementLike, r as Node, s as TextFit, t as ContainerNode } from "./types-BwfCrcx3.cjs";
2
- import { C as PrepareImagesOptions, D as readBodyLimited, E as prepareImages, S as ImageFetchCache, T as fetchOk, _ as googleFonts, a as percentage, b as FetchOptions, c as style, d as vw, f as FontSubset, g as fontFromUrl, h as collectCodepoints, i as image, l as text, m as GoogleFontsOptions, n as em, o as rem, p as GoogleFontFamily, r as fr, s as rgba, t as container, u as vh, v as subsetFonts, w as defaultMaxFetchBytes, x as FetchedImage, y as FetchLike } from "./index-BKo0H_Ng.cjs";
3
- export { ContainerNode, FetchLike, FetchOptions, FetchedImage, FontSubset, GoogleFontFamily, GoogleFontsOptions, ImageFetchCache, ImageNode, Node, NodeAttributes, NodeMetadata, PrepareImagesOptions, ReactElementLike, TextFit, TextNode, collectCodepoints, container, defaultMaxFetchBytes, em, fetchOk, fontFromUrl, fr, googleFonts, image, percentage, prepareImages, readBodyLimited, rem, rgba, style, subsetFonts, text, vh, vw };
2
+ import { _ as readBodyLimited, a as collectCodepoints, c as subsetFonts, d as FetchedImage, f as ImageFetchCache, g as prepareImages, h as fetchOk, i as GoogleFontsOptions, l as FetchLike, m as defaultMaxFetchBytes, n as GenericFontFamily, o as fontFromUrl, p as PrepareImagesOptions, r as GoogleFontFamily, s as googleFonts, t as FontSubset, u as FetchOptions } from "./fonts-CziVseDZ.cjs";
3
+ import { CSSProperties } from "react";
4
+ //#region src/helpers.d.ts
5
+ declare function container(props: Omit<ContainerNode, "type">): ContainerNode;
6
+ declare function text(text: string, style?: CSSProperties): TextNode;
7
+ declare function text(props: Omit<TextNode, "type">): TextNode;
8
+ declare function image(props: Omit<ImageNode, "type">): ImageNode;
9
+ declare function style(style: CSSProperties): CSSProperties;
10
+ declare function percentage(percentage: number): `${number}%`;
11
+ declare function vw(vw: number): `${number}vw`;
12
+ declare function vh(vh: number): `${number}vh`;
13
+ declare function em(em: number): `${number}em`;
14
+ declare function rem(rem: number): `${number}rem`;
15
+ declare function fr(fr: number): `${number}fr`;
16
+ declare function rgba(r: number, g: number, b: number, a?: number): `rgb(${number} ${number} ${number} / ${number})`;
17
+ //#endregion
18
+ export { ContainerNode, FetchLike, FetchOptions, FetchedImage, FontSubset, GenericFontFamily, GoogleFontFamily, GoogleFontsOptions, ImageFetchCache, ImageNode, Node, NodeAttributes, NodeMetadata, PrepareImagesOptions, ReactElementLike, 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,3 +1,18 @@
1
1
  import { a as NodeMetadata, c as TextNode, i as NodeAttributes, n as ImageNode, o as ReactElementLike, r as Node, s as TextFit, t as ContainerNode } from "./types-BwfCrcx3.mjs";
2
- import { C as PrepareImagesOptions, D as readBodyLimited, E as prepareImages, S as ImageFetchCache, T as fetchOk, _ as googleFonts, a as percentage, b as FetchOptions, c as style, d as vw, f as FontSubset, g as fontFromUrl, h as collectCodepoints, i as image, l as text, m as GoogleFontsOptions, n as em, o as rem, p as GoogleFontFamily, r as fr, s as rgba, t as container, u as vh, v as subsetFonts, w as defaultMaxFetchBytes, x as FetchedImage, y as FetchLike } from "./index-CeiZbRFM.mjs";
3
- export { ContainerNode, FetchLike, FetchOptions, FetchedImage, FontSubset, GoogleFontFamily, GoogleFontsOptions, ImageFetchCache, ImageNode, Node, NodeAttributes, NodeMetadata, PrepareImagesOptions, ReactElementLike, TextFit, TextNode, collectCodepoints, container, defaultMaxFetchBytes, em, fetchOk, fontFromUrl, fr, googleFonts, image, percentage, prepareImages, readBodyLimited, rem, rgba, style, subsetFonts, text, vh, vw };
2
+ import { _ as readBodyLimited, a as collectCodepoints, c as subsetFonts, d as FetchedImage, f as ImageFetchCache, g as prepareImages, h as fetchOk, i as GoogleFontsOptions, l as FetchLike, m as defaultMaxFetchBytes, n as GenericFontFamily, o as fontFromUrl, p as PrepareImagesOptions, r as GoogleFontFamily, s as googleFonts, t as FontSubset, u as FetchOptions } from "./fonts-CAwVZx4X.mjs";
3
+ import { CSSProperties } from "react";
4
+ //#region src/helpers.d.ts
5
+ declare function container(props: Omit<ContainerNode, "type">): ContainerNode;
6
+ declare function text(text: string, style?: CSSProperties): TextNode;
7
+ declare function text(props: Omit<TextNode, "type">): TextNode;
8
+ declare function image(props: Omit<ImageNode, "type">): ImageNode;
9
+ declare function style(style: CSSProperties): CSSProperties;
10
+ declare function percentage(percentage: number): `${number}%`;
11
+ declare function vw(vw: number): `${number}vw`;
12
+ declare function vh(vh: number): `${number}vh`;
13
+ declare function em(em: number): `${number}em`;
14
+ declare function rem(rem: number): `${number}rem`;
15
+ declare function fr(fr: number): `${number}fr`;
16
+ declare function rgba(r: number, g: number, b: number, a?: number): `rgb(${number} ${number} ${number} / ${number})`;
17
+ //#endregion
18
+ export { ContainerNode, FetchLike, FetchOptions, FetchedImage, FontSubset, GenericFontFamily, GoogleFontFamily, GoogleFontsOptions, ImageFetchCache, ImageNode, Node, NodeAttributes, NodeMetadata, PrepareImagesOptions, ReactElementLike, 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,n as r,o as i,r as a,s as o,t as s}from"./fonts-B4N9qU8h.mjs";import{a as c,c as l,d as u,i as d,l as f,n as p,o as m,r as h,s as g,t as _,u as v}from"./helpers-CVQCT1Rh.mjs";export{s as collectCodepoints,_ as container,e as defaultMaxFetchBytes,p as em,i as fetchOk,r as fontFromUrl,h as fr,a as googleFonts,d as image,c as percentage,o as prepareImages,t as readBodyLimited,m as rem,g as rgba,l as style,n as subsetFonts,f as text,v as vh,u as vw};
1
+ import{a as e,c as t,i as n,n as r,o as i,r as a,s as o,t as s}from"./fonts-Bmi5c76G.mjs";import{a as c,c as l,d as u,i as d,l as f,n as p,o as m,r as h,s as g,t as _,u as v}from"./helpers-CVQCT1Rh.mjs";export{s as collectCodepoints,_ as container,e as defaultMaxFetchBytes,p as em,i as fetchOk,r as fontFromUrl,h as fr,a as googleFonts,d as image,c as percentage,o as prepareImages,t as readBodyLimited,m as rem,g as rgba,l as style,n as subsetFonts,f as text,v as vh,u as vw};
package/dist/renderer.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./fonts-uO6HxxV0.cjs");function t(e){return e instanceof Uint8Array||e instanceof ArrayBuffer||typeof Buffer<`u`&&Buffer.isBuffer(e)}function n(e){return t(e)?e:typeof e.data==`function`?e.data():e.data}function r(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 i(e){let{sources:t=[],cache:n}=Array.isArray(e)?{sources:e}:e,r=new Map;for(let e of t)r.set(e.src,e);return Promise.all([...r.values()].map(async({src:e,data:t,cache:r})=>({src:e,data:typeof t==`function`?await t():t,cache:r??n})))}var a=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(i){let a=typeof i==`string`?e.n(i):i,o=r(a),s=this.getFont(o);if(s)return s;let c=n(a),l=Promise.resolve(c).then(e=>this.registerInner(t(a)?e:{...a,data:e})).catch(e=>{throw this.deleteFont(o),e});return this.setFont(o,l),l}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 i(t):void 0,fontFamilies:n??r}}};async function o(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.i({fonts:l,source:r}),s,a);return o?.throwIfAborted(),{options:{...c,...u},signal:o}}exports.FontRegistry=a,exports.prepareRenderInput=o,exports.resolveImageLoaders=i;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./fonts-D8OaJ4MQ.cjs");function t(e){return e instanceof Uint8Array||e instanceof ArrayBuffer||typeof Buffer<`u`&&Buffer.isBuffer(e)}function n(e){return t(e)?e:typeof e.data==`function`?e.data():e.data}function r(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 i(e){let{sources:t=[],cache:n}=Array.isArray(e)?{sources:e}:e,r=new Map;for(let e of t)r.set(e.src,e);return Promise.all([...r.values()].map(async({src:e,data:t,cache:r})=>({src:e,data:typeof t==`function`?await t():t,cache:r??n})))}var a=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(i){let a=typeof i==`string`?e.n(i):i,o=r(a),s=this.getFont(o);if(s)return s;let c=n(a),l=Promise.resolve(c).then(e=>this.registerInner(t(a)?e:{...a,data:e})).catch(e=>{throw this.deleteFont(o),e});return this.setFont(o,l),l}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 i(t):void 0,fontFamilies:n??r}}};async function o(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.i({fonts:l,source:r}),s,a);return o?.throwIfAborted(),{options:{...c,...u},signal:o}}exports.FontRegistry=a,exports.prepareRenderInput=o,exports.resolveImageLoaders=i;
@@ -1,4 +1,5 @@
1
1
  import { r as Node } from "./types-BwfCrcx3.cjs";
2
+ import { n as GenericFontFamily } from "./fonts-CziVseDZ.cjs";
2
3
  //#region src/renderer.d.ts
3
4
  /**
4
5
  * Shared wrapper primitives for the `@takumi-rs/core` (napi) and `@takumi-rs/wasm` renderer
@@ -23,6 +24,11 @@ type FontDetails = {
23
24
  * script routes to the subset that covers it.
24
25
  */
25
26
  subsetOf?: string;
27
+ /**
28
+ * CSS generic family keyword this font resolves for, so stacks ending in e.g.
29
+ * `monospace` reach it without naming the family.
30
+ */
31
+ generic?: GenericFontFamily;
26
32
  };
27
33
  /** A registered font, either detailed or raw bytes. */
28
34
  type Font = FontDetails | ByteBuf;
@@ -1,4 +1,5 @@
1
1
  import { r as Node } from "./types-BwfCrcx3.mjs";
2
+ import { n as GenericFontFamily } from "./fonts-CAwVZx4X.mjs";
2
3
  //#region src/renderer.d.ts
3
4
  /**
4
5
  * Shared wrapper primitives for the `@takumi-rs/core` (napi) and `@takumi-rs/wasm` renderer
@@ -23,6 +24,11 @@ type FontDetails = {
23
24
  * script routes to the subset that covers it.
24
25
  */
25
26
  subsetOf?: string;
27
+ /**
28
+ * CSS generic family keyword this font resolves for, so stacks ending in e.g.
29
+ * `monospace` reach it without naming the family.
30
+ */
31
+ generic?: GenericFontFamily;
26
32
  };
27
33
  /** A registered font, either detailed or raw bytes. */
28
34
  type Font = FontDetails | ByteBuf;
package/dist/renderer.mjs CHANGED
@@ -1 +1 @@
1
- import{i as e,n as t}from"./fonts-B4N9qU8h.mjs";function n(e){return e instanceof Uint8Array||e instanceof ArrayBuffer||typeof Buffer<`u`&&Buffer.isBuffer(e)}function r(e){return n(e)?e:typeof e.data==`function`?e.data():e.data}function i(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 a(e){let{sources:t=[],cache:n}=Array.isArray(e)?{sources:e}:e,r=new Map;for(let e of t)r.set(e.src,e);return Promise.all([...r.values()].map(async({src:e,data:t,cache:r})=>({src:e,data:typeof t==`function`?await t():t,cache:r??n})))}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(e){let a=typeof e==`string`?t(e):e,o=i(a),s=this.getFont(o);if(s)return s;let c=r(a),l=Promise.resolve(c).then(e=>this.registerInner(n(a)?e:{...a,data:e})).catch(e=>{throw this.deleteFont(o),e});return this.setFont(o,l),l}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({fonts:l,source:r}),s,a);return o?.throwIfAborted(),{options:{...c,...u},signal:o}}export{o as FontRegistry,s as prepareRenderInput,a as resolveImageLoaders};
1
+ import{i as e,n as t}from"./fonts-Bmi5c76G.mjs";function n(e){return e instanceof Uint8Array||e instanceof ArrayBuffer||typeof Buffer<`u`&&Buffer.isBuffer(e)}function r(e){return n(e)?e:typeof e.data==`function`?e.data():e.data}function i(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 a(e){let{sources:t=[],cache:n}=Array.isArray(e)?{sources:e}:e,r=new Map;for(let e of t)r.set(e.src,e);return Promise.all([...r.values()].map(async({src:e,data:t,cache:r})=>({src:e,data:typeof t==`function`?await t():t,cache:r??n})))}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(e){let a=typeof e==`string`?t(e):e,o=i(a),s=this.getFont(o);if(s)return s;let c=r(a),l=Promise.resolve(c).then(e=>this.registerInner(n(a)?e:{...a,data:e})).catch(e=>{throw this.deleteFont(o),e});return this.setFont(o,l),l}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({fonts:l,source:r}),s,a);return o?.throwIfAborted(),{options:{...c,...u},signal:o}}export{o as FontRegistry,s as prepareRenderInput,a as resolveImageLoaders};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takumi-rs/helpers",
3
- "version": "2.1.2",
3
+ "version": "2.2.0",
4
4
  "description": "Utility helpers for converting JSX/HTML to Takumi node trees, loading fonts, and processing emoji.",
5
5
  "keywords": [
6
6
  "css",