1- <!DOCTYPE html>
1+ <!doctype html>
22< html lang ="en ">
33 < head >
44 < meta charset ="UTF-8 " />
55 < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
66 < title > Go Web — Iframe Embed Test</ title >
77 < style >
8- * { box-sizing : border-box; margin : 0 ; padding : 0 ; }
8+ * {
9+ box-sizing : border-box;
10+ margin : 0 ;
11+ padding : 0 ;
12+ }
913
1014 body {
11- font-family : -apple-system, BlinkMacSystemFont, 'Inter' , 'Segoe UI' , sans-serif;
15+ font-family :
16+ -apple-system, BlinkMacSystemFont, 'Inter' , 'Segoe UI' , sans-serif;
1217 background : # f0f0f0 ;
1318 color : # 333 ;
1419 padding : 40px ;
2934 height : 500px ;
3035 border-radius : 12px ;
3136 overflow : hidden;
32- box-shadow : 0 4px 24px rgba (0 , 0 , 0 , 0.12 );
37+ box-shadow : 0 4px 24px rgba (0 , 0 , 0 , 0.12 );
3338 margin-bottom : 32px ;
3439 }
3540
4954 font-size : 14px ;
5055 }
5156
52- button : hover { background : # f5f5f5 ; }
53- button .active { background : # 0071e3 ; color : # fff ; border-color : # 0071e3 ; }
57+ button : hover {
58+ background : # f5f5f5 ;
59+ }
60+ button .active {
61+ background : # 0071e3 ;
62+ color : # fff ;
63+ border-color : # 0071e3 ;
64+ }
5465
5566 code {
5667 background : # e8e8e8 ;
8697 font-size : 14px ;
8798 line-height : 1.5 ;
8899 }
89-
90100 </ style >
91101 </ head >
92102 < body >
93103 < h1 > Iframe Embed API Test</ h1 >
94104 < p >
95105 This page demonstrates the < code > @lynx-js/go-web</ code > iframe embed API.
96- It loads the Go component inside an iframe via a pure JS < code > mount() </ code > call —
97- no React dependency needed on the host page.
106+ It loads the Go component inside an iframe via a pure JS
107+ < code > mount() </ code > call — no React dependency needed on the host page.
98108 </ p >
99109
100110 < div class ="info ">
101- < strong > How to test:</ strong > < br />
102- 1. Start dev server: < code > cd example && pnpm dev</ code > (serves on < strong > localhost:5969</ strong > )< br />
103- 2. Open this file in a browser (or < code > npx serve example-iframe-embed</ code > )< br />
104- Example data is proxied from < strong > go.lynxjs.org</ strong > via < code > /proxy-lynx-examples</ code > .
111+ < strong > How to test:</ strong > < br />
112+ 1. Start dev server: < code > cd example && pnpm dev</ code > (serves on
113+ < strong > localhost:5969</ strong > )< br />
114+ 2. Open this file in a browser (or
115+ < code > npx serve example-iframe-embed</ code > )< br />
116+ Example data is proxied from < strong > go.lynxjs.org</ strong > via
117+ < code > /proxy-lynx-examples</ code > .
105118 </ div >
106119
107120 < h2 > Usage</ h2 >
108- < div class ="code-block "> <div id="demo" style="height: 500px"></div>
109- <script type="module">
110- import { mount } from 'https://go.lynxjs.org/embed.js';
111- mount('#demo', {
112- example: 'hello-world',
113- defaultFile: 'src/App.tsx',
114- exampleBasePath: 'https://go.lynxjs.org/lynx-examples',
115- });
116- </script></ div >
121+ < div class ="code-block ">
122+ <div id="demo" style="height: 500px"></div> <script
123+ type="module"> import { mount } from 'https://go.lynxjs.org/embed.js';
124+ mount('#demo', { example: 'hello-world', defaultFile: 'src/App.tsx',
125+ exampleBasePath: 'https://go.lynxjs.org/lynx-examples', });
126+ </script>
127+ </ div >
117128
118129 < h2 > Live Demo</ h2 >
119130
@@ -138,9 +149,10 @@ <h2>Live Demo</h2>
138149 // ---------------------------------------------------------------------------
139150
140151 function mount ( container , options ) {
141- const el = typeof container === 'string'
142- ? document . querySelector ( container )
143- : container ;
152+ const el =
153+ typeof container === 'string'
154+ ? document . querySelector ( container )
155+ : container ;
144156
145157 if ( ! el ) throw new Error ( 'Container not found: ' + container ) ;
146158
@@ -155,10 +167,13 @@ <h2>Live Demo</h2>
155167 function handleMessage ( event ) {
156168 if ( event . source !== iframe . contentWindow ) return ;
157169 if ( event . data ?. type === 'go-embed:ready' ) {
158- iframe . contentWindow . postMessage ( {
159- type : 'go-embed:init' ,
160- options : currentOptions ,
161- } , '*' ) ;
170+ iframe . contentWindow . postMessage (
171+ {
172+ type : 'go-embed:init' ,
173+ options : currentOptions ,
174+ } ,
175+ '*' ,
176+ ) ;
162177 }
163178 }
164179
@@ -170,10 +185,13 @@ <h2>Live Demo</h2>
170185 iframe,
171186 update ( newOptions ) {
172187 currentOptions = { ...currentOptions , ...newOptions } ;
173- iframe . contentWindow . postMessage ( {
174- type : 'go-embed:update' ,
175- options : newOptions ,
176- } , '*' ) ;
188+ iframe . contentWindow . postMessage (
189+ {
190+ type : 'go-embed:update' ,
191+ options : newOptions ,
192+ } ,
193+ '*' ,
194+ ) ;
177195 } ,
178196 destroy ( ) {
179197 window . removeEventListener ( 'message' , handleMessage ) ;
@@ -190,17 +208,28 @@ <h2>Live Demo</h2>
190208 // Try a few known examples; the production site doesn't expose a directory listing.
191209 // Requests go through the dev server proxy to avoid CORS.
192210 const knownExamples = [
193- 'hello-world' , 'text' , 'view' , 'image' , 'css' ,
194- 'scroll-view' , 'list' , 'navigator' ,
211+ 'hello-world' ,
212+ 'text' ,
213+ 'view' ,
214+ 'image' ,
215+ 'css' ,
216+ 'scroll-view' ,
217+ 'list' ,
218+ 'navigator' ,
195219 ] ;
196220
197221 const available = [ ] ;
198222 await Promise . all (
199223 knownExamples . map ( async ( name ) => {
200224 try {
201- const res = await fetch ( `${ EMBED_BASE } ${ EXAMPLE_BASE_PATH } /${ name } /example-metadata.json` , { method : 'HEAD' } ) ;
225+ const res = await fetch (
226+ `${ EMBED_BASE } ${ EXAMPLE_BASE_PATH } /${ name } /example-metadata.json` ,
227+ { method : 'HEAD' } ,
228+ ) ;
202229 if ( res . ok ) available . push ( name ) ;
203- } catch { /* skip */ }
230+ } catch {
231+ /* skip */
232+ }
204233 } ) ,
205234 ) ;
206235
@@ -237,7 +266,9 @@ <h2>Live Demo</h2>
237266 btn . textContent = ex . name ;
238267 if ( i === 0 ) btn . classList . add ( 'active' ) ;
239268 btn . addEventListener ( 'click' , ( ) => {
240- controls . querySelectorAll ( 'button' ) . forEach ( b => b . classList . remove ( 'active' ) ) ;
269+ controls
270+ . querySelectorAll ( 'button' )
271+ . forEach ( ( b ) => b . classList . remove ( 'active' ) ) ;
241272 btn . classList . add ( 'active' ) ;
242273 embed . destroy ( ) ;
243274 embed = mount ( '#demo' , {
@@ -249,7 +280,6 @@ <h2>Live Demo</h2>
249280 } ) ;
250281 controls . appendChild ( btn ) ;
251282 } ) ;
252-
253283 </ script >
254284 </ body >
255285</ html >
0 commit comments