-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat_script.py
More file actions
57 lines (50 loc) · 1.64 KB
/
Copy pathformat_script.py
File metadata and controls
57 lines (50 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import re
with open('src/components/LiquidHover.jsx', 'r') as f:
content = f.read()
# Remove imports
content = re.sub(r'import\s+\{\s*jsx\s+as\s+_jsx\s*\}\s+from\s+"react/jsx-runtime";\n', '', content)
content = re.sub(r'import\s+\{\s*addPropertyControls[^}]+\}\s+from\s+"framer";\n', '', content)
content = re.sub(r'import\s+\{\s*ComponentMessage[^}]+\}\s+from\s+"[^"]+";\n', '', content)
# Remove framer metadata at the top
content = re.sub(r'/\*\*.*?\*/\s*', '', content, flags=re.DOTALL)
# Re-write the return block
return_block_pattern = r'return /\*#__PURE__\*/ _jsx\("div", \{.*?\n\}\);\n\}'
def replacer(match):
return """
return (
<div
ref={containerRef}
style={{
position: "relative",
width: "100%",
height: "100%",
overflow: "visible",
top: "0%",
left: "0%",
}}
>
{image && image.src ? (
<canvas
ref={canvasRef}
style={{
position: "absolute",
top: "-10%",
left: "-10%",
width: "120%",
height: "120%",
overflow: "hidden",
pointerEvents: "none"
}}
/>
) : null}
</div>
);
}
"""
content = re.sub(r'return\s+/\*#__PURE__\*/\s*_jsx\("div",\s*\{.*?\n\}\);', replacer, content, flags=re.DOTALL)
# Remove trailing metadata
content = content.split('addPropertyControls(LiquidHover, {')[0]
# Prepend correct react import
content = "import React, { useEffect, useRef } from 'react';\n" + content.replace('import { useEffect, useRef } from "react";', '')
with open('src/components/LiquidHover.jsx', 'w') as f:
f.write(content.strip())