@takumi-rs/helpers 2.5.11 → 2.6.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=/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))};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=i?.get(e);if(a)return a;let o=t(e,n).then(e=>r(e,n.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,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,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){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,n={}){return{key:e,data:()=>t(e,n).then(e=>r(e,n.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)))}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return 33554432}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return y}});
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))};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=i?.get(e);if(a)return a;let o=t(e,n).then(e=>r(e,n.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,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 33554432}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return b}});
@@ -1028,6 +1028,8 @@ type FontSubset = {
1028
1028
  name: string;
1029
1029
  /** Logical family authors reference in `font-family`; expands to every loaded subset. */
1030
1030
  subsetOf: string;
1031
+ /** Position in the group's fallback order, from the lowest codepoint the subset declares. */
1032
+ subsetRank: number;
1031
1033
  /** Stable dedup key (`"{name}:{weight}:{style}:{range}"`), independent of the rotating woff2 URL. */
1032
1034
  key: string;
1033
1035
  weight?: number;
@@ -1039,8 +1041,13 @@ type FontSubset = {
1039
1041
  /** Fetches the subset bytes. The renderer skips files it has already loaded. */
1040
1042
  data: () => Promise<ArrayBuffer>;
1041
1043
  };
1044
+ /**
1045
+ * A codepoint source: content trees, plus loose strings for text a backend injects that no
1046
+ * node carries, such as the digits a PDF page counter fills in.
1047
+ */
1048
+ type CodepointSource = string | Node | (string | Node)[];
1042
1049
  /** Collect every codepoint the content will render. */
1043
- declare function collectCodepoints(source: string | Node | Node[]): Set<number>;
1050
+ declare function collectCodepoints(source: CodepointSource): Set<number>;
1044
1051
  /**
1045
1052
  * Keep the subsets `source` renders, dropping the rest. Range-less fallbacks (a full font or a
1046
1053
  * `text=` subset) always stay. Runs without network, so a renderer can apply it to the final
@@ -1048,7 +1055,7 @@ declare function collectCodepoints(source: string | Node | Node[]): Set<number>;
1048
1055
  */
1049
1056
  declare function subsetFonts<T>({ fonts, source }: {
1050
1057
  fonts: T[];
1051
- source: string | Node | Node[];
1058
+ source: CodepointSource;
1052
1059
  }): T[];
1053
1060
  /**
1054
1061
  * Turn a font URL into a loader: fetches the bytes on demand, keyed by the URL so repeated renders
@@ -1072,4 +1079,4 @@ declare function fontFromUrl(url: string, options?: FetchOptions): {
1072
1079
  */
1073
1080
  declare function googleFonts(options: GoogleFontsOptions | GoogleFontFamily[]): Promise<FontSubset[]>;
1074
1081
  //#endregion
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 };
1082
+ export { prepareImages as _, GoogleFontsOptions as a, googleFonts as c, FetchOptions as d, FetchedImage as f, fetchOk as g, defaultMaxFetchBytes as h, GoogleFontFamily as i, subsetFonts as l, PrepareImagesOptions as m, FontSubset as n, collectCodepoints as o, ImageFetchCache as p, GenericFontFamily as r, fontFromUrl as s, CodepointSource as t, FetchLike as u, readBodyLimited as v };
@@ -1028,6 +1028,8 @@ type FontSubset = {
1028
1028
  name: string;
1029
1029
  /** Logical family authors reference in `font-family`; expands to every loaded subset. */
1030
1030
  subsetOf: string;
1031
+ /** Position in the group's fallback order, from the lowest codepoint the subset declares. */
1032
+ subsetRank: number;
1031
1033
  /** Stable dedup key (`"{name}:{weight}:{style}:{range}"`), independent of the rotating woff2 URL. */
1032
1034
  key: string;
1033
1035
  weight?: number;
@@ -1039,8 +1041,13 @@ type FontSubset = {
1039
1041
  /** Fetches the subset bytes. The renderer skips files it has already loaded. */
1040
1042
  data: () => Promise<ArrayBuffer>;
1041
1043
  };
1044
+ /**
1045
+ * A codepoint source: content trees, plus loose strings for text a backend injects that no
1046
+ * node carries, such as the digits a PDF page counter fills in.
1047
+ */
1048
+ type CodepointSource = string | Node | (string | Node)[];
1042
1049
  /** Collect every codepoint the content will render. */
1043
- declare function collectCodepoints(source: string | Node | Node[]): Set<number>;
1050
+ declare function collectCodepoints(source: CodepointSource): Set<number>;
1044
1051
  /**
1045
1052
  * Keep the subsets `source` renders, dropping the rest. Range-less fallbacks (a full font or a
1046
1053
  * `text=` subset) always stay. Runs without network, so a renderer can apply it to the final
@@ -1048,7 +1055,7 @@ declare function collectCodepoints(source: string | Node | Node[]): Set<number>;
1048
1055
  */
1049
1056
  declare function subsetFonts<T>({ fonts, source }: {
1050
1057
  fonts: T[];
1051
- source: string | Node | Node[];
1058
+ source: CodepointSource;
1052
1059
  }): T[];
1053
1060
  /**
1054
1061
  * Turn a font URL into a loader: fetches the bytes on demand, keyed by the URL so repeated renders
@@ -1072,4 +1079,4 @@ declare function fontFromUrl(url: string, options?: FetchOptions): {
1072
1079
  */
1073
1080
  declare function googleFonts(options: GoogleFontsOptions | GoogleFontFamily[]): Promise<FontSubset[]>;
1074
1081
  //#endregion
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 };
1082
+ export { prepareImages as _, GoogleFontsOptions as a, googleFonts as c, FetchOptions as d, FetchedImage as f, fetchOk as g, defaultMaxFetchBytes as h, GoogleFontFamily as i, subsetFonts as l, PrepareImagesOptions as m, FontSubset as n, collectCodepoints as o, ImageFetchCache as p, GenericFontFamily as r, fontFromUrl as s, CodepointSource as t, FetchLike as u, readBodyLimited as v };
@@ -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,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))};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=r?.get(e);if(a)return a;let o=n(e,t).then(e=>i(e,t.maxBytes??33554432)).catch(t=>{throw r?.delete(e),t});return r?.set(e,o),o}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,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){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(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?_(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=>{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 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,t={}){return{key:e,data:()=>n(e,t).then(e=>i(e,t.maxBytes??33554432))}}async function w(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 y(v(t)).sort((e,t)=>(n.get(e.family)??0)-(n.get(t.family)??0)).map(t=>g(t,e,r.get(t.family)))}export{e as a,i as c,S as i,C as n,n as o,w as r,l as s,b 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,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))};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=r?.get(e);if(a)return a;let o=n(e,t).then(e=>i(e,t.maxBytes??33554432)).catch(t=>{throw r?.delete(e),t});return r?.set(e,o),o}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}function x(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 S(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 C({fonts:e,source:t}){let n=x(t);return e.filter(e=>S(e.ranges??[],n))}function w(e,t={}){return{key:e,data:()=>n(e,t).then(e=>i(e,t.maxBytes??33554432))}}async function T(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{e as a,i as c,C as i,w as n,n as o,T as r,l as s,x as t};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./fonts-BT1cVqWh.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-B330_3WH.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,5 +1,5 @@
1
1
  import { a as NodeMetadata, c as TextFit, i as NodeAttributes, l as TextNode, n as ImageNode, o as ReactElementLike, r as Node, s as RgbaImage, t as ContainerNode } from "./types-Bfi8SERZ.cjs";
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-BFt44wX3.cjs";
2
+ import { _ as prepareImages, a as GoogleFontsOptions, c as googleFonts, d as FetchOptions, f as FetchedImage, g as fetchOk, h as defaultMaxFetchBytes, i as GoogleFontFamily, l as subsetFonts, m as PrepareImagesOptions, n as FontSubset, o as collectCodepoints, p as ImageFetchCache, r as GenericFontFamily, s as fontFromUrl, t as CodepointSource, u as FetchLike, v as readBodyLimited } from "./fonts-B7Uovvva.cjs";
3
3
  import { CSSProperties } from "react";
4
4
  //#region src/helpers.d.ts
5
5
  declare function container(props: Omit<ContainerNode, "type">): ContainerNode;
@@ -15,4 +15,4 @@ declare function rem(rem: number): `${number}rem`;
15
15
  declare function fr(fr: number): `${number}fr`;
16
16
  declare function rgba(r: number, g: number, b: number, a?: number): `rgb(${number} ${number} ${number} / ${number})`;
17
17
  //#endregion
18
- export { ContainerNode, FetchLike, FetchOptions, FetchedImage, FontSubset, GenericFontFamily, GoogleFontFamily, GoogleFontsOptions, ImageFetchCache, ImageNode, Node, NodeAttributes, NodeMetadata, PrepareImagesOptions, ReactElementLike, RgbaImage, TextFit, TextNode, collectCodepoints, container, defaultMaxFetchBytes, em, fetchOk, fontFromUrl, fr, googleFonts, image, percentage, prepareImages, readBodyLimited, rem, rgba, style, subsetFonts, text, vh, vw };
18
+ export { CodepointSource, ContainerNode, FetchLike, FetchOptions, FetchedImage, FontSubset, GenericFontFamily, GoogleFontFamily, GoogleFontsOptions, ImageFetchCache, ImageNode, Node, NodeAttributes, NodeMetadata, PrepareImagesOptions, ReactElementLike, RgbaImage, 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,5 +1,5 @@
1
1
  import { a as NodeMetadata, c as TextFit, i as NodeAttributes, l as TextNode, n as ImageNode, o as ReactElementLike, r as Node, s as RgbaImage, t as ContainerNode } from "./types-Bfi8SERZ.mjs";
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-aYq5UMvm.mjs";
2
+ import { _ as prepareImages, a as GoogleFontsOptions, c as googleFonts, d as FetchOptions, f as FetchedImage, g as fetchOk, h as defaultMaxFetchBytes, i as GoogleFontFamily, l as subsetFonts, m as PrepareImagesOptions, n as FontSubset, o as collectCodepoints, p as ImageFetchCache, r as GenericFontFamily, s as fontFromUrl, t as CodepointSource, u as FetchLike, v as readBodyLimited } from "./fonts-BXKULndO.mjs";
3
3
  import { CSSProperties } from "react";
4
4
  //#region src/helpers.d.ts
5
5
  declare function container(props: Omit<ContainerNode, "type">): ContainerNode;
@@ -15,4 +15,4 @@ declare function rem(rem: number): `${number}rem`;
15
15
  declare function fr(fr: number): `${number}fr`;
16
16
  declare function rgba(r: number, g: number, b: number, a?: number): `rgb(${number} ${number} ${number} / ${number})`;
17
17
  //#endregion
18
- export { ContainerNode, FetchLike, FetchOptions, FetchedImage, FontSubset, GenericFontFamily, GoogleFontFamily, GoogleFontsOptions, ImageFetchCache, ImageNode, Node, NodeAttributes, NodeMetadata, PrepareImagesOptions, ReactElementLike, RgbaImage, TextFit, TextNode, collectCodepoints, container, defaultMaxFetchBytes, em, fetchOk, fontFromUrl, fr, googleFonts, image, percentage, prepareImages, readBodyLimited, rem, rgba, style, subsetFonts, text, vh, vw };
18
+ export { CodepointSource, ContainerNode, FetchLike, FetchOptions, FetchedImage, FontSubset, GenericFontFamily, GoogleFontFamily, GoogleFontsOptions, ImageFetchCache, ImageNode, Node, NodeAttributes, NodeMetadata, PrepareImagesOptions, ReactElementLike, RgbaImage, 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-VUK5hilE.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-DWo7UO1I.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-BT1cVqWh.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.n(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.i({fonts:l,source:r}),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-B330_3WH.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.n(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.i({fonts:l,source:r}),s,a);return o?.throwIfAborted(),{options:{...c,...u},signal:o}}exports.FontRegistry=o,exports.prepareRenderInput=s,exports.resolveImageLoaders=a;
@@ -1,5 +1,4 @@
1
- import { r as Node } from "./types-Bfi8SERZ.cjs";
2
- import { n as GenericFontFamily } from "./fonts-BFt44wX3.cjs";
1
+ import { r as GenericFontFamily, t as CodepointSource } from "./fonts-B7Uovvva.cjs";
3
2
  //#region src/renderer.d.ts
4
3
  /**
5
4
  * Shared wrapper primitives for the `@takumi-rs/core` (napi) and `@takumi-rs/wasm` renderer
@@ -24,6 +23,12 @@ type FontDetails = {
24
23
  * script routes to the subset that covers it.
25
24
  */
26
25
  subsetOf?: string;
26
+ /**
27
+ * Where this subset sits in its group's fallback order; lowest is tried first, and equal
28
+ * ranks order by family name. A subset's `cmap` reaches past the range it was cut for, so
29
+ * the rank is what settles which subset serves a codepoint several of them encode.
30
+ */
31
+ subsetRank?: number;
27
32
  /**
28
33
  * CSS generic family keyword this font resolves for, so stacks ending in e.g.
29
34
  * `monospace` reach it without naming the family.
@@ -158,7 +163,7 @@ type ResolvedRenderOptions<TOptions> = Omit<TOptions, keyof RenderExtras | "font
158
163
  */
159
164
  declare function prepareRenderInput<TOptions extends RenderExtras & {
160
165
  fontFamilies?: string[];
161
- }, TFamily extends RegisteredFamilyLike>(registry: FontRegistry<TFamily>, options: TOptions, source: string | Node | Node[]): Promise<{
166
+ }, TFamily extends RegisteredFamilyLike>(registry: FontRegistry<TFamily>, options: TOptions, source: CodepointSource): Promise<{
162
167
  options: ResolvedRenderOptions<TOptions>;
163
168
  signal: AbortSignal | undefined;
164
169
  }>;
@@ -1,5 +1,4 @@
1
- import { r as Node } from "./types-Bfi8SERZ.mjs";
2
- import { n as GenericFontFamily } from "./fonts-aYq5UMvm.mjs";
1
+ import { r as GenericFontFamily, t as CodepointSource } from "./fonts-BXKULndO.mjs";
3
2
  //#region src/renderer.d.ts
4
3
  /**
5
4
  * Shared wrapper primitives for the `@takumi-rs/core` (napi) and `@takumi-rs/wasm` renderer
@@ -24,6 +23,12 @@ type FontDetails = {
24
23
  * script routes to the subset that covers it.
25
24
  */
26
25
  subsetOf?: string;
26
+ /**
27
+ * Where this subset sits in its group's fallback order; lowest is tried first, and equal
28
+ * ranks order by family name. A subset's `cmap` reaches past the range it was cut for, so
29
+ * the rank is what settles which subset serves a codepoint several of them encode.
30
+ */
31
+ subsetRank?: number;
27
32
  /**
28
33
  * CSS generic family keyword this font resolves for, so stacks ending in e.g.
29
34
  * `monospace` reach it without naming the family.
@@ -158,7 +163,7 @@ type ResolvedRenderOptions<TOptions> = Omit<TOptions, keyof RenderExtras | "font
158
163
  */
159
164
  declare function prepareRenderInput<TOptions extends RenderExtras & {
160
165
  fontFamilies?: string[];
161
- }, TFamily extends RegisteredFamilyLike>(registry: FontRegistry<TFamily>, options: TOptions, source: string | Node | Node[]): Promise<{
166
+ }, TFamily extends RegisteredFamilyLike>(registry: FontRegistry<TFamily>, options: TOptions, source: CodepointSource): Promise<{
162
167
  options: ResolvedRenderOptions<TOptions>;
163
168
  signal: AbortSignal | undefined;
164
169
  }>;
package/dist/renderer.mjs CHANGED
@@ -1 +1 @@
1
- import{i as e,n as t}from"./fonts-VUK5hilE.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:r}),s,a);return o?.throwIfAborted(),{options:{...c,...u},signal:o}}export{s as FontRegistry,c as prepareRenderInput,o as resolveImageLoaders};
1
+ import{i as e,n as t}from"./fonts-DWo7UO1I.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:r}),s,a);return o?.throwIfAborted(),{options:{...c,...u},signal:o}}export{s as FontRegistry,c as prepareRenderInput,o as resolveImageLoaders};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takumi-rs/helpers",
3
- "version": "2.5.11",
3
+ "version": "2.6.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",