Spaces:
Sleeping
Sleeping
fix: decomposed structure preview
Browse files
app.py
CHANGED
|
@@ -222,16 +222,18 @@ def create_error_html(message: str) -> str:
|
|
| 222 |
|
| 223 |
|
| 224 |
def create_svg_viewer_html(svg_content: str) -> str:
|
| 225 |
-
"""Create SVG viewer HTML
|
| 226 |
-
# Basic
|
| 227 |
-
|
|
|
|
|
|
|
| 228 |
|
| 229 |
return f"""
|
| 230 |
<div style='padding: 20px; background: #fff; border: 1px solid #eee; border-radius: 8px; display: block;'>
|
| 231 |
<div style='display: block; align-items: center; margin-bottom: 10px;'>
|
| 232 |
</div>
|
| 233 |
-
<div id='animation-container' style='min-height: 300px; display:
|
| 234 |
-
{
|
| 235 |
</div>
|
| 236 |
</div>
|
| 237 |
"""
|
|
@@ -320,8 +322,8 @@ def create_animation_preview(animation_desc: str, svg_content: str) -> tuple:
|
|
| 320 |
f.write(html_content)
|
| 321 |
print(f"Animation preview saved to: {html_path}")
|
| 322 |
|
| 323 |
-
# Create iframe HTML
|
| 324 |
-
safe_html_content =
|
| 325 |
preview_html = f"""
|
| 326 |
<div style='padding: 20px; background: #fff; border: 1px solid #eee; border-radius: 8px; display: block;'>
|
| 327 |
<div style='display: block; align-items: center; margin-bottom: 10px;'>
|
|
|
|
| 222 |
|
| 223 |
|
| 224 |
def create_svg_viewer_html(svg_content: str) -> str:
|
| 225 |
+
"""Create SVG viewer HTML."""
|
| 226 |
+
# Basic SVG validation - ensure it starts with <svg and ends with </svg>
|
| 227 |
+
svg_content = svg_content.strip()
|
| 228 |
+
if not svg_content.startswith('<svg') or not svg_content.endswith('</svg>'):
|
| 229 |
+
return create_error_html("Invalid SVG format")
|
| 230 |
|
| 231 |
return f"""
|
| 232 |
<div style='padding: 20px; background: #fff; border: 1px solid #eee; border-radius: 8px; display: block;'>
|
| 233 |
<div style='display: block; align-items: center; margin-bottom: 10px;'>
|
| 234 |
</div>
|
| 235 |
+
<div id='animation-container' style='min-height: 300px; display: flex; justify-content: center; align-items: center; background: #fafafa; border-radius: 4px; padding: 20px;'>
|
| 236 |
+
{svg_content}
|
| 237 |
</div>
|
| 238 |
</div>
|
| 239 |
"""
|
|
|
|
| 322 |
f.write(html_content)
|
| 323 |
print(f"Animation preview saved to: {html_path}")
|
| 324 |
|
| 325 |
+
# Create iframe HTML - only escape quotes for srcdoc attribute
|
| 326 |
+
safe_html_content = html_content.replace('"', '"')
|
| 327 |
preview_html = f"""
|
| 328 |
<div style='padding: 20px; background: #fff; border: 1px solid #eee; border-radius: 8px; display: block;'>
|
| 329 |
<div style='display: block; align-items: center; margin-bottom: 10px;'>
|