/
index.html
312 lines (262 loc) · 8.37 KB
/
index.html
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<!DOCTYPE html>
<head>
<meta charset="UTF-8" />
<link class="ico" rel="icon" type="image/svg+xml" href="favicon.ico" />
</head>
<link rel="icon" href="data:," />
<link rel="stylesheet" href="/raw.css" />
<h1>Assets</h1>
<p class="base"></p>
<h2>Raw References from publicDir</h2>
<ul>
<li class="raw-js"></li>
<script src="/raw.js"></script>
<li class="raw-css">
Raw CSS from publicDir should load (this should be red)
</li>
</ul>
<h2>Asset Imports from JS</h2>
<ul>
<li>Relative: <code class="asset-import-relative"></code></li>
<li>Absolute: <code class="asset-import-absolute"></code></li>
<li>From publicDir: <code class="public-import"></code></li>
</ul>
<h2>CSS url references</h2>
<div>Font should be loaded (all text should be italic)</div>
<div class="css-url-absolute">
<span style="background: #fff">CSS background (absolute)</span>
</div>
<div class="css-url-relative">
<span style="background: #fff">CSS background (relative)</span>
</div>
<div class="css-image-set-relative">
<span style="background: #fff"
>CSS background with image-set() (relative)</span
>
</div>
<div class="css-image-set-without-url-call">
<span style="background: #fff"
>CSS background with image-set() (relative)</span
>
</div>
<div class="css-url-relative-at-imported">
<span style="background: #fff"
>CSS background (relative from @imported file in different dir)</span
>
</div>
<div class="css-url-public">
<span style="background: #fff">CSS background (public)</span>
</div>
<div class="css-url-data-uri">
<span style="background: #fff">CSS background (data URI)</span>
</div>
<div class="css-url-base64-inline">
<span style="background: #fff">CSS background (base64 inline in prod)</span>
</div>
<div class="css-url-quotes-base64-inline">
<span style="background: #fff">CSS background (base64 inline in prod)</span>
</div>
<div class="css-url-same-line">
<span style="background: #fff"
>CSS background (multiple urls on same line)</span
>
</div>
<div class="css-url-aliased">
<span style="background: #fff">CSS background (aliased)</span>
</div>
<h2>Unicode URL</h2>
<div>
<code class="unicode-url"></code>
<img src="./nested/テスト-測試-white space.png" />
</div>
<h2>encodeURI for the address</h2>
<div>
<img
class="encodeURI"
src="./nested/%E3%83%86%E3%82%B9%E3%83%88-%E6%B8%AC%E8%A9%A6-white%20space.png"
/>
</div>
<h2>Image Src Set</h2>
<div>
<img
class="img-src-set"
src="./nested/asset.png"
srcset="./nested/asset.png 1x, ./nested/asset.png 2x"
alt=""
/>
</div>
<h2>SVG Fragments</h2>
<div>
<img
class="svg-frag-img"
src="./nested/fragment.svg#icon-clock-view"
alt=""
/>
<img
class="svg-frag-img"
src="./nested/fragment.svg#icon-heart-view"
alt=""
/>
<img
class="svg-frag-img"
src="./nested/fragment.svg#icon-arrow-right-view"
alt=""
/>
</div>
<h2>SVG Fragments via CSS background url</h2>
<div>
<span class="icon icon-clock"></span>
<span class="icon icon-heart"></span>
<span class="icon icon-arrow-right"></span>
</div>
<h2>SVG Fragments via JS Import</h2>
<div>
<p>Imported path: <code class="svg-frag-import-path"></code></p>
<img class="svg-frag-import" alt="" />
</div>
<h2>?raw import</h2>
<code class="raw"></code>
<h2>?url import</h2>
<code class="url"></code>
<h2>?url import with css</h2>
<code class="url-css"></code>
<h2>new URL('...', import.meta.url)</h2>
<img class="import-meta-url-img" />
<code class="import-meta-url"></code>
<h2>new URL('...', import.meta.url,) (with comma)</h2>
<img class="import-meta-url-img-comma" />
<code class="import-meta-url-comma"></code>
<h2>new URL('...', import.meta.url,) (with comma + new line)</h2>
<img class="import-meta-url-img-comma-nl" />
<code class="import-meta-url-comma-nl"></code>
<h2>new URL(`./${dynamic}`, import.meta.url)</h2>
<p>
<img class="dynamic-import-meta-url-img-1" />
<code class="dynamic-import-meta-url-1"></code>
</p>
<p>
<img class="dynamic-import-meta-url-img-2" />
<code class="dynamic-import-meta-url-2"></code>
</p>
<h2>new URL(`./${dynamic}`, import.meta.url,) (with comma)</h2>
<p>
<img class="dynamic-import-meta-url-img-1-comma" />
<code class="dynamic-import-meta-url-1-comma"></code>
</p>
<p>
<img class="dynamic-import-meta-url-img-2-comma" />
<code class="dynamic-import-meta-url-2-comma"></code>
</p>
<h2>new URL(`non-existent`, import.meta.url)</h2>
<p>
<code class="non-existent-import-meta-url"></code>
</p>
<h2>simple script tag import-expression</h2>
<code class="import-expression"></code>
<script>
import('./static/import-expression.js')
import('/import-expression.js')
</script>
<h2>url in style tag</h2>
<h3>url</h3>
<style class="style-url">
.style-url-assets {
background: url('./nested/asset.png');
background-size: 10px 10px;
}
</style>
<div style="background: url('./nested/asset.png'); background-size: 10px 10px">
inline style
</div>
<div class="style-url-assets">use style class</div>
<h3>base64</h3>
<style class="style-base64">
.style-base64-assets {
background: url('./static/icon.png');
}
</style>
<p class="inline-style-base64" style="background: url(./static/icon.png)">
inline style
</p>
<p class="style-base64-assets">use style class</p>
<h3 class="import-css">@import</h3>
<style class="style-import">
@import url('./css/import.css');
</style>
<h3 class="foo-public">
@import CSS from publicDir should load (this should be red)
</h3>
<h3 id="foo">import module css</h3>
<h3 class="raw-query"></h3>
<style>
@import '/foo.css';
</style>
<script type="module">
import './css/fonts.css'
import './css/css-url.css'
import './css/icons.css'
text('.base', `import.meta.${``}env.BASE_URL: ${import.meta.env.BASE_URL}`)
import url from './nested/asset.png'
text('.asset-import-relative', url)
import absoluteUrl from '/nested/asset.png'
text('.asset-import-absolute', absoluteUrl)
import publicUrl from '/icon.png'
text('.public-import', publicUrl)
import svgFrag from './nested/fragment.svg'
text('.svg-frag-import-path', svgFrag)
document.querySelector('.svg-frag-import').src = svgFrag + '#icon-heart-view'
import rawSvg from './nested/fragment.svg?raw'
text('.raw', rawSvg)
import fooUrl from './foo.js?url'
text('.url', fooUrl)
import unicodeUrl from './テスト-測試-white space.js?url'
text('.unicode-url', unicodeUrl)
import cssUrl from './css/icons.css?url'
text('.url-css', cssUrl)
// const url = new URL('non_existent_file.png', import.meta.url)
const metaUrl = new URL('./nested/asset.png', import.meta.url)
text('.import-meta-url', metaUrl)
document.querySelector('.import-meta-url-img').src = metaUrl
// prettier-ignore
const metaUrlWithComma = new URL('./nested/asset.png', import.meta.url,)
text('.import-meta-url-comma', metaUrlWithComma)
document.querySelector('.import-meta-url-img-comma').src = metaUrlWithComma
// testing trailing comma and new line
// prettier-ignore
const metaUrlWithCommaNL = new URL(
'./nested/asset.png',
import.meta.url,
)
text('.import-meta-url-comma-nl', metaUrlWithCommaNL)
document.querySelector('.import-meta-url-img-comma-nl').src =
metaUrlWithCommaNL
import classNames from './css/foo.module.css'
document.querySelector('#foo').className = classNames['foo-module']
import someString from './static/foo.txt?raw'
document.querySelector('.raw-query').textContent = someString
const metaUrlNonExistent = new URL('non-existent', import.meta.url).pathname
text('.non-existent-import-meta-url', metaUrlNonExistent)
/**
* don't process the code in the comment
* const url = new URL('non_existent_file.png', import.meta.url)
*/
function testDynamicImportMetaUrl(name, i) {
const metaUrl = new URL(`./nested/${name}.png`, import.meta.url)
text(`.dynamic-import-meta-url-${i}`, metaUrl)
document.querySelector(`.dynamic-import-meta-url-img-${i}`).src = metaUrl
}
testDynamicImportMetaUrl('icon', 1)
testDynamicImportMetaUrl('asset', 2)
function testDynamicImportMetaUrlWithComma(name, i) {
// prettier-ignore
const metaUrl = new URL(`./nested/${name}.png`, import.meta.url,)
text(`.dynamic-import-meta-url-${i}-comma`, metaUrl)
document.querySelector(`.dynamic-import-meta-url-img-${i}-comma`).src =
metaUrl
}
testDynamicImportMetaUrlWithComma('icon', 1)
testDynamicImportMetaUrlWithComma('asset', 2)
function text(el, text) {
document.querySelector(el).textContent = text
}
</script>