-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
/
index.html
519 lines (449 loc) · 14.5 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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
<!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>
<li>
From publicDir (json): <code class="public-json-import"></code> Content:
<code class="public-json-import-content"></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-image-set-with-var">
<span style="background: #fff">
CSS background image-set() (relative in var)
</span>
</div>
<div class="css-image-set-mix-url-var">
<span style="background: #fff">
CSS background image-set() (mix var and url)
</span>
</div>
<div class="css-image-set-base64">
<span style="background: #fff">
CSS background image-set() (with base64)
</span>
</div>
<div class="css-image-set-gradient">
<span style="background: #fff">
CSS background image-set() (with gradient)
</span>
</div>
<div class="css-image-set-multiple-descriptor">
<span style="background: #fff">
CSS background image-set() (with multiple descriptor)
</span>
</div>
<div
class="css-image-set-multiple-descriptor-inline-style"
style="
background-image: -webkit-image-set(
'./nested/asset.png' type('image/png') 1x,
'./nested/asset.png' type('image/png') 2x
);
background-size: 10px;
"
>
<span style="background: #fff">
CSS background image-set() inline style (with multiple descriptor)
</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>Unknown extension assets import</h2>
<code class="unknown-ext"></code>
<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)</h2>
<img class="import-meta-url-dep-img" />
<code class="import-meta-url-dep"></code>
<h2>new URL('/...', import.meta.url)</h2>
<img class="import-meta-url-base-path-img" />
<code class="import-meta-url-base-path"></code>
<h2>new URL('...', import.meta.url (without extension))</h2>
<p>
<code class="import-meta-url-content-without-extension"></code>
</p>
<p>
<code class="import-meta-url-without-extension"></code>
</p>
<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>
<p>
<code class="dynamic-import-meta-url-js"></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(`./${dynamic}?abc`, import.meta.url)</h2>
<p>
<img class="dynamic-import-meta-url-img-1-query" />
<code class="dynamic-import-meta-url-1-query"></code>
</p>
<p>
<img class="dynamic-import-meta-url-img-2-query" />
<code class="dynamic-import-meta-url-2-query"></code>
</p>
<h2>new URL(`./${1 === 0 ? static : dynamic}?abc`, import.meta.url)</h2>
<p>
<img class="dynamic-import-meta-url-img-1-ternary" />
<code class="dynamic-import-meta-url-1-ternary"></code>
</p>
<p>
<img class="dynamic-import-meta-url-img-2-ternary" />
<code class="dynamic-import-meta-url-2-ternary"></code>
</p>
<h2>new URL(`non-existent`, import.meta.url)</h2>
<p>
<code class="non-existent-import-meta-url"></code>
</p>
<h2>new URL(`${dynamic}`, import.meta.url)</h2>
<p>
<code class="dynamic-import-meta-url-all"></code>
</p>
<h2>simple script tag import-expression</h2>
<code class="import-expression"></code>
<code class="obj-import-express"></code>
<code class="string-import-express"></code>
<script>
const obj = {
import(t) {
text('.obj-import-express', t)
},
}
const stringImport = "const t = import('package')"
function text(el, text) {
document.querySelector(el).textContent = text
}
import('./static/import-expression.js')
import('/import-expression.js')
// import('./static/raw.js')
/* import('./static/raw.js') */
obj.import('ignore object import prop')
try {
text('.string-import-express', t)
} catch {
text('.string-import-express', 'no load')
}
</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
class="inline-style"
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>from publicDir</h3>
<style>
.style-public-assets {
background: url('/icon.png');
}
</style>
<p class="inline-style-public" style="background: url(/icon.png)">
inline style
</p>
<p class="style-public-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>
<h3>style in svg</h3>
<svg viewBox="0 0 512 512" width="21" height="21" class="style-insvg">
<style>
.style-insvg-color {
fill: #0088ff;
}
</style>
<g class="style-insvg-color">
<rect x="224" y="352" width="64" height="64" />
<path
d="M128 128v96h64v-96h96v96h-32v32h-32v64h64v-64h64V128h-32V96H160v32h-32z"
/>
</g>
</svg>
<h3>assets in noscript</h3>
<noscript>
<img class="noscript" src="./nested/asset.png" />
</noscript>
<link rel="stylesheet" href="asset/style.css" />
<div class="relative-css">link style</div>
<div class="relative-js"></div>
<script src="asset/main.js" type="module"></script>
<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 publicJsonUrl from '/foo.json?url'
text('.public-json-import', publicJsonUrl)
;(async () => {
const res = await fetch(publicJsonUrl)
text('.public-json-import-content', await res.text())
})()
import svgFrag from './nested/fragment.svg'
text('.svg-frag-import-path', svgFrag)
document.querySelector('.svg-frag-import').src = svgFrag + '#icon-heart-view'
import unknownExtUrl from './nested/foo.unknown'
text('.unknown-ext', unknownExtUrl)
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
const metaUrlDep = new URL('@/asset.png', import.meta.url)
text('.import-meta-url-dep', metaUrlDep)
document.querySelector('.import-meta-url-dep-img').src = metaUrlDep
// testing URLs for public assets served at the public base path
// equivalent to `new URL(`${import.meta.env.BASE_URL}/icon.png`, import.meta.url)
const metaUrlBasePath = new URL('/icon.png', import.meta.url)
text('.import-meta-url-base-path', metaUrlBasePath)
document.querySelector('.import-meta-url-base-path-img').src = metaUrlBasePath
const metaUrlWithoutExtension = new URL('./nested/test', import.meta.url)
text('.import-meta-url-without-extension', metaUrlWithoutExtension)
;(async () => {
const res = await fetch(metaUrlWithoutExtension)
text('.import-meta-url-content-without-extension', await res.text())
})()
// 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 testDynamicImportMetaUrlWithQuery(name, i) {
// prettier-ignore
const metaUrl = new URL(`./nested/${name}.png?abc`, import.meta.url,)
text(`.dynamic-import-meta-url-${i}-query`, metaUrl)
document.querySelector(`.dynamic-import-meta-url-img-${i}-query`).src =
metaUrl
}
testDynamicImportMetaUrlWithQuery('icon', 1)
testDynamicImportMetaUrlWithQuery('asset', 2)
function testDynamicImportMetaUrlWithTernaryOperator(name, i) {
// prettier-ignore
const metaUrl = new URL(`./nested/${1 === 0 ? 'failed' : name}.png?abc`, import.meta.url,)
text(`.dynamic-import-meta-url-${i}-ternary`, metaUrl)
document.querySelector(`.dynamic-import-meta-url-img-${i}-ternary`).src =
metaUrl
}
testDynamicImportMetaUrlWithTernaryOperator('icon', 1)
testDynamicImportMetaUrlWithTernaryOperator('asset', 2)
{
const name = 'test'
const js = new URL(`./nested/${name}.js`, import.meta.url).href
text('.dynamic-import-meta-url-js', js)
}
{
const name = './nested/icon'
const metaUrl = new URL(`${name}.png`, import.meta.url)
text(`.dynamic-import-meta-url-all`, metaUrl)
}
function text(el, text) {
document.querySelector(el).textContent = text
}
</script>