1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < meta charset ="utf-8 "/>
5
+ < title > Qwik-keyed</ title >
6
+ < link href ="/css/currentStyle.css " rel ="stylesheet "/>
7
+ </ head >
8
+ < body >
9
+ < div id ='main ' q:base ="/frameworks/keyed/qwik/dist/ "> </ div >
10
+ < script >
11
+ // TODO(misko): this should be loaded from URL.
12
+ ! ( function ( ) {
13
+ const qrlResolver = ( doc , element , eventUrl , _url , _base ) => {
14
+ if ( void 0 === eventUrl ) {
15
+ if ( element ) {
16
+ _url = element . getAttribute ( 'q:base' ) ;
17
+ _base = qrlResolver (
18
+ doc ,
19
+ element . parentNode && element . parentNode . closest ( '[q\\:base]' )
20
+ ) ;
21
+ } else {
22
+ _url = doc . baseURI ;
23
+ }
24
+ } else if ( eventUrl ) {
25
+ _url = eventUrl ;
26
+ _base = qrlResolver ( doc , element . closest ( '[q\\:base]' ) ) ;
27
+ }
28
+ return _url ? new URL ( _url , _base ) : void 0 ;
29
+ } ;
30
+ ( ( doc , hasInitialized ) => {
31
+ const ON_PREFIXES = [ 'on:' , 'on-window:' , 'on-document:' ] ;
32
+ const broadcast = async ( infix , type , event ) => {
33
+ type = type . replace ( / ( [ A - Z ] ) / g, ( a ) => '-' + a . toLowerCase ( ) ) ;
34
+ doc
35
+ . querySelectorAll ( '[on' + infix + '\\:' + type + ']' )
36
+ . forEach ( ( target ) => dispatch ( target , type , event ) ) ;
37
+ } ;
38
+ const dispatch = async ( element , eventName , ev , url , previousCtx , attrValue ) => {
39
+ for ( const on of ON_PREFIXES ) {
40
+ attrValue = element . getAttribute ( on + eventName ) || '' ;
41
+ for ( const qrl of attrValue . split ( '\n' ) ) {
42
+ if ( ( url = qrlResolver ( doc , element , qrl ) ) ) {
43
+ const handler = getModuleExport (
44
+ url ,
45
+ window [ url . pathname ] || ( await import ( String ( url ) . split ( '#' ) [ 0 ] ) )
46
+ ) ;
47
+ previousCtx = document . __q_context__ ;
48
+ try {
49
+ document . __q_context__ = [ element , ev , url ] ;
50
+ handler ( element , ev , url ) ;
51
+ } finally {
52
+ document . __q_context__ = previousCtx ;
53
+ }
54
+ }
55
+ }
56
+ }
57
+ } ;
58
+ const getModuleExport = ( url , module , exportName ) =>
59
+ module [ ( exportName = url . hash . replace ( / ^ # ? ( [ ^ ? [ | ] * ) .* $ / , '$1' ) || 'default' ) ] ||
60
+ ( ( msg ) => {
61
+ throw new Error ( 'QWIK: ' + msg ) ;
62
+ } ) ( url + ' does not export ' + exportName ) ;
63
+ const processEvent = async ( ev , element ) => {
64
+ if ( ( element = ev . target ) == doc ) {
65
+ setTimeout ( ( ) => broadcast ( '-document' , ev . type , ev ) ) ;
66
+ } else {
67
+ while ( element && element . getAttribute ) {
68
+ dispatch ( element , ev . type , ev ) ;
69
+ element = ev . bubbles ? element . parentElement : null ;
70
+ }
71
+ }
72
+ } ;
73
+ const addEventListener = ( eventName ) =>
74
+ doc . addEventListener ( eventName , processEvent , {
75
+ capture : ! 0 ,
76
+ } ) ;
77
+ const processReadyStateChange = ( readyState ) => {
78
+ readyState = doc . readyState ;
79
+ if ( ! hasInitialized && ( 'interactive' == readyState || 'complete' == readyState ) ) {
80
+ hasInitialized = 1 ;
81
+ broadcast ( '' , 'q-init' , new CustomEvent ( 'qInit' ) ) ;
82
+ }
83
+ } ;
84
+ {
85
+ const scriptTag = doc . querySelector ( 'script[events]' ) ;
86
+ if ( scriptTag ) {
87
+ ( scriptTag . getAttribute ( 'events' ) || '' ) . split ( / [ \s , ; ] + / ) . forEach ( addEventListener ) ;
88
+ } else {
89
+ for ( const key in doc ) {
90
+ if ( 0 == key . indexOf ( 'on' ) ) {
91
+ addEventListener ( key . substring ( 2 ) ) ;
92
+ }
93
+ }
94
+ }
95
+ }
96
+ doc . addEventListener ( 'readystatechange' , processReadyStateChange ) ;
97
+ processReadyStateChange ( ) ;
98
+ } ) ( document ) ;
99
+ } ) ( ) ;
100
+ </ script >
101
+ < script type ="module ">
102
+ // Because there is no SSR, we have to bootstrap from client.
103
+ import { clientBootstrap } from './dist/build/main.js' ;
104
+ clientBootstrap ( ) ;
105
+ </ script >
106
+ </ html >
0 commit comments