gradio-pr-bot commited on
Commit
9fb6020
·
verified ·
1 Parent(s): 5b81432

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. 6.7.0/html/shared/HTML.svelte +54 -7
6.7.0/html/shared/HTML.svelte CHANGED
@@ -9,6 +9,7 @@
9
  html_template = "${value}",
10
  css_template = "",
11
  js_on_load = null,
 
12
  visible = true,
13
  autoscroll = false,
14
  apply_default_css = true,
@@ -304,6 +305,47 @@
304
  }
305
  }
306
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
  $effect(() => {
308
  if (!element || mounted) return;
309
  mounted = true;
@@ -357,14 +399,19 @@
357
  }
358
  scroll_on_html_update();
359
 
360
- if (js_on_load && element) {
361
- try {
362
- const func = new Function("element", "trigger", "props", js_on_load);
363
- func(element, trigger, reactiveProps);
364
- } catch (error) {
365
- console.error("Error executing js_on_load:", error);
366
  }
367
- }
 
 
 
 
 
 
 
 
368
  });
369
 
370
  // Props update effect
 
9
  html_template = "${value}",
10
  css_template = "",
11
  js_on_load = null,
12
+ head = null,
13
  visible = true,
14
  autoscroll = false,
15
  apply_default_css = true,
 
305
  }
306
  }
307
 
308
+ async function loadHead(headHtml: string): Promise<void> {
309
+ if (!headHtml) return;
310
+ const parser = new DOMParser();
311
+ const doc = parser.parseFromString(`<head>${headHtml}</head>`, "text/html");
312
+ const promises: Promise<void>[] = [];
313
+ for (const el of Array.from(doc.head.children)) {
314
+ if (el.tagName === "SCRIPT") {
315
+ const src = (el as HTMLScriptElement).src;
316
+ if (src) {
317
+ if (document.querySelector(`script[src="${src}"]`)) continue;
318
+ const script = document.createElement("script");
319
+ script.src = src;
320
+ promises.push(
321
+ new Promise<void>((resolve, reject) => {
322
+ script.onload = () => resolve();
323
+ script.onerror = () =>
324
+ reject(new Error(`Failed to load script: ${src}`));
325
+ })
326
+ );
327
+ document.head.appendChild(script);
328
+ } else {
329
+ const script = document.createElement("script");
330
+ script.textContent = el.textContent;
331
+ document.head.appendChild(script);
332
+ }
333
+ } else {
334
+ const existing =
335
+ el.tagName === "LINK" && (el as HTMLLinkElement).href
336
+ ? document.querySelector(
337
+ `link[href="${(el as HTMLLinkElement).href}"]`
338
+ )
339
+ : null;
340
+ if (!existing) {
341
+ document.head.appendChild(el.cloneNode(true));
342
+ }
343
+ }
344
+ }
345
+ await Promise.all(promises);
346
+ }
347
+
348
+ // Mount effect
349
  $effect(() => {
350
  if (!element || mounted) return;
351
  mounted = true;
 
399
  }
400
  scroll_on_html_update();
401
 
402
+ (async () => {
403
+ if (head) {
404
+ await loadHead(head);
 
 
 
405
  }
406
+ if (js_on_load && element) {
407
+ try {
408
+ const func = new Function("element", "trigger", "props", js_on_load);
409
+ func(element, trigger, reactiveProps);
410
+ } catch (error) {
411
+ console.error("Error executing js_on_load:", error);
412
+ }
413
+ }
414
+ })();
415
  });
416
 
417
  // Props update effect