
    zi                        U d Z ddlmZ ddlZddlZddlmZ  ee      j                         j                  j                  Z
e
dz  Ze
dz  Zddd	Zd
ed<   ddhZddhZh dZddZddZddZddZedk(  r ej.                   e              yy)uN  IDS Phase 3 — Mobile Prototype Renderer.

Open a device frame HTML, inject the chosen scenario into the .screen-content
placeholder, and capture a viewport-sized PNG.

Usage:
    python3 render_prototype.py \
        --device iphone15pro \
        --mode light \
        --scenario dashboard \
        --output /abs/path/output.png
    )annotationsN)Pathframes	scenarios)i  iT  )i  i  )iphone15pro	pixel9prozdict[str, tuple[int, int]]DEVICE_VIEWPORTSr   r   lightdark>   	dashboardai_analysissignup_step1signup_step2signup_step3cardnews_publishinsurance_comparec                 <   t        j                  d      } | j                  ddt        t                     | j                  ddt        t
                     | j                  ddt        t                     | j                  ddd	
       | j                         S )NzMobile prototype renderer)descriptionz--deviceT)requiredchoicesz--modez
--scenarioz--outputzAbsolute output PNG path)r   help)argparseArgumentParseradd_argumentsortedVALID_DEVICESVALID_MODESVALID_SCENARIOS
parse_args)parsers    J/home/jay/workspace/skills/mobile-prototype-ko/scripts/render_prototype.pyr   r   +   s    $$1LMF

T6-;PQ
49LM
tVO=TU

T8RS    c                   t         |  dz  }|j                         st        d|       |j                  d      }|j	                         }|j                  d      }|j                  d      }d}|dk7  r|dk7  r|||t        d      z    }|j                  d	      }|dk7  r|j                  d
|      nd}|j                  d      }	d}
|dk7  r|	dk7  r||dz   |	 }
||
z   S )N.htmlzScenario not found: zutf-8)encodingz<stylez</style> z<body>z</body>   )SCENARIOS_DIRis_fileFileNotFoundError	read_textlowerfindlen)scenariopathrawr.   style_start	style_endstyle_block
body_startbody_open_end
body_close
body_inners              r!   load_scenario_bodyr;   4   s    hZu--D<<>"6tf =>>
..'.
*CIIKE**X&K

:&IKbY"_+	C
O(CDG$J1;r1ACHHS*-rMI&JJzR/*Z8
##r"   c                X   	 ddl m} t        |  d| dz  }|j                         st        d|       t        |    \  }}t        |      }	t        |      }
|
j                  j                  d	d	
               5 }|j                  j!                  d	      }|j#                  ||dd      }|j%                         }|j'                  |j)                         d       |j+                  d|	       |j-                  d       |j/                  t1        |
      dd       |j3                          d d d        |
j                         st5        d|
       y # t        $ r>}t        d| t        j
                         t	        j                  d       Y d }~d }~ww xY w# 1 sw Y   rxY w)Nr   )sync_playwrightzPlaywright not available: file   _r$   zFrame not found: T)parentsexist_ok)headless)widthheight)viewportdevice_scale_factorload)
wait_untilz(html) => {
                const el = document.querySelector('.screen-content');
                if (el) {
                    el.innerHTML = html;
                }
            }i,  F)r2   	full_pageomit_backgroundzScreenshot was not written to )playwright.sync_apir=   ImportErrorprintsysstderrexit
FRAMES_DIRr+   r,   r	   r;   r   parentmkdirchromiumlaunchnew_contextnew_pagegotoas_urievaluatewait_for_timeout
screenshotstrcloseRuntimeError)devicemoder1   outputr=   exc
frame_pathrE   rF   scenario_htmloutput_pathpwbrowsercontextpages                  r!   renderrm   I   s   7
 $u55J"3J< @AA$V,ME6&x0Mv,KTD9		 b++$$d$3%%$7 ! & 
 !		*##%&	9 	 	
 	c"S-PUV-0  ;K=IJJ !M  *3%0szzB s$   E ;B4F 	F3FF F)c                    t               } 	 t        | j                  | j                  | j                  | j
                         t        d| j
                          y# t        $ r(}t        d| t        j                         Y d }~yd }~ww xY w)Nzrender failed: r>   r)   zOK: r   )
r   rm   rb   rc   r1   rd   	ExceptionrO   rP   rQ   )argsre   s     r!   mainrq   v   sn    <Dt{{DIIt}}dkkB 
D
	  u%CJJ7s   6A 	B$BB__main__)returnzargparse.Namespace)r1   r_   rs   r_   )
rb   r_   rc   r_   r1   r_   rd   r_   rs   None)rs   int)__doc__
__future__r   r   rP   pathlibr   __file__resolverT   
SKILL_ROOTrS   r*   r	   __annotations__r   r   r   r   r;   rm   rq   __name__rR    r"   r!   <module>r      s    #  
 (^##%,,33
("
[( 0 , 
 ,$**KZ zCHHTV r"   