@@ -18,6 +18,7 @@ const displayFont = read(DMSerifDisplay).arrayBuffer();
1818 * Sources:
1919 * - https://github.com/huggingface/chat-ui/blob/ebeff50ac0ac4367a8e1a32b46dcc5ac2e8fc43f/src/routes/assistant/%5BassistantId%5D/thumbnail.png/%2Bserver.ts#L44-L82
2020 * - https://geoffrich.net/posts/svelte-social-image/
21+ * - https://github.com/sveltejs/svelte.dev/blob/497b6d5b2c67373a68833a22184cf409004e630d/apps/svelte.dev/src/routes/docs/%5Btopic%5D/%5B...path%5D/card.png/%2Bserver.ts
2122 */
2223export async function GET ( { url } ) {
2324 const renderedComponent = render ( Thumbnail , {
@@ -62,17 +63,7 @@ export async function GET({ url }) {
6263 . render ( )
6364 . asPng ( ) ;
6465
65- // `png` is not usable directly inside `new Response()` for some reason, TS says
66- let bodyData ;
67- if ( png instanceof ArrayBuffer ) {
68- bodyData = png ;
69- } else if ( png . buffer instanceof ArrayBuffer ) {
70- bodyData = png . buffer ;
71- } else {
72- bodyData = new Uint8Array ( png ) ;
73- }
74-
75- const response = new Response ( bodyData , {
66+ const response = new Response ( new Uint8Array ( png ) , {
7667 headers : {
7768 "Content-Type" : "image/png"
7869 }
@@ -87,15 +78,12 @@ type VNode = ReturnType<typeof html>;
8778 * Decodes the XML-ified parts of string subnodes
8879 * to revert to the original content
8980 *
90- * @param original the original node
81+ * @param node the original node
9182 * @returns the node with replaced leaves
9283 */
93- function decodeVNode ( original : VNode ) : VNode {
94- const children = original . props . children ;
95-
96- if ( ! children ) {
97- return original ;
98- }
84+ function decodeVNode ( node : VNode ) : VNode {
85+ const children = node . props . children ;
86+ if ( ! children ) return node ;
9987
10088 const decodedChildren =
10189 typeof children === "string"
@@ -104,13 +92,11 @@ function decodeVNode(original: VNode): VNode {
10492 ? children . map ( decodeVNode )
10593 : decodeVNode ( children ) ;
10694
107- if ( decodedChildren === children ) {
108- return original ;
109- }
95+ if ( decodedChildren === children ) return node ;
11096
11197 return {
112- ...original ,
113- props : { ...original . props , children : decodedChildren }
98+ ...node ,
99+ props : { ...node . props , children : decodedChildren }
114100 } ;
115101}
116102
0 commit comments